diff options
author | jose.lausuch <jose.lausuch@ericsson.com> | 2016-11-22 16:29:20 +0100 |
---|---|---|
committer | jose.lausuch <jose.lausuch@ericsson.com> | 2016-11-28 10:24:21 +0100 |
commit | d84b20c90908bfa4e2e544f06b422226b67e2b26 (patch) | |
tree | 7c918003f8390a2b140822b237763b7583a19b50 | |
parent | 3dd256b66f19f382eb3cdb27719af48c84e84804 (diff) |
Refactor Docker build jobs
- Remove incremental tags for stable branches
- Use "latest" or "stable" tags only
- Have a single job template for all projects
More info here: https://wiki.opnfv.org/display/INF/Docker+handling+in+CI
Change-Id: Ibce3ef2faee136f56f0eab12dfe7a93c267db854
Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
-rw-r--r-- | jjb/opnfv/opnfv-docker.sh | 52 | ||||
-rw-r--r-- | jjb/opnfv/opnfv-docker.yml | 153 | ||||
-rwxr-xr-x | utils/calculate_version.sh | 136 |
3 files changed, 42 insertions, 299 deletions
diff --git a/jjb/opnfv/opnfv-docker.sh b/jjb/opnfv/opnfv-docker.sh index e637f7b32..e0fbb7564 100644 --- a/jjb/opnfv/opnfv-docker.sh +++ b/jjb/opnfv/opnfv-docker.sh @@ -20,7 +20,7 @@ echo if [[ -n $(ps -ef|grep 'docker build'|grep -v grep) ]]; then echo "There is already another build process in progress:" echo $(ps -ef|grep 'docker build'|grep -v grep) - # Abort this job since it will colide and might mess up the current one. + # Abort this job since it will collide and might mess up the current one. echo "Aborting..." exit 1 fi @@ -51,20 +51,6 @@ if [[ -n "$(docker images | grep $DOCKER_REPO_NAME)" ]]; then done fi -# If we just want to update the latest_stable image -if [[ "$UPDATE_LATEST_STABLE" == "true" ]]; then - echo "Pulling $DOCKER_REPO_NAME:$STABLE_TAG ..." - docker pull $DOCKER_REPO_NAME:$STABLE_TAG - if [[ $? -ne 0 ]]; then - echo "ERROR: The image $DOCKER_REPO_NAME with tag $STABLE_TAG does not exist." - exit 1 - fi - docker tag $DOCKER_REPO_NAME:$STABLE_TAG $DOCKER_REPO_NAME:latest_stable - echo "Pushing $DOCKER_REPO_NAME:latest_stable ..." - docker push $DOCKER_REPO_NAME:latest_stable - exit 0 -fi - # cd to directory where Dockerfile is located cd $WORKSPACE/docker @@ -78,35 +64,20 @@ branch="${GIT_BRANCH##origin/}" echo "Current branch: $branch" if [[ "$branch" == "master" ]]; then - DOCKER_TAG="master" - DOCKER_BRANCH_TAG="latest" + DOCKER_TAG="latest" else - git clone https://gerrit.opnfv.org/gerrit/releng $WORKSPACE/releng - - DOCKER_TAG=$($WORKSPACE/releng/utils/calculate_version.sh -t docker \ - -n $DOCKER_REPO_NAME) - DOCKER_BRANCH_TAG="stable" - - ret_val=$? - if [[ $ret_val -ne 0 ]]; then - echo "Error retrieving the version tag." - exit 1 - fi + DOCKER_TAG="stable" fi -echo "Tag version to be build and pushed: $DOCKER_TAG" - # Start the build -echo "Building docker image: $DOCKER_REPO_NAME:$DOCKER_BRANCH_TAG" +echo "Building docker image: $DOCKER_REPO_NAME:$DOCKER_TAG" +echo "--------------------------------------------------------" +echo +cmd="docker build --no-cache -t $DOCKER_REPO_NAME:$DOCKER_TAG --build-arg BRANCH=$branch ." -if [[ $DOCKER_REPO_NAME == *"functest"* ]]; then - docker build --no-cache -t $DOCKER_REPO_NAME:$DOCKER_BRANCH_TAG --build-arg BRANCH=$branch . -else - docker build --no-cache -t $DOCKER_REPO_NAME:$DOCKER_BRANCH_TAG . -fi +echo ${cmd} +${cmd} -echo "Creating tag '$DOCKER_TAG'..." -docker tag $DOCKER_REPO_NAME:$DOCKER_BRANCH_TAG $DOCKER_REPO_NAME:$DOCKER_TAG # list the images echo "Available images are:" @@ -117,10 +88,5 @@ if [[ "$PUSH_IMAGE" == "true" ]]; then echo "Pushing $DOCKER_REPO_NAME:$DOCKER_TAG to the docker registry..." echo "--------------------------------------------------------" echo - # Push to the Dockerhub repository - echo "Pushing $DOCKER_REPO_NAME:$DOCKER_BRANCH_TAG ..." - docker push $DOCKER_REPO_NAME:$DOCKER_BRANCH_TAG - - echo "Pushing $DOCKER_REPO_NAME:$DOCKER_TAG ..." docker push $DOCKER_REPO_NAME:$DOCKER_TAG fi diff --git a/jjb/opnfv/opnfv-docker.yml b/jjb/opnfv/opnfv-docker.yml index f313b3b92..0df0ddf6f 100644 --- a/jjb/opnfv/opnfv-docker.yml +++ b/jjb/opnfv/opnfv-docker.yml @@ -6,31 +6,44 @@ name: opnfv-docker + master: &master + stream: master + branch: '{stream}' + disabled: false + colorado: &colorado + stream: colorado + branch: 'stable/{stream}' + disabled: false + project: - - 'bottlenecks' - - 'cperf' - - 'functest' - - 'storperf' - - 'qtip' + # projects with jobs for master + - 'bottlenecks': + <<: *master + - 'cperf': + <<: *master + - 'dovetail': + <<: *master + - 'functest': + <<: *master + - 'qtip': + <<: *master + - 'storperf': + <<: *master + - 'yardstick': + <<: *master + # projects with jobs for stable + - 'bottlenecks': + <<: *colorado + - 'functest': + <<: *colorado + - 'storperf': + <<: *colorado + - 'yardstick': + <<: *colorado jobs: - '{project}-docker-build-push-{stream}' - - 'yardstick-docker-build-push-{stream}' - #dovetail not sync with release, an independent job - #only master by now, will adjust accordingly in future - - 'dovetail-docker-build-push-{dovetailstream}' - stream: - - master: - branch: '{stream}' - disabled: false - - colorado: - branch: 'stable/{stream}' - disabled: false - dovetailstream: - - master: - branch: '{dovetailstream}' - disabled: false ######################## # job templates @@ -49,20 +62,9 @@ default: "true" description: "To enable/disable pushing the image to Dockerhub." - string: - name: BASE_VERSION - default: "colorado.0" - description: "Base version to be used." - - string: name: DOCKER_REPO_NAME default: "opnfv/{project}" description: "Dockerhub repo to be pushed to." - - string: - name: UPDATE_LATEST_STABLE - default: "false" - description: "This will update the latest_stable image only." - - string: - name: STABLE_TAG - description: "If above option is true, this is the tag to be pulled." scm: - git-scm: @@ -78,92 +80,3 @@ - pollscm: cron: "*/30 * * * *" -- job-template: - name: 'yardstick-docker-build-push-{stream}' - - disabled: '{obj:disabled}' - - parameters: - - project-parameter: - project: 'yardstick' - - 'opnfv-build-ubuntu-defaults' - - string: - name: PUSH_IMAGE - default: "true" - description: "To enable/disable pushing the image to Dockerhub." - - string: - name: BASE_VERSION - default: "colorado.0" - description: "Base version to be used." - - string: - name: DOCKER_REPO_NAME - default: "opnfv/yardstick" - description: "Dockerhub repo to be pushed to." - - string: - name: UPDATE_LATEST_STABLE - default: "false" - description: "This will update the latest_stable image only." - - string: - name: STABLE_TAG - description: "If above option is true, this is the tag to be pulled." - - scm: - - git-scm: - credentials-id: '{ssh-credentials}' - refspec: '' - branch: '{branch}' - - builders: - - shell: - !include-raw-escape: ./opnfv-docker.sh - - triggers: - - pollscm: - cron: "*/30 * * * *" - -- job-template: - name: 'dovetail-docker-build-push-{dovetailstream}' - - disabled: '{obj:disabled}' - - parameters: - - project-parameter: - project: 'dovetail' - - 'opnfv-build-ubuntu-defaults' - - string: - name: PUSH_IMAGE - default: "true" - description: "To enable/disable pushing the image to Dockerhub." - #BASE_VERSION parameter is used for version control - #by now, only master branch is used, this parameter takes no effect - #once branch control settled, should be adjusted togather with - #opnfv-docker.sh and caculate_version.sh - - string: - name: BASE_VERSION - default: "1.0" - description: "Base version to be used." - - string: - name: DOCKER_REPO_NAME - default: "opnfv/dovetail" - description: "Dockerhub repo to be pushed to." - - string: - name: UPDATE_LATEST_STABLE - default: "false" - description: "This will update the latest_stable image only." - - string: - name: STABLE_TAG - description: "If above option is true, this is the tag to be pulled." - - scm: - - git-scm: - credentials-id: '{ssh-credentials}' - refspec: '' - branch: '{branch}' - - builders: - - shell: - !include-raw-escape: ./opnfv-docker.sh - - triggers: - - pollscm: - cron: "*/30 * * * *" diff --git a/utils/calculate_version.sh b/utils/calculate_version.sh deleted file mode 100755 index cf929dd5e..000000000 --- a/utils/calculate_version.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/bin/bash -# SPDX-license-identifier: Apache-2.0 -############################################################################## -# Copyright (c) 2016 Ericsson AB and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -# Calculates and generates the version tag for the OPNFV objects: -# - Docker images -# - ISOs -# - Artifacts - -info () { - logger -s -t "Calculate_version.info" "$*" -} - - -error () { - logger -s -t "Calculate_version.error" "$*" - exit 1 -} - - -#Functions which calculate the version -function docker_version() { - docker_image=$1 - url_repo="https://registry.hub.docker.com/v2/repositories/${docker_image}/" - url_tag="https://registry.hub.docker.com/v2/repositories/${docker_image}/tags/" - status=$(curl -s --head -w %{http_code} ${url_repo} -o /dev/null) - if [ "${status}" != "200" ]; then - error "Cannot access ${url_repo}. Does the image ${docker_image} exist?" - fi - tag_json=$(curl $url_tag 2>/dev/null | python -mjson.tool | grep ${BASE_VERSION} | head -1) - #e.g. tag_json= "name": "brahmaputra.0.2", - #special case, for dovetail, not sync with release, tag_json name not headed with arno, etc - if [ "${tag_json}" == "" ]; then - echo ${BASE_VERSION}.0 - else - tag=$(echo $tag_json | awk '{print $2}' | sed 's/\,//' | sed 's/\"//g') - #e.g.: tag=brahmaputra.0.2 - #special case, for dovetail, not sync with release - tag_current_version=$(echo $tag | sed 's/.*\.//') - tag_new_version=$(($tag_current_version+1)) - #e.g.: tag=brahmaputra.0.3 - echo ${BASE_VERSION}.${tag_new_version} - fi -} - - -function artifact_version() { - # To be done - error "Not supported yet..." -} - - -STORAGE_TYPES=(docker artifactrepo) -TYPE="" -NAME="" - - -usage="Calculates the version text of one of the following objects. - -usage: - bash $(basename "$0") [-h|--help] -t|--type docker|artifactrepo -n|--name <object_name> - -where: - -h|--help show this help text - -t|--type specify the storage location - -n|--name name of the repository/object - -examples: - $(basename "$0") -t docker -n opnfv/functest - $(basename "$0") -t artifactrepo -n fuel" - - - - -# Parse parameters -while [[ $# > 0 ]] - do - key="$1" - case $key in - -h|--help) - echo "$usage" - exit 0 - shift - ;; - -t|--type) - TYPE="$2" - shift - ;; - -n|--name) - NAME="$2" - shift - ;; - *) - error "unknown option $1" - exit 1 - ;; - esac - shift # past argument or value -done - -if [ -z "$BASE_VERSION" ]; then - error "Base version must be specified as environment variable. Ex.: export BASE_VERSION='brahmaputra.0'" -fi - -if [ "${TYPE}" == "" ]; then - error "Please specify the type of object to get the version from. $usage" -fi - -if [ "${NAME}" == "" ]; then - error "Please specify the name for the given storage type. $usage" -fi - -not_in=1 -for i in "${STORAGE_TYPES[@]}"; do - if [[ "${TYPE}" == "$i" ]]; then - not_in=0 - fi -done -if [ ${not_in} == 1 ]; then - error "Unknown type: ${TYPE}. Available storage types are: [${STORAGE_TYPES[@]}]" -fi - - -#info "Calculating version for object '${TYPE}' with arguments '${INFO}'..." -if [ "${TYPE}" == "docker" ]; then - docker_version $NAME - -elif [ "${TYPE}" == "artifactrepo" ]; then - artifact_version $NAME -fi |