diff options
Diffstat (limited to 'mvn-phase-lib.sh')
-rwxr-xr-x | mvn-phase-lib.sh | 139 |
1 files changed, 121 insertions, 18 deletions
diff --git a/mvn-phase-lib.sh b/mvn-phase-lib.sh index 9de7cced..66d5bbc0 100755 --- a/mvn-phase-lib.sh +++ b/mvn-phase-lib.sh @@ -19,6 +19,58 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. +FQDN="${MVN_PROJECT_GROUPID}.${MVN_PROJECT_ARTIFACTID}" +if [ "$MVN_PROJECT_MODULEID" == "__" ]; then + MVN_PROJECT_MODULEID="" +fi + +if [[ "$MVN_PROJECT_VERSION" == *SNAPSHOT ]]; then + echo "=> for SNAPSHOT artifact build" + MVN_DEPLOYMENT_TYPE='SNAPSHOT' + MVN_DOCKERREGISTRY="$MVN_DOCKERREGISTRY_SNAPSHOT" + MVN_DOCKERREGISTRY_SERVERID="$MVN_DOCKERREGISTRY_SNAPSHOT_SERVERID" +else + echo "=> for STAGING/RELEASE artifact build" + MVN_DEPLOYMENT_TYPE='STAGING' + # below is not mistake. we only use the snapshot registry + MVN_DOCKERREGISTRY="$MVN_DOCKERREGISTRY_SNAPSHOT" + MVN_DOCKERREGISTRY_SERVERID="$MVN_DOCKERREGISTRY_SNAPSHOT_SERVERID" +fi +echo "MVN_DEPLOYMENT_TYPE is [$MVN_DEPLOYMENT_TYPE]" + + +TIMESTAMP=$(date +%C%y%m%dT%H%M%S) + +# WROKSPACE points to the current dir when the script is called, may be the root or module +if [ -z "$WORKSPACE" ]; then + WORKSPACE=$(pwd) +fi + + +TIMESTAMP=$(date +%C%y%m%dT%H%M%S) + + + +echo "MVN_PROJECT_MODULEID is [$MVN_PROJECT_MODULEID]" +echo "MVN_PHASE is [$MVN_PHASE]" +echo "MVN_PROJECT_GROUPID is [$MVN_PROJECT_GROUPID]" +echo "MVN_PROJECT_ARTIFACTID is [$MVN_PROJECT_ARTIFACTID]" +echo "MVN_PROJECT_VERSION is [$MVN_PROJECT_VERSION]" +echo "MVN_NEXUSPROXY is [$MVN_NEXUSPROXY]" +echo "MVN_RAWREPO_BASEURL_UPLOAD is [$MVN_RAWREPO_BASEURL_UPLOAD]" +echo "MVN_RAWREPO_BASEURL_DOWNLOAD is [$MVN_RAWREPO_BASEURL_DOWNLOAD]" +MVN_RAWREPO_HOST=$(echo "$MVN_RAWREPO_BASEURL_UPLOAD" | cut -f3 -d'/' |cut -f1 -d':') +echo "MVN_RAWREPO_HOST is [$MVN_RAWREPO_HOST]" +echo "MVN_RAWREPO_SERVERID is [$MVN_RAWREPO_SERVERID]" +echo "MVN_DOCKERREGISTRY is [$MVN_DOCKERREGISTRY]" +echo "MVN_DOCKERREGISTRY_SERVERID is [$MVN_DOCKERREGISTRY_SERVERID]" +echo "MVN_PYPISERVER_BASEURL is [$MVN_PYPISERVER_BASEURL]" +echo "MVN_PYPISERVER_SERVERID is [$MVN_PYPISERVER_SERVERID]" +echo "FQDN is [$FQDN]" +echo "MVN_PROJECT_MODULEID is [$MVN_PROJECT_MODULEID]" +echo "MVN_DEPLOYMENT_TYPE is [$MVN_DEPLOYMENT_TYPE]" + + clean_templated_files() { TEMPLATE_FILES=$(find . -name "*-template") @@ -226,40 +278,36 @@ upload_files_of_extension() } +upload_files_of_extension_rec() +{ + FILES=$(find . -name "*.${1}") + for F in $FILES ; do + upload_raw_file "$F" + done +} + + build_and_push_docker() { IMAGENAME="onap/${FQDN}.${MVN_PROJECT_MODULEID}" IMAGENAME=$(echo "$IMAGENAME" | sed -e 's/_*$//g' -e 's/\.*$//g') + IMAGENAME=$(echo "$IMAGENAME" | tr '[:upper:]' '[:lower:]') # use the major and minor version of the MVN artifact version as docker image version VERSION="${MVN_PROJECT_VERSION//[^0-9.]/}" VERSION2=$(echo "$VERSION" | cut -f1-2 -d'.') LFQI="${IMAGENAME}:${VERSION}-${TIMESTAMP}" - #BUILD_PATH="${WORKSPACE}" - # build a docker image - #docker build --rm -f "${WORKSPACE}"/Dockerfile -t "${LFQI}" "${BUILD_PATH}" - #BUILD_PATH="${WORKSPACE}" # build a docker image docker build --rm -f ./Dockerfile -t "${LFQI}" ./ - REPO="" - if [ $MVN_DEPLOYMENT_TYPE == "SNAPSHOT" ]; then - REPO=$MVN_DOCKERREGISTRY_DAILY - elif [ $MVN_DEPLOYMENT_TYPE == "STAGING" ]; then - # there seems to be no staging docker registry? set to use SNAPSHOT also - #REPO=$MVN_DOCKERREGISTRY_RELEASE - REPO=$MVN_DOCKERREGISTRY_DAILY - else - echo "Fail to determine DEPLOYMENT_TYPE" - REPO=$MVN_DOCKERREGISTRY_DAILY - fi - echo "DEPLOYMENT_TYPE is: $MVN_DEPLOYMENT_TYPE, repo is $REPO" + REPO="$MVN_DOCKERREGISTRY" + SERVERID="$MVN_DOCKERREGISTRY_SERVERID" if [ ! -z "$REPO" ]; then - USER=$(xpath -e "//servers/server[id='$REPO']/username/text()" "$SETTINGS_FILE") - PASS=$(xpath -e "//servers/server[id='$REPO']/password/text()" "$SETTINGS_FILE") + USER=$(xpath -e "//servers/server[id='$SERVERID']/username/text()" "$SETTINGS_FILE") + PASS=$(xpath -e "//servers/server[id='$SERVERID']/password/text()" "$SETTINGS_FILE") if [ -z "$USER" ]; then echo "Error: no user provided" fi @@ -297,3 +345,58 @@ build_and_push_docker() +push_docker_image() +{ + if [ -z "$1" ]; then + return + fi + OLDTAGNAME="$1" + OLDREPO=$(echo $TAGNAME | cut -f1 -d '/') + IMAGENAME_W_VERSION=$(echo $TAGNAME | cut -f2- -d '/') + + # build a docker image + docker pull "$OLDTAGNAME" + + REPO="$MVN_DOCKERREGISTRY" + SERVERID="$MVN_DOCKERREGISTRY_SERVERID" + + if [ ! -z "$REPO" ]; then + USER=$(xpath -e "//servers/server[id='$SERVERID']/username/text()" "$SETTINGS_FILE") + PASS=$(xpath -e "//servers/server[id='$SERVERID']/password/text()" "$SETTINGS_FILE") + if [ -z "$USER" ]; then + echo "Error: no user provided" + fi + if [ -z "$PASS" ]; then + echo "Error: no password provided" + fi + [ -z "$PASS" ] && PASS_PROVIDED="<empty>" || PASS_PROVIDED="<password>" + echo docker login "$REPO" -u "$USER" -p "$PASS_PROVIDED" + docker login "$REPO" -u "$USER" -p "$PASS" + + if [ $MVN_DEPLOYMENT_TYPE == "SNAPSHOT" ]; then + REPO="$REPO/snapshots" + elif [ $MVN_DEPLOYMENT_TYPE == "STAGING" ]; then + # there seems to be no staging docker registry? set to use SNAPSHOT also + #REPO=$MVN_DOCKERREGISTRY_RELEASE + REPO="$REPO" + else + echo "Fail to determine DEPLOYMENT_TYPE" + REPO="$REPO/unknown" + fi + + OLDTAG="${OLDTAGNAME}" + PUSHTAGS="${REPO}/${IMAGENAME_W_VERSION}-${TIMESTAMP} ${REPO}/${IMAGENAME_W_VERSION} ${REPO}/${IMAGENAME_W_VERSION}-latest" + for NEWTAG in ${PUSHTAGS} + do + echo "tagging ${OLDTAG} to ${NEWTAG}" + docker tag "${OLDTAG}" "${NEWTAG}" + echo "pushing ${NEWTAG}" + docker push "${NEWTAG}" + OLDTAG="${NEWTAG}" + done + fi + +} + + + |