diff --git a/README.md b/README.md index 9c23090..f58d8d0 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ the modification, for example: The following playbook will produce a modified image with the tag `:latest-updated` which will do a yum update using the host's /etc/yum.repos.d. The yum update will only occur if there are differences between host and image -package versions. In this playbook the tasks_from is set as a variable instead +package versions. In this playbook the tasks\_from is set as a variable instead of an `import_role` parameter. - hosts: localhost @@ -90,6 +90,25 @@ of an `import_role` parameter. yum_repos_dir_path: /etc/yum.repos.d modified_append_tag: updated +### RPM install ### + +The following playbook will produce a modified image with RPMs from the +specified rpms\_path on the local filesystem installed as a new layer +for the container. The new container tag is appened with the '-hotfix' +suffix. Useful for creating adhoc hotfix containers with local RPMs with no +network connectivity. + + - hosts: localhost + tasks: + - name: include tripleo-modify-image + import_role: + name: tripleo-modify-image + vars: + tasks_from: rpm_install.yml + source_image: docker.io/tripleomaster/centos-binary-nova-api:latest + rpms_path: /foo/bar + modified_append_tag: -hotfix + ## License ## Apache 2.0 diff --git a/files/rpm_install.sh b/files/rpm_install.sh new file mode 100755 index 0000000..f63fab1 --- /dev/null +++ b/files/rpm_install.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -ex + +rpm -Uvh /tmp/*.rpm +rm -f /tmp/*.rpm +rm -f /tmp/rpm_install.sh diff --git a/tasks/rpm_install.yml b/tasks/rpm_install.yml new file mode 100644 index 0000000..ae5893b --- /dev/null +++ b/tasks/rpm_install.yml @@ -0,0 +1,53 @@ +- import_tasks: precheck.yml + tags: + - always + +- name: Inspect image + docker_image_facts: + name: "{{ source_image }}" + register: source_image_facts + +- name: Set original_user + set_fact: + original_user: "{{ source_image_facts.images[0].Config.User }}" + +- name: Create image build context directory + tempfile: + state: directory + prefix: tripleo-modify-image + register: context_dir + +- name: Set modify_dir_path + set_fact: + modify_dir_path: "{{ context_dir.path }}" + +- name: List RPMs + find: + paths: "{{ rpms_path }}" + patterns: "^.*?\\.rpm$" + use_regex: yes + when: rpms_path is defined + register: context_rpms + +- name: Set rpms_list + set_fact: + rpms_list: "{{ context_rpms.files|json_query('[*].path') }}" + +- name: Copy RPMs to context dir + copy: + src: "{{ item }}" + dest: "{{ modify_dir_path }}" + loop: "{{ rpms_list }}" + +- name: Write Dockerfile to {{ modify_dir_path }} + template: + src: Dockerfile-rpm.j2 + dest: "{{ modify_dir_path }}/Dockerfile" + +- name: Write rpm_install.sh + copy: + src: rpm_install.sh + dest: "{{ modify_dir_path }}/rpm_install.sh" + mode: '0555' + +- include_tasks: modify_image.yml diff --git a/tasks/yum_update.yml b/tasks/yum_update.yml index a09dcee..1502034 100644 --- a/tasks/yum_update.yml +++ b/tasks/yum_update.yml @@ -65,7 +65,7 @@ - name: Write Dockerfile to {{ modify_dir_path }} template: - src: Dockerfile.j2 + src: Dockerfile-yum.j2 dest: "{{ modify_dir_path }}/Dockerfile" - name: Write yum_update.sh diff --git a/templates/Dockerfile-rpm.j2 b/templates/Dockerfile-rpm.j2 new file mode 100644 index 0000000..93d70a7 --- /dev/null +++ b/templates/Dockerfile-rpm.j2 @@ -0,0 +1,13 @@ +FROM {{ source_image }} +LABEL modified_append_tag={{ modified_append_tag }} + +USER root + +{% for rpm in rpms_list %} +COPY {{ rpm | basename }} /tmp/ +{% endfor %} + +COPY rpm_install.sh /tmp/ +RUN /tmp/rpm_install.sh + +USER "{{ original_user }}" diff --git a/templates/Dockerfile.j2 b/templates/Dockerfile-yum.j2 similarity index 100% rename from templates/Dockerfile.j2 rename to templates/Dockerfile-yum.j2