From 31834188b590c962b843cd056b0d898c0b05d5b6 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Tue, 18 Jun 2019 16:14:18 +0200 Subject: [PATCH] Deploy docker image of nightly build automatically --- Jenkinsfile | 2 +- Util/BuildTools/Deploy.sh | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f6850464c..87cc03447 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -80,7 +80,7 @@ pipeline { stage('Deploy') { when { anyOf { branch "master"; buildingTag() } } steps { - sh 'make deploy ARGS="--replace-latest"' + sh 'make deploy ARGS="--replace-latest --docker-push"' } } } diff --git a/Util/BuildTools/Deploy.sh b/Util/BuildTools/Deploy.sh index 25f5a1c9b..de9f1bbed 100755 --- a/Util/BuildTools/Deploy.sh +++ b/Util/BuildTools/Deploy.sh @@ -7,6 +7,7 @@ source $(dirname "$0")/Environment.sh REPLACE_LATEST=false +DOCKER_PUSH=false AWS_COPY="aws s3 cp" UPLOAD_MAPS=true @@ -16,9 +17,9 @@ UPLOAD_MAPS=true DOC_STRING="Upload latest build to S3." -USAGE_STRING="Usage: $0 [-h|--help] [--replace-latest] [--dry-run]" +USAGE_STRING="Usage: $0 [-h|--help] [--replace-latest] [--docker-push] [--dry-run]" -OPTS=`getopt -o h --long help,replace-latest,dry-run -n 'parse-options' -- "$@"` +OPTS=`getopt -o h --long help,replace-latest,docker-push,dry-run -n 'parse-options' -- "$@"` if [ $? != 0 ] ; then echo "$USAGE_STRING" ; exit 2 ; fi @@ -29,6 +30,9 @@ while true; do --replace-latest ) REPLACE_LATEST=true; shift ;; + --docker-push ) + DOCKER_PUSH=true; + shift ;; --dry-run ) AWS_COPY="echo ${AWS_COPY}"; shift ;; @@ -54,9 +58,11 @@ LATEST_DEPLOY_URI=${S3_PREFIX}/Dev/CARLA_Latest.tar.gz if [[ ${REPOSITORY_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then log "Detected tag ${REPOSITORY_TAG}." DEPLOY_NAME=CARLA_${REPOSITORY_TAG}.tar.gz + DOCKER_TAG=${REPOSITORY_TAG} else S3_PREFIX=${S3_PREFIX}/Dev DEPLOY_NAME=$(git log --pretty=format:'%cd_%h' --date=format:'%Y%m%d' -n 1).tar.gz + DOCKER_TAG=latest fi log "Using package ${LATEST_PACKAGE} as ${DEPLOY_NAME}." @@ -103,6 +109,33 @@ if ${UPLOAD_MAPS} ; then fi +# ============================================================================== +# -- Docker build and push ----------------------------------------------------- +# ============================================================================== + +if ${DOCKER_PUSH} ; then + + DOCKER_BUILD_FOLDER=${CARLA_BUILD_FOLDER}/${REPOSITORY_TAG}.Docker + DOCKER_NAME=carlasim/carla:${DOCKER_TAG} + + mkdir -p ${DOCKER_BUILD_FOLDER} + + tar -xvzf ${LATEST_PACKAGE_PATH} -C ${DOCKER_BUILD_FOLDER}/ + + pushd "${DOCKER_BUILD_FOLDER}" >/dev/null + + log "Building Docker image ${DOCKER_NAME}." + + docker build -t ${DOCKER_NAME} -f Dockerfile . + + log "Pushing Docker image." + + docker push carlasim/carla + + popd >/dev/null + +fi; + # ============================================================================== # -- ...and we are done -------------------------------------------------------- # ==============================================================================