4 # ============LICENSE_START================================================
6 # =========================================================================
7 # Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
8 # =========================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END==================================================
24 # This creates the x.y.z-container.yaml file for releasing a docker image.
25 # It should be executed from somewhere within the "git" repo to be
26 # released. Assumes the following:
27 # - the latest commit is at the top of the "git log"
28 # - the branch to be released is currently checked out
29 # - the latest maven-docker-stage jenkins job is the one to be released
30 # - the defaultbranch within the .gitreview file is set to the
31 # branch to be released
33 # This uses xmllint, which is part of the libxml2-utils package.
35 # If behind a firewall, then http_proxy must be set so that curl
36 # can get through the firewall.
39 if [ $# -lt 1 -o "$1" = "-?" ]
41 echo "arg(s): docker-container-name1 docker-container-name2 ..." >&2
45 TOPDIR=$(git rev-parse --show-toplevel)
46 if [ -z "${TOPDIR}" ]; then
47 echo "cannot determine top of 'git' repo" >&2
51 BRANCH=$(awk -F= '$1 == "defaultbranch" { print $2 }' "${TOPDIR}/.gitreview")
52 if [ -z "${BRANCH}" ]; then
53 echo "cannot extract default branch from ${TOPDIR}/.gitreview" >&2
56 echo Branch: ${BRANCH}
58 PROJECT=$(awk -F= '$1 == "project" { print $2 }' "${TOPDIR}/.gitreview" |
60 if [ -z "${PROJECT}" ]; then
61 echo "cannot extract project from ${TOPDIR}/.gitreview" >&2
64 echo Project: ${PROJECT}
65 TPROJ=$(echo ${PROJECT} | sed 's!/!%2F!')
66 DPROJ=$(echo ${PROJECT} | sed 's!/!-!')
70 '/*[local-name()="project"]/*[local-name()="version"]/text()' \
74 if [ -z "${RELEASE}" ]; then
75 echo "cannot extract release from ${TOPDIR}/pom.xml" >&2
78 echo Release: ${RELEASE}
80 REF_ID=$(git log | grep commit | head -1 | awk '{ print $2 }')
81 if [ -z "${REF_ID}" ]; then
82 echo "cannot extract ref from 'git log'" >&2
87 prefix='https://jenkins.onap.org/view/policy/job/'
89 curl --silent ${prefix}${DPROJ}-maven-docker-stage-${BRANCH}/ |
90 grep "Last completed build" |
91 sed -e 's!.*Last completed build .#!!' -e 's!).*!!' |
94 if [ -z "${STAGE_ID}" ]; then
95 echo "cannot extract last docker stage ID from jenkins" >&2
98 STAGE_ID=${DPROJ}-maven-docker-stage-${BRANCH}/${STAGE_ID}
99 echo Stage ID: ${STAGE_ID}
101 prefix='https://jenkins.onap.org/view/policy/job/'
102 JOB_OUT=$(curl --silent ${prefix}${STAGE_ID}/console)
103 echo "${JOB_OUT}" | grep -q "Finished: SUCCESS"
104 if [ $? -ne 0 ]; then
105 echo "last docker build has not completed successfully" >&2
109 echo Creating ${TOPDIR}/releases/${RELEASE}-container.yaml
110 cat >"${TOPDIR}/releases/${RELEASE}-container.yaml" <<EOT
111 distribution_type: 'container'
112 container_release_tag: '${RELEASE}'
114 log_dir: '${STAGE_ID}'
119 for CONT_NAME in "$@"
124 /Successfully tagged onap/ { found = 0 }
125 /Successfully tagged onap\/${CONT_NAME}:/ { found = 1 }
126 found == 1 && /Tag with/ { print }
129 sed 's!.*Tag with!!' |
132 if [ -z "${VERSION}" ]; then
133 echo "cannot extract ${CONT_NAME} version from jenkins build output" >&2
136 echo ${CONT_NAME} version: ${VERSION}
138 cat >>"${TOPDIR}/releases/${RELEASE}-container.yaml" <<EOT_LOOP
139 - name: '${CONT_NAME}'
140 version: '${VERSION}'