diff --git a/tasks/modify_image.yml b/tasks/modify_image.yml index 9464aa7..567504e 100644 --- a/tasks/modify_image.yml +++ b/tasks/modify_image.yml @@ -8,11 +8,6 @@ - modify_dir_path is defined - modify_dir_path | length > 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: Create Dockerfile tempfile name tempfile: path: "{{ modify_dir_path }}" diff --git a/tasks/precheck.yml b/tasks/precheck.yml index adf54fd..6649784 100644 --- a/tasks/precheck.yml +++ b/tasks/precheck.yml @@ -7,3 +7,8 @@ - name: Ensure that container_build_tool is correctly set fail: msg="{{ container_build_tool }} is not a valid value for container_build_tool. Pick docker or buildah." when: container_build_tool not in ['docker', 'buildah'] + +- 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 diff --git a/tasks/yum_update.yml b/tasks/yum_update.yml index 13e27b0..47497ac 100644 --- a/tasks/yum_update.yml +++ b/tasks/yum_update.yml @@ -2,55 +2,8 @@ tags: - always -- import_tasks: get_original_user.yml +- import_tasks: yum_update_buildah.yml + when: container_build_tool == 'buildah' -- 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: Copy local file repos to context directory - shell: | - #!/bin/sh - set -ex - - cp -a {{ yum_repos_dir_path }} {{ modify_dir_path }}/yum.repos.d - - # discover repos with local packages - repos=$(sed -n 's/baseurl=file:\/\///p' {{ yum_repos_dir_path }}/*.repo) - - mkdir repos - for repo in $repos ; do - if [ -d $repo ]; then - target_dir=repos$repo - echo "copying $repo to $target_dir" - mkdir -p $target_dir - cp -a $repo/* $target_dir - fi - done - args: - chdir: "{{ modify_dir_path }}" - when: yum_repos_dir_path is defined - -- name: Write Dockerfile to {{ modify_dir_path }} - template: - src: Dockerfile-yum.j2 - dest: "{{ modify_dir_path }}/Dockerfile" - -- name: Write yum_update.sh - copy: - src: yum_update.sh - dest: "{{ modify_dir_path }}/yum_update.sh" - mode: '0555' - -- include_tasks: modify_image.yml - -- name: Clean modify directory - file: - state: absent - path: "{{ modify_dir_path }}" +- import_tasks: yum_update_docker.yml + when: container_build_tool == 'docker' diff --git a/tasks/yum_update_buildah.yml b/tasks/yum_update_buildah.yml new file mode 100644 index 0000000..36f6350 --- /dev/null +++ b/tasks/yum_update_buildah.yml @@ -0,0 +1,49 @@ +- import_tasks: precheck.yml + tags: + - always + +- name: From image {{ source_image }} + command: buildah from {{ source_image }} + register: from_image_cmd + +- name: Set from_image + set_fact: + from_image: "{{ from_image_cmd.stdout }}" + +- name: Run buildah config + command: > + buildah config + --label modified_append_tag={{ modified_append_tag }} + --workingdir / {{ from_image }} + +- name: Copy yum_update.sh + command: > + buildah copy + {{ from_image }} + files/yum_update.sh /tmp/yum_update.sh + +- name: List file repos + shell: sed -n 's|baseurl=file://||p' *.repo + args: + chdir: "{{ yum_repos_dir_path }}" + register: file_repos + +- name: Run yum_update.sh + command: > + buildah run + --volume {{ yum_repos_dir_path }}:/etc/yum.repos.d + {% for repo in file_repos.stdout_lines %} + {% if repo|exists %} + --volume {{ repo }}:{{ repo }} + {% endif %} + {% endfor %} + --user root + --net host + {{ from_image }} + /tmp/yum_update.sh "{{ update_repo }}" + +- name: Commit changes to image {{ target_image | default(source_image) }} + command: > + buildah commit + {{ from_image }} + {{ target_image | default(source_image) }} diff --git a/tasks/yum_update_docker.yml b/tasks/yum_update_docker.yml new file mode 100644 index 0000000..13e27b0 --- /dev/null +++ b/tasks/yum_update_docker.yml @@ -0,0 +1,56 @@ +- import_tasks: precheck.yml + tags: + - always + +- import_tasks: get_original_user.yml + +- 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: Copy local file repos to context directory + shell: | + #!/bin/sh + set -ex + + cp -a {{ yum_repos_dir_path }} {{ modify_dir_path }}/yum.repos.d + + # discover repos with local packages + repos=$(sed -n 's/baseurl=file:\/\///p' {{ yum_repos_dir_path }}/*.repo) + + mkdir repos + for repo in $repos ; do + if [ -d $repo ]; then + target_dir=repos$repo + echo "copying $repo to $target_dir" + mkdir -p $target_dir + cp -a $repo/* $target_dir + fi + done + args: + chdir: "{{ modify_dir_path }}" + when: yum_repos_dir_path is defined + +- name: Write Dockerfile to {{ modify_dir_path }} + template: + src: Dockerfile-yum.j2 + dest: "{{ modify_dir_path }}/Dockerfile" + +- name: Write yum_update.sh + copy: + src: yum_update.sh + dest: "{{ modify_dir_path }}/yum_update.sh" + mode: '0555' + +- include_tasks: modify_image.yml + +- name: Clean modify directory + file: + state: absent + path: "{{ modify_dir_path }}"