Merge "jjb/releng: fix compass-container $DOCKERFILE"
[releng.git] / jjb / daisy4nfv / daisy4nfv-upload-artifact.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2016 ZTE Coreporation and others.
4 # hu.zhijiang@zte.com.cn
5 # sun.jing22@zte.com.cn
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11 set -o pipefail
12
13 # check if we built something
14 if [ -f $WORKSPACE/.noupload ]; then
15     echo "Nothing new to upload. Exiting."
16     /bin/rm -f $WORKSPACE/.noupload
17     exit 0
18 fi
19
20 # source the opnfv.properties to get ARTIFACT_VERSION
21 source $WORKSPACE/opnfv.properties
22
23 importkey () {
24 # clone releng repository
25 echo "Cloning releng repository..."
26 [ -d releng ] && rm -rf releng
27 git clone https://gerrit.opnfv.org/gerrit/releng $WORKSPACE/releng/ &> /dev/null
28 #this is where we import the siging key
29 if [ -f $WORKSPACE/releng/utils/gpg_import_key.sh ]; then
30   source $WORKSPACE/releng/utils/gpg_import_key.sh
31 fi
32 }
33
34 signbin () {
35 gpg2 -vvv --batch --yes --no-tty \
36   --default-key opnfv-helpdesk@rt.linuxfoundation.org  \
37   --passphrase besteffort \
38   --detach-sig $BUILD_DIRECTORY/opnfv-$OPNFV_ARTIFACT_VERSION.bin
39
40 gsutil cp $BUILD_DIRECTORY/opnfv-$OPNFV_ARTIFACT_VERSION.bin.sig gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.bin.sig
41 echo "BIN signature Upload Complete!"
42 }
43
44 uploadbin () {
45 # log info to console
46 echo "Uploading $INSTALLER_TYPE artifact. This could take some time..."
47 echo
48
49 cd $WORKSPACE
50 # upload artifact and additional files to google storage
51 gsutil cp $BUILD_DIRECTORY/opnfv-$OPNFV_ARTIFACT_VERSION.bin \
52     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.bin > gsutil.bin.log 2>&1
53 gsutil cp $BUILD_DIRECTORY/opnfv-$OPNFV_ARTIFACT_VERSION.iso \
54     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso >> gsutil.bin.log 2>&1
55 gsutil cp $WORKSPACE/opnfv.properties \
56     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.properties > gsutil.properties.log 2>&1
57 if [[ ! "$JOB_NAME" =~ (verify|merge) ]]; then
58     gsutil cp $WORKSPACE/opnfv.properties \
59     gs://$GS_URL/latest.properties > gsutil.latest.log 2>&1
60 elif [[ "$JOB_NAME" =~ "merge" ]]; then
61     echo "Uploaded Daisy4nfv artifacts for a merged change"
62 fi
63
64 gsutil -m setmeta \
65     -h "Content-Type:text/html" \
66     -h "Cache-Control:private, max-age=0, no-transform" \
67     gs://$GS_URL/latest.properties \
68     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.properties > /dev/null 2>&1
69
70 gsutil -m setmeta \
71     -h "Cache-Control:private, max-age=0, no-transform" \
72     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.bin > /dev/null 2>&1
73
74 # disabled errexit due to gsutil setmeta complaints
75 #   BadRequestException: 400 Invalid argument
76 # check if we uploaded the file successfully to see if things are fine
77 gsutil ls gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.bin > /dev/null 2>&1
78 if [[ $? -ne 0 ]]; then
79     echo "Problem while uploading artifact!"
80     echo "Check log $WORKSPACE/gsutil.bin.log on the machine where this build is done."
81     exit 1
82 fi
83
84 echo "Done!"
85 echo
86 echo "--------------------------------------------------------"
87 echo
88 echo "Artifact is available as http://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.bin"
89 echo
90 echo "--------------------------------------------------------"
91 echo
92 }
93
94 importkey
95 signbin
96 uploadbin