From 5b6ecf143a3259131876251fecb2ae2a4ceec01a Mon Sep 17 00:00:00 2001 From: Thugutla sailakshmi Date: Tue, 10 Sep 2019 16:52:32 +0530 Subject: docker script file for VALET-API module docker script file for VALET-API module Issue-ID: OPTFRA-578 Change-Id: I824ab0cdc495105651a4145d95e131219e9a595f Signed-off-by: Thugutla sailakshmi --- engine/version.properties | 28 ++++++++++++++ valetapi/build-dockers.sh | 94 +++++++++++++++++++++++++++++++++++++++++++++ valetapi/version.properties | 28 ++++++++++++++ version.properties | 29 -------------- 4 files changed, 150 insertions(+), 29 deletions(-) create mode 100644 engine/version.properties create mode 100644 valetapi/build-dockers.sh create mode 100644 valetapi/version.properties delete mode 100644 version.properties diff --git a/engine/version.properties b/engine/version.properties new file mode 100644 index 0000000..b847a8d --- /dev/null +++ b/engine/version.properties @@ -0,0 +1,28 @@ +# +# ------------------------------------------------------------------------- +# Copyright (c) 2015-2017 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# + +major=1 +minor=3 +patch=1 + +base_version=${major}.${minor}.${patch} + +# Release must be completed with git revision # in Jenkins +release_version=${base_version} +snapshot_version=${base_version}-SNAPSHOT diff --git a/valetapi/build-dockers.sh b/valetapi/build-dockers.sh new file mode 100644 index 0000000..516f860 --- /dev/null +++ b/valetapi/build-dockers.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +# The script starts in the root folder of the repo, which has the following outline +# We fetch the version information from version.properties, build docker files and +# do a docker push. Since the job will be run under Jenkins, it will have the Nexus +# credentials + +set -e + +BUILD_ARGS="--no-cache" +ORG="onap" +PROJECT="fgps-api" +DOCKER_REPOSITORY="nexus.onap.org:5100" +IMAGE_NAME="${DOCKER_REPOSITORY}/${ORG}/${PROJECT}" + +# Version properties +source version.properties +VERSION=$release_version +SNAPSHOT=$snapshot_version +STAGING=${release_version}-STAGING +TIMESTAMP=$(date +"%Y%m%dT%H%M%S")Z +REPO="" + +if [ $HTTP_PROXY ]; then + BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}" +fi +if [ $HTTPS_PROXY ]; then + BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}" +fi + +function log_ts() { # Log message with timestamp + echo [DEBUG LOG at $(date -u +%Y%m%d:%H%M%S)] "$@" +} + +function get_artifact_version() { + log_ts Get Maven Artifact version from pom.xml + MVN_ARTIFACT_VERSION=`echo -e "setns x=http://maven.apache.org/POM/4.0.0 \n xpath /x:project/x:version/text() "| xmllint --shell conductor/pom.xml | grep content | sed 's/.*content=//'` + log_ts Maven artifact version for fgps-api is $MVN_ARTIFACT_VERSION + if [[ "$MVN_ARTIFACT_VERSION" =~ SNAPSHOT ]]; then + log_ts "REPO is snapshots"; + REPO=snapshots + else + log_ts "REPO is releases"; + REPO=releases + fi + BUILD_ARGS+=" --build-arg REPO=${REPO}" + BUILD_ARGS+=" --build-arg MVN_ARTIFACT_VERSION=${MVN_ARTIFACT_VERSION}" +} + +function build_image() { + log_ts Building Image in folder: $PWD with build arguments ${BUILD_ARGS} + mvn clean install + cp target/ValetApi.jar src/main/docker + docker build ${BUILD_ARGS} -t ${IMAGE_NAME}:latest src/main/docker + log_ts ... Built +} + +function push_image() { + if [[ "$REPO" == snapshots ]]; then + push_snapshot_image + else + push_staging_image + fi +} + +function push_snapshot_image(){ + log_ts Tagging images: ${IMAGE_NAME}:\{${SNAPSHOT}-${TIMESTAMP},${SNAPSHOT}-latest\} + docker tag ${IMAGE_NAME}:latest ${IMAGE_NAME}:${SNAPSHOT}-${TIMESTAMP} + docker tag ${IMAGE_NAME}:latest ${IMAGE_NAME}:${SNAPSHOT}-latest + log_ts ... Tagged images + + log_ts Pushing images: ${IMAGE_NAME}:\{${SNAPSHOT}-${TIMESTAMP},${SNAPSHOT}-latest\} + docker push ${IMAGE_NAME}:${SNAPSHOT}-${TIMESTAMP} + docker push ${IMAGE_NAME}:${SNAPSHOT}-latest + log_ts ... Pushed images +} + +function push_staging_image(){ + log_ts Tagging images: ${IMAGE_NAME}:\{${STAGING}-${TIMESTAMP},${STAGING}-latest\} + docker tag ${IMAGE_NAME}:latest ${IMAGE_NAME}:${STAGING}-${TIMESTAMP} + docker tag ${IMAGE_NAME}:latest ${IMAGE_NAME}:${STAGING}-latest + log_ts ... Tagged images + + log_ts Pushing images: ${IMAGE_NAME}:\{${STAGING}-${TIMESTAMP},${STAGING}-latest\} + docker push ${IMAGE_NAME}:${STAGING}-${TIMESTAMP} + docker push ${IMAGE_NAME}:${STAGING}-latest + log_ts ... Pushed images +} + +( + get_artifact_version + build_image + push_image +) diff --git a/valetapi/version.properties b/valetapi/version.properties new file mode 100644 index 0000000..b847a8d --- /dev/null +++ b/valetapi/version.properties @@ -0,0 +1,28 @@ +# +# ------------------------------------------------------------------------- +# Copyright (c) 2015-2017 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# + +major=1 +minor=3 +patch=1 + +base_version=${major}.${minor}.${patch} + +# Release must be completed with git revision # in Jenkins +release_version=${base_version} +snapshot_version=${base_version}-SNAPSHOT diff --git a/version.properties b/version.properties deleted file mode 100644 index be52259..0000000 --- a/version.properties +++ /dev/null @@ -1,29 +0,0 @@ -# -# ------------------------------------------------------------------------- -# Copyright (c) 2019 AT&T Intellectual Property -# Modifications Copyright (C) 2019 IBM -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# ------------------------------------------------------------------------- -# - -major=1.0.0 -minor=1.0.0 -patch=1.0.0 - -base_version=${major}.${minor}.${patch} - -# Release must be completed with git revision # in Jenkins -release_version=${base_version} -snapshot_version=${base_version}-SNAPSHOT -- cgit 1.2.3-korg