ca4ba00b018eff2eb7fca46da4dd15e755be4ce8
[releng.git] / jjb / fuel / fuel-upload-artifact.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Ericsson AB 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 # check if we built something
13 if [ -f $WORKSPACE/.noupload ]; then
14     echo "Nothing new to upload. Exiting."
15     /bin/rm -f $WORKSPACE/.noupload
16     exit 0
17 fi
18
19 # source the opnfv.properties to get ARTIFACT_VERSION
20 source $WORKSPACE/opnfv.properties
21
22 nfsstore () {
23 # storing ISOs for verify & merge jobs will be done once we get the disk array
24 if [[ ! "$JOB_NAME" =~ (verify|merge) ]]; then
25     # store ISO locally on NFS first
26     ISOSTORE="/iso_mount/opnfv_ci/${GIT_BRANCH##*/}"
27     if [[ -d "$ISOSTORE" ]]; then
28         # remove all but most recent 5 ISOs first to keep iso_mount clean & tidy
29         cd $ISOSTORE
30         ls -tp | grep -v '/' | tail -n +6 | xargs -d '\n' /bin/rm -f --
31
32         # store ISO
33         echo "Storing $INSTALLER_TYPE artifact on NFS..."
34         /bin/cp -f $BUILD_DIRECTORY/opnfv-$OPNFV_ARTIFACT_VERSION.iso \
35             $ISOSTORE/opnfv-$OPNFV_ARTIFACT_VERSION.iso
36     fi
37 fi
38 }
39
40 importkey () {
41 # clone releng repository
42 echo "Cloning releng repository..."
43 [ -d releng ] && rm -rf releng
44 git clone https://gerrit.opnfv.org/gerrit/releng $WORKSPACE/releng/ &> /dev/null
45 #this is where we import the siging key
46 if [ -f $WORKSPACE/releng/utils/gpg_import_key.sh ]; then
47   source $WORKSPACE/releng/utils/gpg_import_key.sh
48 fi
49 }
50
51 signiso () {
52 gpg2 -vvv --batch --yes --no-tty \
53   --default-key opnfv-helpdesk@rt.linuxfoundation.org  \
54   --passphrase besteffort \
55   --detach-sig $BUILD_DIRECTORY/opnfv-$OPNFV_ARTIFACT_VERSION.iso
56
57 gsutil cp $BUILD_DIRECTORY/opnfv-$OPNFV_ARTIFACT_VERSION.iso.sig gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso.sig
58 echo "ISO signature Upload Complete!"
59 }
60
61 uploadiso () {
62 # log info to console
63 echo "Uploading $INSTALLER_TYPE artifact. This could take some time..."
64 echo
65
66 cd $WORKSPACE
67 # upload artifact and additional files to google storage
68 gsutil cp $BUILD_DIRECTORY/opnfv-$OPNFV_ARTIFACT_VERSION.iso \
69     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso > gsutil.iso.log 2>&1
70 gsutil cp $WORKSPACE/opnfv.properties \
71     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.properties > gsutil.properties.log 2>&1
72 if [[ ! "$JOB_NAME" =~ (verify|merge) ]]; then
73     gsutil cp $WORKSPACE/opnfv.properties \
74     gs://$GS_URL/latest.properties > gsutil.latest.log 2>&1
75 elif [[ "$JOB_NAME" =~ "merge" ]]; then
76     echo "Uploaded Fuel ISO for a merged change"
77 fi
78
79 gsutil -m setmeta \
80     -h "Content-Type:text/html" \
81     -h "Cache-Control:private, max-age=0, no-transform" \
82     gs://$GS_URL/latest.properties \
83     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.properties > /dev/null 2>&1
84
85 gsutil -m setmeta \
86     -h "Cache-Control:private, max-age=0, no-transform" \
87     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso > /dev/null 2>&1
88
89 # disabled errexit due to gsutil setmeta complaints
90 #   BadRequestException: 400 Invalid argument
91 # check if we uploaded the file successfully to see if things are fine
92 gsutil ls gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso > /dev/null 2>&1
93 if [[ $? -ne 0 ]]; then
94     echo "Problem while uploading artifact!"
95     echo "Check log $WORKSPACE/gsutil.iso.log on the machine where this build is done."
96     exit 1
97 fi
98
99 echo "Done!"
100 echo
101 echo "--------------------------------------------------------"
102 echo
103 echo "Artifact is available as http://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso"
104 echo
105 echo "--------------------------------------------------------"
106 echo
107 }
108
109 nfsstore
110
111 if [[ "$JOB_NAME" =~ merge ]]; then
112     uploadiso
113 elif [[ "$JOB_NAME" =~ build ]]; then
114     importkey
115     signiso
116     uploadiso
117 fi
118