From b25fe2590cc8d8d15968cabf36d5fdb421ead083 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Fri, 14 Jun 2019 16:13:23 -0400 Subject: [PATCH] Allow devs to modify images with Python directories This will allow dev to update their container images from a local Python directory, example in /home/joe/git/openstack/heat. The new parameter python_dir is a list of directories. To use it, your playbook must be like: - 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 modified_append_tag: -devel python_dir: - /home/joe/git/openstack/heat Change-Id: I182c3fa58dc9af870e0da9f51ae1e22aa90d03e5 --- README.rst | 24 +++++++++++++++++++++++- defaults/main.yml | 2 ++ files/dev_install.sh | 18 +++++++++++++++++- tasks/dev_install.yml | 12 ++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 9c6d923..736b8a5 100644 --- a/README.rst +++ b/README.rst @@ -56,7 +56,7 @@ Role Variables - See modify image variables -.. list-table:: Variables used for def install +.. list-table:: Variables used for dev install :widths: auto :header-rows: 1 @@ -78,6 +78,9 @@ Role Variables * - `refspecs` - `[]` - An array of project/refspec pairs that will be installed into the generated container. Currently only supports python source projects. + * - `python_dir` + - `[]` + - Directory which contains a Python project ready to be installed with pip. Requirements @@ -188,6 +191,8 @@ 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. +It can be used to pull a review from OpenDev Gerrit: + .. code-block:: - hosts: localhost @@ -205,6 +210,23 @@ container image as an sdist tarball to run pip install locally. refspec: refs/changes/12/1234/3 modified_append_tag: -devel +or it can be used to build an image from a local Python directory: + +.. code-block:: + + - 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 + modified_append_tag: -devel + python_dir: + - /home/joe/git/openstack/heat + License ------- diff --git a/defaults/main.yml b/defaults/main.yml index 13ae719..8cc6510 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,3 +1,5 @@ --- update_repo: '' container_build_tool: 'docker' +python_dir: [] +refspecs: [] diff --git a/files/dev_install.sh b/files/dev_install.sh index 99553eb..8397692 100644 --- a/files/dev_install.sh +++ b/files/dev_install.sh @@ -27,6 +27,22 @@ function cherrypick { } +# Copy a Python directory +# $1 : Python directory to copy and install to generate a tarball. +function copy { + local PYTHON_DIR=$1 + + rm -rf dev + cp -r $PYTHON_DIR dev + cd dev + SKIP_GENERATE_AUTHORS=1 SKIP_WRITE_GIT_CHANGELOG=1 python setup.py sdist + cp dist/*.tar.gz ../ +} + mkdir -p refspec_projects cd refspec_projects -cherrypick $1 $2 +if [[ "$GERRIT_MODE" == 1 ]]; then + cherrypick $1 $2 +else + copy $1 +fi diff --git a/tasks/dev_install.yml b/tasks/dev_install.yml index 5271b30..e170254 100644 --- a/tasks/dev_install.yml +++ b/tasks/dev_install.yml @@ -28,8 +28,20 @@ - name: Git checkout the refspecs into local temp dir command: "/bin/bash dev_install.sh {{ item.project }} {{ item.refspec }}" + environment: + GERRIT_MODE: 1 args: chdir: "{{ modify_dir_path }}" loop: "{{ refspecs }}" + when: item > 0 + +- name: Copy the Python directories into local temp dir + command: "/bin/bash dev_install.sh {{ item }}" + environment: + GERRIT_MODE: 0 + args: + chdir: "{{ modify_dir_path }}" + loop: "{{ python_dir }}" + when: item > 0 - include_tasks: modify_image.yml