Skip to content

Commit

Permalink
Add publish-dev-env job
Browse files Browse the repository at this point in the history
This job publishes dev-env to a specified registry.
The container is built based on specific sandbox_branch.

Change-Id: I2684570d4b50d795fb586283bb99812038d103b0
Partial-Bug: #1783332
  • Loading branch information
wurbanski committed Jul 27, 2018
1 parent 55daee0 commit c381395
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 14 deletions.
10 changes: 9 additions & 1 deletion .zuul.yaml
Expand Up @@ -21,7 +21,7 @@
name: dev-env-base
description: |
Base job used to work on dev-env. Contains build as a pre step.
parent: contrail-src-base
parent: contrail-base2
pre-run: playbooks/dev-env-base/pre
nodeset: builder-centos-7

Expand All @@ -32,3 +32,11 @@
Runs a set of steps to build RPMs and containers.
parent: dev-env-base
run: playbooks/test-dev-env/run

- job:
name: publish-dev-env
description: |
This job builds and publishes developer-sandbox container.
parent: dev-env-base
run: playbooks/publish-dev-env/run

11 changes: 7 additions & 4 deletions container/build.sh
@@ -1,16 +1,19 @@
#!/bin/bash
BRANCH=master
IMAGE=opencontrail/developer-sandbox

while getopts ":b:" opt; do
while getopts ":b:i:" opt; do
case $opt in
b) BRANCH=$OPTARG
;;
i) IMAGE=$OPTARG
;;
\?) echo "Invalid option: $opt"; exit 1;;
esac
done

shift $((OPTIND-1))

TAG=${1:-centos-7.4}
echo Building contrail-dev-env image: opencontrail/developer-sandbox:${TAG}
docker build --build-arg BRANCH=${BRANCH} --no-cache --tag opencontrail/developer-sandbox:${TAG} .
TAG=${1:-latest}
echo Building contrail-dev-env image: ${IMAGE}:${TAG}
docker build --build-arg BRANCH=${BRANCH} --no-cache --tag ${IMAGE}:${TAG} .
16 changes: 16 additions & 0 deletions playbooks/publish-dev-env/run.yaml
@@ -0,0 +1,16 @@
- hosts: all
roles:
- zuul-include-vars
- role: add-insecure-registry
new_registry: "{{ contrail_docker_registry }}"

- hosts: all
name: Publish containers to the internal registry
roles:
- role: publish-container-images
registry: "{{ contrail_docker_registry }}"
tag: "{{ packaging.docker_version }}"
images:
- name: "{{ image_name }}"
tag: "{{ image_tag }}"

3 changes: 2 additions & 1 deletion roles/build-dev-env/defaults/main.yaml
@@ -1,2 +1,3 @@
container_tag: "{{ zuul.change }}-{{ zuul.patchset }}-{{ zuul.buildset[0:9] }}"
image_tag: "{{ packaging.docker_version }}"
image_name: "opencontrailnightly/developer-sandbox"
sandbox_branch: "{{ zuul.branch }}"
2 changes: 1 addition & 1 deletion roles/build-dev-env/tasks/main.yaml
Expand Up @@ -13,7 +13,7 @@
become: true

- name: build image
command: ./build.sh -b "{{ sandbox_branch }}" "{{ container_tag }}"
command: ./build.sh -b "{{ sandbox_branch }}" -i "{{ image_name }}" "{{ image_tag }}"
args:
chdir: "{{ zuul.project.src_dir }}/container"
become: true
Expand Down
4 changes: 4 additions & 0 deletions roles/publish-dev-env/defaults/main.yaml
@@ -0,0 +1,4 @@
image_tag: "{{ packaging.docker_version }}"
image_name: "opencontrailnightly/developer-sandbox"
image_target: "opencontrail/developer-sandbox"
sandbox_branch: "{{ zuul.branch }}"
12 changes: 12 additions & 0 deletions roles/publish-dev-env/tasks/main.yaml
@@ -0,0 +1,12 @@
---

- name: Retag developer-sandbox
command: >
docker tag {{ image_name }}:{{ image_tag }}
{{ image_target }}:{{ sandbox_branch }}
become: true

- name: Push developer-sandbox
command: >
docker push {{ image_target }}:{{ sandbox_branch }}
become: true
3 changes: 2 additions & 1 deletion roles/test-dev-env/defaults/main.yaml
@@ -1 +1,2 @@
container_tag: "{{ zuul.change }}-{{ zuul.patchset }}-{{ zuul.buildset[0:9] }}"
image_tag: "{{ packaging.docker_version }}"
image_name: "opencontrailnightly/developer-sandbox"
2 changes: 1 addition & 1 deletion roles/test-dev-env/tasks/main.yaml
@@ -1,5 +1,5 @@
- name: startup
command: ./startup.sh -t {{ container_tag }}
command: ./startup.sh -i "{{ image_name }}" -t "{{ image_tag }}"
args:
chdir: "{{ zuul.project.src_dir }}"
become: true
Expand Down
14 changes: 9 additions & 5 deletions startup.sh
Expand Up @@ -7,10 +7,14 @@ scriptdir=$(dirname "$0")
cd "$scriptdir"
setup_only=0
own_vm=0
DEVENVTAG=centos-7.4
DEVENVTAG=latest
IMAGE=opencontrailnightly/developer-sandbox

while getopts ":t:sb" opt; do
while getopts ":t:i:sb" opt; do
case $opt in
i)
IMAGE=$OPTARG
;;
t)
DEVENVTAG=$OPTARG
;;
Expand Down Expand Up @@ -98,15 +102,15 @@ fi

if [[ "$own_vm" -eq 0 ]]; then
if ! is_created "contrail-developer-sandbox"; then
if [[ x"$DEVENVTAG" == x"centos-7.4" ]]; then
docker pull opencontrail/developer-sandbox:${DEVENVTAG}
if [[ x"$DEVENVTAG" == x"latest" ]]; then
docker pull ${IMAGE}:${DEVENVTAG}
fi
docker run --privileged --name contrail-developer-sandbox \
-w /root -itd \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ${rpm_source}:/root/contrail/RPMS \
-v $(pwd):/root/contrail-dev-env \
opencontrail/developer-sandbox:${DEVENVTAG} >/dev/null
${IMAGE}:${DEVENVTAG} >/dev/null
echo contrail-developer-sandbox created.
else
if is_up "contrail-developer-sandbox"; then
Expand Down

0 comments on commit c381395

Please sign in to comment.