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