使用 Jenkins 部署 Django docker 镜像

时间:2021-07-12 04:29:29

标签: django docker jenkins docker-compose ansible

我想用 Jenkins 部署 Django Docker 镜像。

我已经用中间的 docker 注册表创建了这个管道。 为此,我有 2 个 Jenkins 任务

  1. 构建映像并传输到注册表
  2. 从注册表拉取到所需的服务器并启动映像

现在,我想避免使用 docker 注册表以加快部署速度。

现在我有这样的东西,但它不起作用:

---
- hosts: "{{ HOSTS|default('docker') }}"
  remote_user: "{{ USER }}"
  vars:
    deploy_port: "{{ DEPLOY_PORT|default(8080) }}"
    git_branch: "{{ GIT_BRANCH|default('Development') }}"
    python_settings: "{{ PYTHON_SETTINGS|default('Development') }}"
    su_user: "{{ SU_USER|default('test') }}"
    su_email: "{{ SU_EMAIL|default('test@test.si') }}"
    su_password: "{{ SU_PASSWORD|default('test') }}"
    app_container_name: "{{ APP_NAME|default('test') }}"
  tasks:
  - name: Remove old image
    docker_image:
      name: my-project-name-{{ git_branch }}
      state: absent
      force: yes
  - name: build django image
    docker_image:
      path: .
      name: my-project-name-{{ git_branch }}
      nocache: yes
  - name: Start django image
    docker_container:
      name: "{{ app_container_name }}"
      image: my-project-name-{{ git_branch }}
      state: started
      restart: yes
      restart_policy: always
      ports:
      - "{{ deploy_port }}:80"
      env:
        PYTHONUNBUFFERED: 0
        DJANGO_ENV_NAME: "{{ python_settings }}"
        SU_USER: "{{ su_user }}"
        SU_EMAIL: "{{ su_email }}"
        SU_PASSWORD: "{{ su_password }}"
      tty: yes

这给了我詹金斯的错误

raise errors.APIError(e, response, explanation=explanation)\r\ndocker.errors.APIError: 500 Server Error: Internal Server Error (\"{\"message\":\"Cannot locate specified Dockerfile: Dockerfile\"}\")\r\n", 
    "msg": "MODULE FAILURE"
}
    to retry, use: --limit @/var/jenkins_home/workspace/my_project STAGE/run_test.retry

PLAY RECAP *********************************************************************
stage                      : ok=2    changed=0    unreachable=0    failed=1   

0 个答案:

没有答案