diff --git a/README.rst b/README.rst index 3e664eb..3c212c0 100644 --- a/README.rst +++ b/README.rst @@ -26,8 +26,8 @@ Role Variables - `[undefined]` - If set, the modified image will be tagged with `target_image + modified_append_tag`. If `target_image` is not set, the modified image will be tagged with `source_image + modified_append_tag`. If the purpose of the image is not changing, it may be enough to rely on the `source_image + modified_append_tag` tag to identify that this is a modified version of the source image. * - `container_build_tool` - - `docker` - - Tool used to build containers, can be 'docker' or 'buildah' + - `buildah` + - Tool used to build containers, can be only 'buildah' .. list-table:: Variables used for yum update :widths: auto @@ -56,7 +56,6 @@ Role Variables - `None` - Optional path of directory to be used as `/etc/yum.repos.d` during the update * - `container_build_tool` - - `docker` - See modify image variables * - `yum_cache` - `None` @@ -91,7 +90,6 @@ Role Variables - `None` - Optional path of directory to be used as `/etc/yum.repos.d` during the update * - `container_build_tool` - - `docker` - See modify image variables @@ -112,7 +110,6 @@ Role Variables - `''` - See modify image variables * - `container_build_tool` - - `docker` - See modify image variables * - `refspecs` - `[]` @@ -127,8 +124,6 @@ Requirements - ansible >= 2.4 - python >= 2.6 - - docker-py >= 1.7.0 - - Docker API >= 1.20 Dependencies ------------ @@ -156,7 +151,7 @@ The following playbook will produce a modified image with the tag vars: source_image: docker.io/tripleomaster/centos-binary-nova-api:latest modify_dir_path: /path/to/example_modify_dir - container_build_tool: docker # or buildah + container_build_tool: buildah The directory `example_modify_dir` contains the `Dockerfile` which will perform the modification, for example: @@ -197,7 +192,7 @@ In this playbook the tasks\_from is set as a variable instead of an source_image: docker.io/tripleomaster/centos-binary-nova-api:latest yum_repos_dir_path: /etc/yum.repos.d modified_append_tag: updated - container_build_tool: buildah # or docker + container_build_tool: buildah yum_cache: /tmp/containers-updater/yum_cache rpms_path: /home/stack/rpms @@ -212,7 +207,7 @@ In this playbook the tasks\_from is set as a variable instead of an tasks_from: yum_update.yml source_image: docker.io/tripleomaster/centos-binary-nova-api:latest modified_append_tag: updated - container_build_tool: docker # or buildah + container_build_tool: buildah rpms_path: /home/stack/rpms/ Note, if you have a locally installed gating repo, you can add @@ -240,7 +235,7 @@ a variable instead of an `import_role` parameter. source_image: docker.io/tripleomaster/centos-binary-nova-api:latest yum_repos_dir_path: /etc/yum.repos.d yum_packages: ['foobar-nova-plugin', 'fizzbuzz-nova-plugin'] - container_build_tool: docker # or buildah + container_build_tool: buildah RPM install ~~~~~~~~~~~ diff --git a/defaults/main.yml b/defaults/main.yml index d46f9b9..b587eea 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,6 +1,6 @@ --- update_repo: '' -container_build_tool: 'docker' +container_build_tool: 'buildah' python_dir: [] refspecs: [] yum_packages: [] diff --git a/meta/main.yml b/meta/main.yml index cb172cb..55602a7 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -12,7 +12,6 @@ galaxy_info: - 7 galaxy_tags: - - docker - buildah - container - openstack diff --git a/tasks/get_original_user.yml b/tasks/get_original_user.yml index a6602c6..49743a1 100644 --- a/tasks/get_original_user.yml +++ b/tasks/get_original_user.yml @@ -1,45 +1,14 @@ --- -- when: container_build_tool == 'docker' - block: - - name: Inspect image with Docker - docker_image_facts: - name: "{{ source_image }}" - retries: 5 - delay: 5 - until: source_image_facts.images is defined - register: source_image_facts - - block: - - name: Pull Docker image if not currently downloaded - docker_image: - name: "{{ source_image }}" - - name: Inspect image with Docker - docker_image_facts: - name: "{{ source_image }}" - retries: 5 - delay: 5 - until: downloaded_image_facts.images is defined - register: downloaded_image_facts - # https://github.com/ansible/ansible/issues/15710#issuecomment-216645922 - - name: Override source_image_facts - set_fact: - source_image_facts: "{{ downloaded_image_facts }}" - when: source_image_facts.images | length == 0 - - name: Set original_user with Docker - set_fact: - original_user: "{{ source_image_facts.images[0].Config.User }}" - -- when: container_build_tool == 'buildah' - block: - - name: Ensure image exists - shell: podman image exists {{ source_image }} || podman pull {{ source_image }} - become: true - - name: Inspect image with Buildah - command: buildah inspect {{ source_image }} - register: source_image_facts - become: true - - name: Set config with Buildah - set_fact: - buildah_config: "{{ source_image_facts.stdout_lines | join('') | from_json }}" - - name: Set original_user with Buildah - set_fact: - original_user: "{{ buildah_config['Docker']['config']['User'] }}" +- name: Ensure image exists + shell: podman image exists {{ source_image }} || podman pull {{ source_image }} + become: true +- name: Inspect image with Buildah + command: buildah inspect {{ source_image }} + register: source_image_facts + become: true +- name: Set config with Buildah + set_fact: + buildah_config: "{{ source_image_facts.stdout_lines | join('') | from_json }}" +- name: Set original_user with Buildah + set_fact: + original_user: "{{ buildah_config['Docker']['config']['User'] }}" diff --git a/tasks/precheck.yml b/tasks/precheck.yml index 2fb2fd0..75a2eaf 100644 --- a/tasks/precheck.yml +++ b/tasks/precheck.yml @@ -7,8 +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'] + container_build_tool. Use 'buildah'." + when: container_build_tool != 'buildah' - name: Set default modified_append_tag set_fact: diff --git a/tasks/yum_install.yml b/tasks/yum_install.yml index 5bb9973..547e507 100644 --- a/tasks/yum_install.yml +++ b/tasks/yum_install.yml @@ -5,6 +5,3 @@ - import_tasks: yum_install_buildah.yml when: container_build_tool == 'buildah' - -- import_tasks: yum_install_docker.yml - when: container_build_tool == 'docker' diff --git a/tasks/yum_install_docker.yml b/tasks/yum_install_docker.yml deleted file mode 100644 index 6d11b37..0000000 --- a/tasks/yum_install_docker.yml +++ /dev/null @@ -1,57 +0,0 @@ ---- -- 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-install.j2 - dest: "{{ modify_dir_path }}/Dockerfile" - -- name: Write yum_install.sh - copy: - src: yum_install.sh - dest: "{{ modify_dir_path }}/yum_install.sh" - mode: '0555' - -- include_tasks: modify_image.yml - -- name: Clean modify directory - file: - state: absent - path: "{{ modify_dir_path }}" diff --git a/tasks/yum_update.yml b/tasks/yum_update.yml index 72ecb70..6fdfc36 100644 --- a/tasks/yum_update.yml +++ b/tasks/yum_update.yml @@ -5,6 +5,3 @@ - import_tasks: yum_update_buildah.yml when: container_build_tool == 'buildah' - -- import_tasks: yum_update_docker.yml - when: container_build_tool == 'docker' diff --git a/tasks/yum_update_docker.yml b/tasks/yum_update_docker.yml deleted file mode 100644 index ea2e3f5..0000000 --- a/tasks/yum_update_docker.yml +++ /dev/null @@ -1,71 +0,0 @@ ---- -- 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 }}" - -- import_tasks: copy_rpms.yml - -- 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 and rpms_path is undefined - -- name: Write Dockerfile to {{ modify_dir_path }} - template: - src: Dockerfile-yum.j2 - dest: "{{ modify_dir_path }}/Dockerfile" - -- name: Identify the primary package manager (dnf or yum) - shell: command -v dnf || command -v yum - register: pkg_mgr_output - -- name: Set fact for the used package manager binary - set_fact: - pkg_mgr: "{{ pkg_mgr_output.stdout }}" - -- name: Set fact for the used cache path - set_fact: - cache_path: /var/cache/{{ pkg_mgr.split('/')[-1] }} - -- name: Write yum_update.sh - template: - src: yum_update.sh.j2 - 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 }}" diff --git a/templates/yum_update.sh.j2 b/templates/yum_update.sh.j2 index 6d4a28b..8ce22a6 100755 --- a/templates/yum_update.sh.j2 +++ b/templates/yum_update.sh.j2 @@ -55,7 +55,3 @@ sync {% else %} rm -rf /var/cache/$PKG_MGR {% endif %} - -{% if container_build_tool is defined and container_build_tool == 'docker' %} -rm -f /tmp/yum_install.sh -{% endif %} diff --git a/vars/main.yml b/vars/main.yml index 44af6c1..043446f 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,6 +1,3 @@ --- -# NOTE(aschultz): remove --format docker when oci images are properly supported -# we support 'docker' or 'buildah' build_commands: - docker: docker build buildah: buildah bud --format docker