From e865f69b4e4aa440cc8efaac4f9972bc309f4a15 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Mon, 30 Apr 2018 17:26:58 +1200 Subject: [PATCH] Basic template based Dockerfile approach --- tasks/main.yml | 22 +++++++++++++++++++++- templates/Dockerfile.j2 | 2 ++ vars/main.yml | 14 ++++---------- 3 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 templates/Dockerfile.j2 diff --git a/tasks/main.yml b/tasks/main.yml index ed97d53..4754fec 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1 +1,21 @@ ---- +- name: Set default modified_append_tag + set_fact: + modified_append_tag: "{{ lookup('pipe','date +-modified-%Y%m%d%H%M%S') }}" + when: modified_append_tag is undefined or modified_append_tag == None + +- name: Create image build context directory + tempfile: + state: directory + prefix: tripleo-modify-image + register: context_dir + +- name: Write Dockerfile to {{ context_dir.path }} + template: + src: Dockerfile.j2 + dest: "{{ context_dir.path }}/Dockerfile" + +- name: Modify image + docker_image: + name: "{{ modified_image }}{{ modified_append_tag }}" + path: "{{ context_dir.path }}" + diff --git a/templates/Dockerfile.j2 b/templates/Dockerfile.j2 new file mode 100644 index 0000000..97ded3f --- /dev/null +++ b/templates/Dockerfile.j2 @@ -0,0 +1,2 @@ +FROM {{ source_image }} +LABEL modified_append_tag={{ modified_append_tag }} diff --git a/vars/main.yml b/vars/main.yml index 8290715..4fc97a4 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -2,19 +2,13 @@ # Mandatory fully qualified reference to the source image to be modified source_image: -# Mandatory path to the directory containing the Dockerfile to modify the image -modify_dir_path: - # String to be appended after the tag to indicate this is a modified version of -# the source image. -modified_append_tag: "-modified-{{lookup('pipe','date +%Y%m%d%H%M%S')}}" +# the source image. Defaults to the output of the command +# "date +-modified-%Y%m%d%H%M%S" +modified_append_tag: # If set, the modified image will be tagged with this reference. If the purpose # of the image is not changing, it may be enough to rely on modified_append_tag # to identify that this is a modified version of the source image. # modified_append_tag will still be appended to this reference. -modified_image: - -# Build-time variables for the image build. The role variables source_image and -# modified_append_tag will be merged with this dict. -modify_buildargs: {} +modified_image: {{ source_image }}