From ee15db4c7c49710b1b114e0f83b3b96e1f096faa Mon Sep 17 00:00:00 2001 From: Jaron Rolfe Date: Thu, 12 Oct 2017 15:57:34 -0400 Subject: [PATCH 1/4] allow for private registry without latest tag The logic that sets awx_web_docker_actual_image and awx_task_docker_actual_image creates and pushes images to the private registry tagged with the awx version, which is appropriate, but then tries to pull with no tag. (so docker defaults to "latest", which does not exist) --- installer/local_docker/tasks/main.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/installer/local_docker/tasks/main.yml b/installer/local_docker/tasks/main.yml index 0e81ac8a10..b18b778516 100644 --- a/installer/local_docker/tasks/main.yml +++ b/installer/local_docker/tasks/main.yml @@ -85,8 +85,10 @@ - name: Set full image path for Registry set_fact: - awx_web_docker_actual_image: "{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_web_image }}" - awx_task_docker_actual_image: "{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_task_image }}" + awx_web_docker_actual_image: >- + {{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_web_image }}:{{ awx_version }} + awx_task_docker_actual_image: >- + {{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_task_image }}:{{ awx_version }} when: docker_registry is defined - name: Set full image path for local install From 67df298f215bf326b57a0b85caebcdb4c72f3040 Mon Sep 17 00:00:00 2001 From: Jaron Rolfe Date: Sun, 15 Oct 2017 22:15:11 -0400 Subject: [PATCH 2/4] Replace deprecated "include" with "include_tasks" --- installer/check_vars/tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/check_vars/tasks/main.yml b/installer/check_vars/tasks/main.yml index bed592a99b..3699d4e4f6 100644 --- a/installer/check_vars/tasks/main.yml +++ b/installer/check_vars/tasks/main.yml @@ -1,7 +1,7 @@ # main.yml --- -- include: check_openshift.yml +- include_tasks: check_openshift.yml when: openshift_host is defined and openshift_host != '' -- include: check_docker.yml +- include_tasks: check_docker.yml when: openshift_host is not defined or openshift_host == '' From 5e17d72922a613e7000ac35936c78b536f02aa55 Mon Sep 17 00:00:00 2001 From: Jaron Rolfe Date: Mon, 16 Oct 2017 00:38:28 -0400 Subject: [PATCH 3/4] Improve push capabilities and allow build playbook to push --- INSTALL.md | 4 +++ installer/build.yml | 1 + installer/image_push/tasks/main.yml | 40 +++++++++++++++++++++++++++ installer/install.yml | 1 - installer/inventory | 5 ++++ installer/local_docker/tasks/main.yml | 28 ++----------------- 6 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 installer/image_push/tasks/main.yml diff --git a/INSTALL.md b/INSTALL.md index e16c4f3bc3..10ae5a0ac0 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -330,6 +330,10 @@ If you wish to tag and push built images to a Docker registry, set the following > Username of the user that will push images to the registry. Defaults to *developer*. +*docker_remove_local_images* + +> Due to the way that the docker_image module behaves, images will not be pushed to a remote repository if they are present locally. Set this to delete local versions of the images that will be pushed to the remote. This will fail if containers are currently running from those images. + **Note** > These settings are ignored if using official images diff --git a/installer/build.yml b/installer/build.yml index da8f03c0bb..00dc6424ef 100644 --- a/installer/build.yml +++ b/installer/build.yml @@ -4,3 +4,4 @@ gather_facts: false roles: - { role: image_build } + - { role: image_push, when: "docker_registry is defined" } diff --git a/installer/image_push/tasks/main.yml b/installer/image_push/tasks/main.yml new file mode 100644 index 0000000000..111f7e0cd2 --- /dev/null +++ b/installer/image_push/tasks/main.yml @@ -0,0 +1,40 @@ +--- +- name: Remove local images to ensure proper push behavior + block: + - name: Remove web image + docker_image: + name: "{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_web_image }}" + tag: "{{ awx_version }}" + state: absent + + - name: Remove task image + docker_image: + name: "{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_task_image }}" + tag: "{{ awx_version }}" + state: absent + delegate_to: localhost + when: docker_remove_local_images + +- name: Tag and Push Container Images + block: + - name: Tag and push web image to registry + docker_image: + name: "{{ awx_web_image }}" + repository: "{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_web_image }}" + tag: "{{ awx_version }}" + push: yes + + - name: Tag and push task image to registry + docker_image: + name: "{{ awx_task_image }}" + repository: "{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_task_image }}" + tag: "{{ awx_version }}" + push: yes + delegate_to: localhost + +- name: Set full image path for Registry + set_fact: + awx_web_docker_actual_image: >- + {{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_web_image }}:{{ awx_version }} + awx_task_docker_actual_image: >- + {{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_task_image }}:{{ awx_version }} diff --git a/installer/install.yml b/installer/install.yml index 01360e9ad3..d37d3af596 100644 --- a/installer/install.yml +++ b/installer/install.yml @@ -7,4 +7,3 @@ - { role: image_build, when: "dockerhub_base is not defined" } - { role: openshift, when: "openshift_host is defined" } - { role: local_docker, when: "openshift_host is not defined" } - diff --git a/installer/inventory b/installer/inventory index 1cccc1271a..3e2b987f7a 100644 --- a/installer/inventory +++ b/installer/inventory @@ -39,6 +39,11 @@ host_port=80 # docker_registry_repository=awx # docker_registry_username=developer + +# Docker_image will not attempt to push to remote if the image already exists locally +# Set this to true to delete images from docker on the build host so that they are pushed to the remote repository +docker_remove_local_images=False + # Set pg_hostname if you have an external postgres server, otherwise # a new postgres service will be created # pg_hostname=postgresql diff --git a/installer/local_docker/tasks/main.yml b/installer/local_docker/tasks/main.yml index b18b778516..4206b4c4f0 100644 --- a/installer/local_docker/tasks/main.yml +++ b/installer/local_docker/tasks/main.yml @@ -65,31 +65,9 @@ timeout: 300 when: ansible_connection != "local" and docker_registry is not defined - - name: Tag and push web image to registry - docker_image: - name: "{{ awx_web_image }}" - repository: "{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_web_image }}" - tag: "{{ awx_version }}" - push: yes - when: docker_registry is defined - delegate_to: localhost - - - name: Tag and push task image to registry - docker_image: - name: "{{ awx_task_image }}" - repository: "{{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_task_image }}" - tag: "{{ awx_version }}" - push: yes - when: docker_registry is defined - delegate_to: localhost - - - name: Set full image path for Registry - set_fact: - awx_web_docker_actual_image: >- - {{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_web_image }}:{{ awx_version }} - awx_task_docker_actual_image: >- - {{ docker_registry }}/{{ docker_registry_repository }}/{{ awx_task_image }}:{{ awx_version }} - when: docker_registry is defined + - include_role: + name: image_push + when: docker_registry is defined and dockerhub_base is not defined - name: Set full image path for local install set_fact: From cc5f329d332f9b756e6b942339e305f1fff67ffb Mon Sep 17 00:00:00 2001 From: Jaron Rolfe Date: Thu, 19 Oct 2017 21:43:37 -0400 Subject: [PATCH 4/4] Explanation for image removal block and idiomatic handling of var that enables it --- installer/image_push/tasks/main.yml | 5 ++++- installer/inventory | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/installer/image_push/tasks/main.yml b/installer/image_push/tasks/main.yml index 111f7e0cd2..a81bdf6644 100644 --- a/installer/image_push/tasks/main.yml +++ b/installer/image_push/tasks/main.yml @@ -1,5 +1,8 @@ --- - name: Remove local images to ensure proper push behavior + # TODO: this code will not be necessary if and when docker_image can be configured to push if the image + # Already exists locally + # Pull request: https://github.com/ansible/ansible/pull/31863 block: - name: Remove web image docker_image: @@ -13,7 +16,7 @@ tag: "{{ awx_version }}" state: absent delegate_to: localhost - when: docker_remove_local_images + when: docker_remove_local_images|default(False) - name: Tag and Push Container Images block: diff --git a/installer/inventory b/installer/inventory index 3e2b987f7a..e09e91f362 100644 --- a/installer/inventory +++ b/installer/inventory @@ -42,7 +42,7 @@ host_port=80 # Docker_image will not attempt to push to remote if the image already exists locally # Set this to true to delete images from docker on the build host so that they are pushed to the remote repository -docker_remove_local_images=False +# docker_remove_local_images=False # Set pg_hostname if you have an external postgres server, otherwise # a new postgres service will be created