diff --git a/README.md b/README.md index 8571321..46c3fc2 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,18 @@ A role to allow modification to container images built for the TripleO project. | `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 dev 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 @@ -112,6 +124,28 @@ network connectivity. 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 diff --git a/files/dev_install.sh b/files/dev_install.sh new file mode 100644 index 0000000..ee5d2d6 --- /dev/null +++ b/files/dev_install.sh @@ -0,0 +1,32 @@ +set -e + +# Cherry-pick a refspec +# $1 : project name e.g. keystone +# $2 : Gerrit refspec(s) to cherry pick +function cherrypick(){ + local PROJ_NAME=$1 + local REFSPECS="$2" + + # check that git is installed + if ! rpm -qi git &> /dev/null; then + echo "Please install git before using this module." + exit 1 + fi + + if [ ! -d "$PROJ_NAME" ]; then + git clone "https://git.openstack.org/openstack/$PROJ_NAME" + fi + cd "$PROJ_NAME" + for REFSPEC in $REFSPECS; do + git fetch "https://review.openstack.org/openstack/$PROJ_NAME" "$REFSPEC" + git cherry-pick FETCH_HEAD || git cherry-pick --abort + done + + 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 diff --git a/tasks/dev_install.yml b/tasks/dev_install.yml new file mode 100644 index 0000000..2979b3f --- /dev/null +++ b/tasks/dev_install.yml @@ -0,0 +1,34 @@ +- 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: Write Dockerfile to {{ modify_dir_path }} + template: + src: Dockerfile-dev.j2 + dest: "{{ modify_dir_path }}/Dockerfile" + +- name: Write dev_install.sh + copy: + src: dev_install.sh + dest: "{{ modify_dir_path }}/dev_install.sh" + mode: '0555' + +- name: Git checkout the refspecs into local temp dir + command: "/bin/bash dev_install.sh {{ item.project }} {{ item.refspec }}" + args: + chdir: "{{ modify_dir_path }}" + loop: "{{ refspecs }}" + +- include_tasks: modify_image.yml diff --git a/templates/Dockerfile-dev.j2 b/templates/Dockerfile-dev.j2 new file mode 100644 index 0000000..8e4d100 --- /dev/null +++ b/templates/Dockerfile-dev.j2 @@ -0,0 +1,9 @@ +FROM {{ source_image }} +LABEL modified_append_tag={{ modified_append_tag }} + +USER root + +COPY refspec_projects /root/refspec_projects +RUN /bin/bash -c 'rpm -qi python-pip || yum install -y python-pip; cd /; for X in $(ls /root/refspec_projects/*.tar.gz); do pip install $X; done; rm -Rf /root/refspec_projects' + +USER "{{ original_user }}"