Add rpm_install tasks
This patch adds a new rpm_install tasks which can be used to build a new container layer from a set of local RPMs. This is useful for building contains locally with no network connectivity. As part of the change the existing Yum update Dockerfile.j2 was renamed to Dockerfile-yum.j2 to make it more specific. Change-Id: I951c976ebb84c28cecefd2f5753a8232f46ad4aa
This commit is contained in:
parent
68703e732d
commit
7178d84867
21
README.md
21
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
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
rpm -Uvh /tmp/*.rpm
|
||||
rm -f /tmp/*.rpm
|
||||
rm -f /tmp/rpm_install.sh
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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 }}"
|
Loading…
Reference in New Issue