Add Jerma in blacklist logics
[releng.git] / jjb / dovetail / dovetail-artifacts-upload.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 set -o pipefail
11
12 echo "dovetail: pull and save the images"
13
14 [[ -d ${CACHE_DIR} ]] || mkdir -p ${CACHE_DIR}
15
16 cd ${CACHE_DIR}
17 sudo docker pull ${DOCKER_REPO_NAME}:${DOCKER_TAG}
18 sudo docker save -o ${STORE_FILE_NAME} ${DOCKER_REPO_NAME}:${DOCKER_TAG}
19 sudo chmod og+rw ${STORE_FILE_NAME}
20
21 OPNFV_ARTIFACT_VERSION=$(date -u +"%Y-%m-%d_%H-%M-%S")
22 GS_UPLOAD_LOCATION="${STORE_URL}/${OPNFV_ARTIFACT_VERSION}"
23 (
24     echo "OPNFV_ARTIFACT_VERSION=$OPNFV_ARTIFACT_VERSION"
25     echo "OPNFV_GIT_URL=$(git config --get remote.origin.url)"
26     echo "OPNFV_GIT_SHA1=$(git rev-parse HEAD)"
27     echo "OPNFV_ARTIFACT_URL=$GS_UPLOAD_LOCATION"
28     echo "OPNFV_BUILD_URL=$BUILD_URL"
29 ) > $WORKSPACE/opnfv.properties
30 source $WORKSPACE/opnfv.properties
31
32 importkey () {
33 # clone releng repository
34 echo "Cloning releng repository..."
35 [ -d releng ] && rm -rf releng
36 git clone https://gerrit.opnfv.org/gerrit/releng $WORKSPACE/releng/ &> /dev/null
37 #this is where we import the siging key
38 if [ -f $WORKSPACE/releng/utils/gpg_import_key.sh ]; then
39   source $WORKSPACE/releng/utils/gpg_import_key.sh
40 fi
41 }
42
43 sign () {
44 gpg2 -vvv --batch --yes --no-tty \
45   --default-key opnfv-helpdesk@rt.linuxfoundation.org  \
46   --passphrase besteffort \
47   --detach-sig ${CACHE_DIR}/${STORE_FILE_NAME}
48
49 gsutil cp ${CACHE_DIR}/${STORE_FILE_NAME}.sig ${STORE_URL}/${STORE_FILE_NAME}.sig
50 echo "signature Upload Complete!"
51 }
52
53 upload () {
54 # log info to console
55 echo "Uploading ${STORE_FILE_NAME} to artifact. This could take some time..."
56 echo
57
58 cd $WORKSPACE
59 # upload artifact and additional files to google storage
60 gsutil cp ${CACHE_DIR}/${STORE_FILE_NAME} \
61 ${STORE_URL}/${STORE_FILE_NAME} > gsutil.dockerfile.log 2>&1
62 gsutil cp $WORKSPACE/opnfv.properties \
63 ${STORE_URL}/opnfv-$OPNFV_ARTIFACT_VERSION.properties > gsutil.properties.log 2>&1
64 gsutil cp $WORKSPACE/opnfv.properties \
65     ${STORE_URL}/latest.properties > gsutil.latest.log 2>&1
66
67 gsutil -m setmeta \
68     -h "Content-Type:text/html" \
69     -h "Cache-Control:private, max-age=0, no-transform" \
70     ${STORE_URL}/latest.properties \
71     ${STORE_URL}/opnfv-$OPNFV_ARTIFACT_VERSION.properties > /dev/null 2>&1
72
73 gsutil -m setmeta \
74     -h "Cache-Control:private, max-age=0, no-transform" \
75     ${STORE_URL}/${STORE_FILE_NAME} > /dev/null 2>&1
76
77 # disabled errexit due to gsutil setmeta complaints
78 #   BadRequestException: 400 Invalid argument
79 # check if we uploaded the file successfully to see if things are fine
80 gsutil ls ${STORE_URL}/${STORE_FILE_NAME} > /dev/null 2>&1
81 if [[ $? -ne 0 ]]; then
82     echo "Problem while uploading artifact!"
83     exit 1
84 fi
85
86 echo "dovetail: uploading Done!"
87 echo
88 echo "--------------------------------------------------------"
89 echo
90 }
91
92 #importkey
93 #sign
94 upload