Merge "[deployment_handler] Fix some nits and improve output"
[releng.git] / jjb / apex / apex-upload-artifact.sh
1 #!/bin/bash
2 set -o errexit
3 set -o nounset
4 set -o pipefail
5
6 # log info to console
7 echo "Uploading the Apex artifact. This could take some time..."
8 echo "--------------------------------------------------------"
9 echo
10
11 # source the opnfv.properties to get ARTIFACT_VERSION
12 source $WORKSPACE/opnfv.properties
13
14 BUILD_DIRECTORY=${WORKSPACE}/.build
15
16 # clone releng repository
17 echo "Cloning releng repository..."
18 [ -d releng ] && rm -rf releng
19 git clone https://gerrit.opnfv.org/gerrit/releng $WORKSPACE/releng/ &> /dev/null
20 #this is where we import the siging key
21 if [ -f $WORKSPACE/releng/utils/gpg_import_key.sh ]; then 
22   source $WORKSPACE/releng/utils/gpg_import_key.sh
23 fi
24
25 signrpm () {
26 for artifact in $RPM_LIST $SRPM_LIST; do
27   echo "Signing artifact: ${artifact}"
28   gpg2 -vvv --batch --yes --no-tty \
29     --default-key opnfv-helpdesk@rt.linuxfoundation.org \
30     --passphrase besteffort \
31     --detach-sig $artifact
32     gsutil cp "$artifact".sig gs://$GS_URL/$(basename "$artifact".sig)
33     echo "Upload complete for ${artifact} signature"
34 done
35 }
36
37 signiso () {
38 time gpg2 -vvv --batch --yes --no-tty \
39   --default-key opnfv-helpdesk@rt.linuxfoundation.org  \
40   --passphrase besteffort \
41   --detach-sig $BUILD_DIRECTORY/release/OPNFV-CentOS-7-x86_64-$OPNFV_ARTIFACT_VERSION.iso
42
43 gsutil cp $BUILD_DIRECTORY/release/OPNFV-CentOS-7-x86_64-$OPNFV_ARTIFACT_VERSION.iso.sig gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso.sig 
44 echo "ISO signature Upload Complete!"
45 }
46
47 uploadiso () {
48 # upload artifact and additional files to google storage
49 gsutil cp $BUILD_DIRECTORY/release/OPNFV-CentOS-7-x86_64-$OPNFV_ARTIFACT_VERSION.iso gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso > gsutil.iso.log
50 echo "ISO Upload Complete!"
51 RPM_INSTALL_PATH=$BUILD_DIRECTORY/noarch
52 RPM_LIST=$RPM_INSTALL_PATH/$(basename $OPNFV_RPM_URL)
53 VERSION_EXTENSION=$(echo $(basename $OPNFV_RPM_URL) | sed 's/opnfv-apex-//')
54 for pkg in common undercloud onos; do
55     RPM_LIST+=" ${RPM_INSTALL_PATH}/opnfv-apex-${pkg}-${VERSION_EXTENSION}"
56 done
57 SRPM_INSTALL_PATH=$BUILD_DIRECTORY
58 SRPM_LIST=$SRPM_INSTALL_PATH/$(basename $OPNFV_SRPM_URL)
59 VERSION_EXTENSION=$(echo $(basename $OPNFV_SRPM_URL) | sed 's/opnfv-apex-//')
60 for pkg in common undercloud onos; do
61     SRPM_LIST+=" ${SRPM_INSTALL_PATH}/opnfv-apex-${pkg}-${VERSION_EXTENSION}"
62 done
63 }
64
65 uploadrpm () {
66 #This is where we upload the rpms
67 for artifact in $RPM_LIST $SRPM_LIST; do
68   echo "Uploading artifact: ${artifact}"
69   gsutil cp $artifact gs://$GS_URL/$(basename $artifact) > gsutil.iso.log
70   echo "Upload complete for ${artifact}"
71 done
72 gsutil cp $WORKSPACE/opnfv.properties gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.properties > gsutil.properties.log
73 gsutil cp $WORKSPACE/opnfv.properties gs://$GS_URL/latest.properties > gsutil.latest.log
74 }
75
76 uploadsnap () {
77   # Uploads snapshot artifact and updated properties file
78   echo "Uploading snapshot artifacts"
79   gsutil cp $WORKSPACE/apex-csit-snap-`date +%Y-%m-%d`.tar.gz gs://$GS_URL/ > gsutil.iso.log
80   gsutil cp $WORKSPACE/snapshot.properties gs://$GS_URL/snapshot.properties > gsutil.latest.log
81   echo "Upload complete for Snapshot"
82 }
83
84 if echo $WORKSPACE | grep csit > /dev/null; then
85   uploadsnap
86 elif gpg2 --list-keys | grep "opnfv-helpdesk@rt.linuxfoundation.org"; then
87   echo "Signing Key avaliable"
88   signiso
89   uploadiso
90   signrpm
91   uploadrpm
92 else
93   uploadiso
94   uploadrpm
95 fi
96
97 echo
98 echo "--------------------------------------------------------"
99 echo "Done!"
100 echo "ISO Artifact is available as http://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso"
101 echo "RPM Artifact is available as http://$GS_URL/$(basename $OPNFV_RPM_URL)"