Add dev mode install playbook for source installs

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.

Useful for local ad-hoc testing of upstream patches without
having to build and RPM in those cases.

Change-Id: I93c0e86b2e421b0bcb777d536fcb0d30e0ee3b68
This commit is contained in:
Dan Prince 2018-08-29 15:45:56 -04:00
parent 34293e3e08
commit 618d3ab83c
4 changed files with 109 additions and 0 deletions

View File

@ -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

32
files/dev_install.sh Normal file
View File

@ -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

34
tasks/dev_install.yml Normal file
View File

@ -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

View File

@ -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 }}"