RETIRED, Ansible role to modify container images built for TripleO
Go to file
Alex Schultz 012209ae34 Convert readme to rst
In order to release we need to fix some linting issues in the readme for
pypi. Let's switch it to rst to be consistent with the new standard.

Change-Id: Ifcdc3289b0a626e43f687c429d0a5fc082d13a6e
2019-04-01 09:47:22 -06:00
ci-scripts Add tox checks, pbr packaging 2018-05-23 11:57:41 +12:00
defaults Run all linters via pre-commit 2019-02-15 18:22:10 +05:30
files Don't print commands during yum update 2019-03-22 11:30:56 +13:00
meta Run all linters via pre-commit 2019-02-15 18:22:10 +05:30
tasks Run all linters via pre-commit 2019-02-15 18:22:10 +05:30
templates Fix dev install (yum -y...) 2019-02-20 14:41:15 +00:00
vars Run all linters via pre-commit 2019-02-15 18:22:10 +05:30
zuul.d Run all linters via pre-commit 2019-02-15 18:22:10 +05:30
.ansible-lint Run all linters via pre-commit 2019-02-15 18:22:10 +05:30
.gitreview Add .gitreview file 2018-05-25 08:35:01 +12:00
.pre-commit-config.yaml Run all linters via pre-commit 2019-02-15 18:22:10 +05:30
.yamllint Run all linters via pre-commit 2019-02-15 18:22:10 +05:30
ansible-requirements.txt Add tox checks, pbr packaging 2018-05-23 11:57:41 +12:00
ansible.cfg Fix the roles_path to actually work in a venv 2018-08-29 15:46:57 -04:00
LICENSE Run all linters via pre-commit 2019-02-15 18:22:10 +05:30
README.rst Convert readme to rst 2019-04-01 09:47:22 -06:00
requirements.txt Add tox checks, pbr packaging 2018-05-23 11:57:41 +12:00
setup.cfg Convert readme to rst 2019-04-01 09:47:22 -06:00
setup.py Run all linters via pre-commit 2019-02-15 18:22:10 +05:30
test-requirements.txt Run all linters via pre-commit 2019-02-15 18:22:10 +05:30
tox.ini Run all linters via pre-commit 2019-02-15 18:22:10 +05:30

TripleO Modify Image

A role to allow modification to container images built for the TripleO project.

Role Variables

Variables used for modify image
Name Default Value Description
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.
target_image [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'
Variables used for yum update
Name Default Value Description
source_image [undefined] See modify image variables
modified_append_tag date +-modified-%Y%m%d%H%M%S See modify image variables
target_image '' See modify image variables
update_repo '' If set, packages from this repo will be updated. Other repos will only be used for dependencies of these updates.
yum_repos_dir_path None Optional path of directory to be used as /etc/yum.repos.d during the update
container_build_tool docker See modify image variables
Variables used for def install
Name Default Value Description
source_image [undefined] See modify image variables
modified_append_tag date +-modified-%Y%m%d%H%M%S See modify image variables
target_image '' See modify image variables
container_build_tool docker See modify image variables
refspecs [] An array of project/refspec pairs that will be installed into the generated container. Currently only supports python source projects.

Requirements

  • ansible >= 2.4
  • python >= 2.6
  • docker-py >= 1.7.0
  • Docker API >= 1.20

Dependencies

None

Example Playbooks

Modify Image

The following playbook will produce a modified image with the tag :latest-modified-<timestamp> based on the Dockerfile in the custom directory /path/to/example_modify_dir.

- hosts: localhost
  tasks:
  - name: include tripleo-modify-image
    import_role:
      name: tripleo-modify-image
      tasks_from: modify_image.yml
    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

The directory example_modify_dir contains the Dockerfile which will perform the modification, for example:

# This will be replaced in the file Dockerfile.modified
FROM centos-binary-nova-api

# switch to root to install packages
USER root

# install packages
RUN curl "https://bootstrap.pypa.io/get-pip.py" -o "/tmp/get-pip.py"
RUN python /tmp/get-pip.py

# switch the container back to the default user
USER nova

Yum update

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 of an import_role parameter.

- hosts: localhost
  tasks:
  - name: include tripleo-modify-image
    import_role:
      name: tripleo-modify-image
    vars:
      tasks_from: yum_update.yml
      source_image: docker.io/tripleomaster/centos-binary-nova-api:latest
      compare_host_packages: true
      yum_repos_dir_path: /etc/yum.repos.d
      modified_append_tag: updated
      container_build_tool: docker # or buildah

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

Dev install

The following playbook will produce a modified image with Python source code installed via pip. To minimize dependencies within the container we generate the sdist locally and then copy it into the resulting container image as an sdist tarball to run pip install locally.

- hosts: localhost
  connection: local
  tasks:
  - name: dev install heat-api
    import_role:
      name: tripleo-modify-image
    vars:
      tasks_from: dev_install.yml
      source_image: docker.io/tripleomaster/centos-binary-heat-api:current-tripleo
      refspecs:
        -
          project: heat
          refspec: refs/changes/12/1234/3
      modified_append_tag: -devel

License

Apache 2.0