dovetail: bugfix for gsutil upload
[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
20 OPNFV_ARTIFACT_VERSION=$(date -u +"%Y-%m-%d_%H-%M-%S")
21 GS_UPLOAD_LOCATION="gs://$GS_URL/$OPNFV_ARTIFACT_VERSION"
22 (
23     echo "OPNFV_ARTIFACT_VERSION=$OPNFV_ARTIFACT_VERSION"
24     echo "OPNFV_GIT_URL=$(git config --get remote.origin.url)"
25     echo "OPNFV_GIT_SHA1=$(git rev-parse HEAD)"
26     echo "OPNFV_ARTIFACT_URL=$GS_UPLOAD_LOCATION"
27     echo "OPNFV_BUILD_URL=$BUILD_URL"
28 ) > $WORKSPACE/opnfv.properties
29 source $WORKSPACE/opnfv.properties
30
31 importkey () {
32 # clone releng repository
33 echo "Cloning releng repository..."
34 [ -d releng ] && rm -rf releng
35 git clone https://gerrit.opnfv.org/gerrit/releng $WORKSPACE/releng/ &> /dev/null
36 #this is where we import the siging key
37 if [ -f $WORKSPACE/releng/utils/gpg_import_key.sh ]; then
38   source $WORKSPACE/releng/utils/gpg_import_key.sh
39 fi
40 }
41
42 sign () {
43 gpg2 -vvv --batch --yes --no-tty \
44   --default-key opnfv-helpdesk@rt.linuxfoundation.org  \
45   --passphrase besteffort \
46   --detach-sig ${CACHE_DIR}/${STORE_FILE_NAME}
47
48 gsutil cp ${CACHE_DIR}/${STORE_FILE_NAME}.sig ${STORE_URL}/${STORE_FILE_NAME}.sig
49 echo "signature Upload Complete!"
50 }
51
52 upload () {
53 # log info to console
54 echo "Uploading to artifact. This could take some time..."
55 echo
56
57 cd $WORKSPACE
58 # upload artifact and additional files to google storage
59 gsutil cp ${CACHE_DIR}/${STORE_FILE_NAME} \
60 ${STORE_URL}/${STORE_FILE_NAME} > gsutil.file.log 2>&1
61 gsutil cp $WORKSPACE/opnfv.properties \
62 ${STORE_URL}/opnfv-$OPNFV_ARTIFACT_VERSION.properties > gsutil.properties.log 2>&1
63 gsutil cp $WORKSPACE/opnfv.properties \
64     ${STORE_URL}/latest.properties > gsutil.latest.log 2>&1
65
66 gsutil -m setmeta \
67     -h "Content-Type:text/html" \
68     -h "Cache-Control:private, max-age=0, no-transform" \
69     ${STORE_URL}/latest.properties \
70     ${STORE_URL}/opnfv-$OPNFV_ARTIFACT_VERSION.properties > /dev/null 2>&1
71
72 gsutil -m setmeta \
73     -h "Cache-Control:private, max-age=0, no-transform" \
74     ${STORE_URL}/${STORE_FILE_NAME} > /dev/null 2>&1
75
76 # disabled errexit due to gsutil setmeta complaints
77 #   BadRequestException: 400 Invalid argument
78 # check if we uploaded the file successfully to see if things are fine
79 gsutil ls ${STORE_URL}/${STORE_FILE_NAME} > /dev/null 2>&1
80 if [[ $? -ne 0 ]]; then
81     echo "Problem while uploading artifact!"
82     exit 1
83 fi
84
85 echo "dovetail: uploading Done!"
86 echo
87 echo "--------------------------------------------------------"
88 echo
89 }
90
91 importkey
92 sign
93 upload