02197cfa90bd659abaf51a5c3cd821283b95b671
[infra/cicd.git] / jjb / cloud-infra / scripts / oom-upload.sh
1 #!/bin/bash
2
3 # ============LICENSE_START=======================================================
4 #  Copyright (C) 2021 The Nordix Foundation. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # SPDX-License-Identifier: Apache-2.0
19 # ============LICENSE_END=========================================================
20
21 set -o errexit
22 set -o pipefail
23
24 ONAP_OOM_GIT_REVISION=$(cd "${WORKSPACE}/build/onap-oom" && git rev-parse --short HEAD)
25 ONAP_UMBRELLA_CHART=$(find ${WORKSPACE}/build/onap-oom/kubernetes/dist/packages -name onap-*${ONAP_OOM_GIT_REVISION}.tgz)
26 IMAGES_LIST=$(find ${WORKSPACE} -maxdepth 1 -name onap-*${ONAP_OOM_GIT_REVISION}_images.txt)
27
28 export NORDIX_ARM_REPO="onap"
29 export ARTIFACT_ARM_FOLDER="oom"
30 export BUILD_IDENTIFIER="${ONAP_OOM_GIT_REVISION}"
31 export NORDIX_ARTIFACT_URL="${NORDIX_ARM_HTTPS_URL}/${NORDIX_ARM_REPO}/${ARTIFACT_ARM_FOLDER}/${BUILD_IDENTIFIER}"
32
33 echo "Info  : Pushing ONAP umbrella chart to Nordix Harbor"
34 HELM_BIN="${WORKSPACE}/bin/helm"
35 ${HELM_BIN} repo remove onaptest || true
36 ${HELM_BIN} repo add onaptest "${NORDIX_REGISTRY}/chartrepo/onaptest"
37 ${HELM_BIN} push -f "${ONAP_UMBRELLA_CHART}" --username "${HARBOR_USERNAME}" --password "${HARBOR_PASSWORD}" onaptest
38
39 export BUILD_ARTIFACTS="${ONAP_UMBRELLA_CHART} ${IMAGES_LIST}"
40 echo "Info  : Uploading ${BUILD_ARTIFACTS} to Nordix ARM ${NORDIX_ARM_REPO} repository"
41 for BUILD_ARTIFACT in $BUILD_ARTIFACTS; do
42   echo "Info  : Generating checksums for $BUILD_ARTIFACT"
43   ARTIFACT_MD5SUM=$(md5sum "${BUILD_ARTIFACT}" | cut -d' ' -f1)
44   ARTIFACT_SHASUM=$(shasum "${BUILD_ARTIFACT}" | cut -d' ' -f1)
45   ARTIFACT_SHA256SUM=$(sha256sum "${BUILD_ARTIFACT}" | cut -d' ' -f1)
46
47   REMOTE_ARTIFACT=$(basename "${BUILD_ARTIFACT}")
48   # NOTE(cian): URL-encoding remote artifact as filename may contain special characters
49   REMOTE_ARTIFACT=$(echo -n "${REMOTE_ARTIFACT}" | python3 -c 'from sys import stdout, stdin; from urllib.parse import quote; stdout.write(quote(stdin.read()))')
50
51   echo "Info  : Uploading ${BUILD_ARTIFACT} to Nordix Artifactory"
52   curl -s -S \
53       -H "X-JFrog-Art-Api:${NORDIX_ARM_TOKEN}" \
54       -H "X-Checksum-MD5:${ARTIFACT_MD5SUM}" \
55       -H "X-Checksum-Sha1:${ARTIFACT_SHASUM}" \
56       -H "X-Checksum-Sha256:${ARTIFACT_SHA256SUM}" \
57       -T "${BUILD_ARTIFACT}" \
58       "${NORDIX_ARTIFACT_URL}/${REMOTE_ARTIFACT}"
59   echo "Info  : Artifact ${BUILD_ARTIFACT} is available on ${NORDIX_ARTIFACT_URL}/${REMOTE_ARTIFACT}"
60 done
61
62 echo "Done!"
63
64 # vim: set ts=2 sw=2 expandtab: