diff --git a/ansible/delta-hosts/hosts b/ansible/delta-hosts/hosts index 6be6fd74..fdddf605 100644 --- a/ansible/delta-hosts/hosts +++ b/ansible/delta-hosts/hosts @@ -37,6 +37,9 @@ delta-consul-c [user-vault] localhost +[user-local] +localhost + [worker] localhost diff --git a/ansible/gamma-hosts/hosts b/ansible/gamma-hosts/hosts index ce2f2eb4..85f132aa 100644 --- a/ansible/gamma-hosts/hosts +++ b/ansible/gamma-hosts/hosts @@ -41,6 +41,9 @@ gamma-consul-c [user-vault] localhost +[user-local] +localhost + [worker] localhost diff --git a/ansible/group_vars/alpha-image-builder.yml b/ansible/group_vars/alpha-image-builder.yml index 4824df73..d2a1e158 100644 --- a/ansible/group_vars/alpha-image-builder.yml +++ b/ansible/group_vars/alpha-image-builder.yml @@ -1,8 +1,7 @@ app_name: image-builder name: "{{ app_name }}" -# namespace (can include "registry.runnable.com:") -image_builder_docker_namespace: "{{ registry_host }}/runnable/image-builder" -app_repo: git@github.com:CodeNow/{{ app_name }}.git + +repo: git@github.com:CodeNow/{{ name }}.git # consul values consul_values: diff --git a/ansible/image-builder.yml b/ansible/image-builder.yml index 6710e62a..3fca438c 100644 --- a/ansible/image-builder.yml +++ b/ansible/image-builder.yml @@ -1,10 +1,13 @@ --- +- hosts: user-local + vars_files: + - group_vars/alpha-image-builder.yml + roles: + - { role: build_with_dockerfile } + - hosts: "{{ dock | default('docks') }}" vars_files: - group_vars/alpha-image-builder.yml roles: - - { role: notify, tags: [notify] } - - { role: node, tags: [setup] } - - { role: git_repo } - - { role: image-builder } + - { role: pull-image } - { role: consul_value, tags: [consul_value] } diff --git a/ansible/roles/build_with_dockerfile/tasks/main.yml b/ansible/roles/build_with_dockerfile/tasks/main.yml index d7453048..f2e76689 100644 --- a/ansible/roles/build_with_dockerfile/tasks/main.yml +++ b/ansible/roles/build_with_dockerfile/tasks/main.yml @@ -30,9 +30,20 @@ become: yes command: docker build {{ build_args | default("") }} --tag="{{ container_image }}:{{ container_tag }}" "{{ build_dir }}/{{ name }}/repo" +- name: login to registry + delegate_to: "{{ builder }}" + tags: deploy, build + become: yes + command: docker login -u {{ registry_username }} -p {{ registry_token }} -e "info@runnable.com" {{ registry_host }} + - name: push docker image delegate_to: "{{ builder }}" tags: deploy, build become: yes - ignore_errors: True command: docker push {{ container_image }}:{{ container_tag }} + +- name: logout of registry + delegate_to: "{{ builder }}" + tags: deploy, build + become: yes + command: docker logout {{ registry_host }} diff --git a/ansible/roles/builder/tasks/main.yml b/ansible/roles/builder/tasks/main.yml index ae163e76..f330c086 100644 --- a/ansible/roles/builder/tasks/main.yml +++ b/ansible/roles/builder/tasks/main.yml @@ -31,6 +31,7 @@ - name: set number of images built tags: deploy, build set_fact: + # Quay IO includes deleted images in this query through the `end_ts` property no_images_found: "{{ currently_built_tags|json_query('json.tags')|length == 0 }}" - name: set number of images built @@ -192,4 +193,4 @@ tags: deploy, build when: build_image become: yes - command: docker logout + command: docker logout {{ registry_host }} diff --git a/ansible/roles/image-builder/tasks/main.yml b/ansible/roles/image-builder/tasks/main.yml deleted file mode 100644 index 1a29a3aa..00000000 --- a/ansible/roles/image-builder/tasks/main.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -- name: npm install - tags: deploy - npm: - path=/opt/runnable/image-builder - state=latest - -- name: build the image-builder - tags: deploy - become: true - command: docker build --no-cache --tag="{{ image_builder_docker_namespace }}:{{ git_branch }}" /opt/runnable/image-builder - -- name: tag the image-builder with registry.runnable.com - tags: deploy - become: true - command: docker tag {{ image_builder_docker_namespace }}:{{ git_branch }} registry.runnable.com/{{ image_builder_docker_namespace }}:{{ git_branch }} diff --git a/ansible/roles/pull-image/tasks/main.yml b/ansible/roles/pull-image/tasks/main.yml new file mode 100644 index 00000000..088a7143 --- /dev/null +++ b/ansible/roles/pull-image/tasks/main.yml @@ -0,0 +1,15 @@ +--- +- name: login to registry + tags: deploy + become: yes + command: docker login -u {{ registry_username }} -p {{ registry_token }} -e "info@runnable.com" {{ registry_host }} + +- name: pull image + tags: deploy + become: true + command: docker pull {{ container_image }}:{{ container_tag }} + +- name: logout of registry + tags: deploy + become: yes + command: docker logout {{ registry_host }}