diff --git a/README.md b/README.md index 5f14c7e..e6e92a4 100644 --- a/README.md +++ b/README.md @@ -8,20 +8,20 @@ A role to allow modification to container images built for the TripleO project. | Name | Default Value | Description | |-------------------|---------------------|----------------------| -| `source_image` | `None` | Mandatory fully qualified reference to the source image to be modified. The supplied Dockerfile will be copied and modified to make the FROM directive match this variable. | -| `modify_dir_path` | `None` | Mandatory path to the directory containing the Dockerfile to modify the image | -| `modified_append_tag` | `None` | String to be appended after the tag to indicate this is a modified version of the source image. Defaults to the output of the command `date +-modified-%Y%m%d%H%M%S` | -| `modified_image` | `{{source_image}}` | 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. | +| `source_image` | `[undefined]` | Mandatory fully qualified reference to the source image to be modified. The supplied Dockerfile will be copied and modified to make the FROM directive match this variable. | +| `modify_dir_path` | `[undefined]` | Mandatory path to the directory containing the Dockerfile to modify the image | +| `modified_append_tag` | `date +-modified-%Y%m%d%H%M%S` | String to be appended after the tag to indicate this is a modified version of the source image. | +| `modified_image_prefix` | `''` | 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. | **Variables used for yum update** | Name | Default Value | Description | |-------------------|---------------------|----------------------| -| `source_image` | `None` | See modify image variables | -| `modified_append_tag` | `None` | See modify image variables | -| `modified_image` | `{{source_image}}` | See modify image variables | +| `source_image` | `[undefined]` | See modify image variables | +| `modified_append_tag` | `date +-modified-%Y%m%d%H%M%S` | See modify image variables | +| `modified_image_prefix` | `''` | See modify image variables | | `yum_repos_dir_path` | `None` | Optional path of directory to be used as `/etc/yum.repos.d` during the update | -| `compare_host_packages` | False | If True, skip yum update when package versions match host package versions | +| `compare_host_packages` | `False` | If `True`, skip yum update when package versions match host package versions | ## Requirements ## diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..c4fecd3 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,3 @@ +modified_image_prefix: '' +modified_append_tag: "{{ lookup('pipe','date +-modified-%Y%m%d%H%M%S') }}" +compare_host_packages: no diff --git a/handlers/main.yml b/handlers/main.yml deleted file mode 100644 index ed97d53..0000000 --- a/handlers/main.yml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/meta/main.yml b/meta/main.yml index ed97d53..f89306a 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1 +1,21 @@ ---- +galaxy_info: + author: Steve Baker + description: Modify container images built for TripleO + company: Red Hat + license: Apache 2.0 + min_ansible_version: 2.4 + + platforms: + - name: EL + versions: + - 7 + + galaxy_tags: + - docker + - container + - openstack + - tripleo + - packaging + - system + +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml index fe3a172..cbdfef3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,9 +1,3 @@ -- name: Set default tasks_from - set_fact: - tasks_from: modify_image.yaml - when: tasks_from is undefined - -- name: Running tasks from {{ tasks_from }} - include_role: - name: tripleo-modify-image - tasks_from: "{{ tasks_from }}" +- import_tasks: precheck.yml + tags: + - always diff --git a/tasks/modify_image.yml b/tasks/modify_image.yml index 7aebbd2..647aa4b 100644 --- a/tasks/modify_image.yml +++ b/tasks/modify_image.yml @@ -1,7 +1,6 @@ -- name: Set default facts - include_role: - name: tripleo-modify-image - tasks_from: set_defaults.yml +- import_tasks: precheck.yml + tags: + - always - name: Copy Dockerfile to Dockerfile.modified copy: @@ -20,9 +19,9 @@ insertafter: "^FROM " line: "LABEL modified_append_tag={{ modified_append_tag }}" -- name: Modify image +- name: Modify image docker_image: - name: "{{ modified_image }}{{ modified_append_tag }}" + name: "{{ modified_image_prefix }}{{ modified_append_tag }}" path: "{{ modify_dir_path }}" dockerfile: Dockerfile.modified diff --git a/tasks/precheck.yml b/tasks/precheck.yml new file mode 100644 index 0000000..b2cc47c --- /dev/null +++ b/tasks/precheck.yml @@ -0,0 +1,11 @@ +- name: Ensure that source_image is defined + assert: + that: + - source_image is defined + - source_image | length > 0 + +- name: Ensure that modify_dir_path is defined + assert: + that: + - modify_dir_path is defined + - modify_dir_path | length > 0 diff --git a/tasks/set_defaults.yml b/tasks/set_defaults.yml deleted file mode 100644 index 587ebcc..0000000 --- a/tasks/set_defaults.yml +++ /dev/null @@ -1,9 +0,0 @@ -- 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 - -- name: Set default modified_image - set_fact: - modified_image: "{{source_image}}" - when: modified_image is undefined diff --git a/tasks/yum_update.yml b/tasks/yum_update.yml index 4c979b5..8f783d3 100644 --- a/tasks/yum_update.yml +++ b/tasks/yum_update.yml @@ -1,7 +1,6 @@ -- name: Set default facts - include_role: - name: tripleo-modify-image - tasks_from: set_defaults.yml +- import_tasks: precheck.yml + tags: + - always - name: Inspect image docker_image_facts: @@ -27,15 +26,15 @@ - name: Generate host package json file block: - - command: | - rpm -qa --qf '"%{NAME}": "%{VERSION}-%{RELEASE}"\n' - register: rpm_query_output + - command: | + rpm -qa --qf '"%{NAME}": "%{VERSION}-%{RELEASE}"\n' + register: rpm_query_output - - copy: - content: "{{ rpm_query_output.stdout | from_yaml | to_nice_json }}" - dest: "{{ context_dir.path }}/host_packages.json" - - when: compare_host_packages is defined and compare_host_packages + - copy: + content: "{{ rpm_query_output.stdout | from_yaml | to_nice_json }}" + dest: "{{ context_dir.path }}/host_packages.json" + + when: compare_host_packages - name: Write Dockerfile to {{ context_dir.path }} template: @@ -46,17 +45,13 @@ copy: src: yum_update.sh dest: "{{ context_dir.path }}/yum_update.sh" - mode: 0555 + mode: '0555' - name: Write compare-package-json.py copy: src: compare-package-json.py dest: "{{ context_dir.path }}/compare-package-json.py" - mode: 0555 + mode: '0555' - name: Modify image - include_role: - name: tripleo-modify-image - tasks_from: modify_image.yml - vars: - modify_dir_path: "{{ context_dir.path }}" + import_tasks: modify_image.yml diff --git a/templates/Dockerfile.j2 b/templates/Dockerfile.j2 index 178004b..c986fd0 100644 --- a/templates/Dockerfile.j2 +++ b/templates/Dockerfile.j2 @@ -10,7 +10,7 @@ COPY compare-package-json.py /tmp/ COPY yum.repos.d /etc/ {% endif %} -{% if compare_host_packages is defined %} +{% if compare_host_packages %} COPY host_packages.json /tmp/ {% endif %} diff --git a/vars/main.yml b/vars/main.yml deleted file mode 100644 index ed97d53..0000000 --- a/vars/main.yml +++ /dev/null @@ -1 +0,0 @@ ----