Skip to content

Commit

Permalink
Merge pull request #59 from smarterclayton/publish
Browse files Browse the repository at this point in the history
Add an image publisher step
  • Loading branch information
smarterclayton committed Nov 9, 2017
2 parents f9bbe77 + 6a6e2bf commit 2a810ff
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions playbooks/publish_image.yaml
@@ -0,0 +1,38 @@
---
- name: Publish the most recent image
hosts: localhost
connection: local
gather_facts: no
tasks:

- name: Require openshift_gcp_image
fail:
msg: "A source image name or family is required for image publishing. Please ensure `openshift_gcp_image` is defined."
when: openshift_gcp_image is undefined

- name: Require openshift_gcp_target_image
fail:
msg: "A target image name or family is required for image publishing. Please ensure `openshift_gcp_target_image` is defined."
when: openshift_gcp_target_image is undefined

- block:
- name: Retrieve images in the {{ openshift_gcp_target_image }} family
command: >
gcloud --project "{{ openshift_gcp_project }}" compute images list
"--filter=family={{ openshift_gcp_target_image }}"
--format=json --sort-by ~creationTimestamp
register: images
- name: Prune oldest images
command: >
gcloud --project "{{ openshift_gcp_project }}" compute images delete "{{ item['name'] }}"
with_items: "{{ (images.stdout | default('[]') | from_json )[( openshift_gcp_keep_images | int ):] }}"
when: openshift_gcp_keep_images is defined

- name: Copy the latest image in the family {{ openshift_gcp_image }} to {{ openshift_gcp_target_image }}
command: >
gcloud --project "{{ openshift_gcp_target_project | default(openshift_gcp_project) }}"
beta compute images create
"{{ openshift_gcp_target_image_name | default(openshift_gcp_target_image + '-' + lookup('pipe','date +%Y%m%d-%H%M%S')) }}"
--family "{{ openshift_gcp_target_image }}"
--source-image-family "{{ openshift_gcp_image }}"
--source-image-project "{{ openshift_gcp_project }}"

0 comments on commit 2a810ff

Please sign in to comment.