Apex: fix apex upload for images
[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 BUILD_DIRECTORY=$WORKSPACE/../$BUILD_DIRECTORY
17
18 if [[ ! "$ARTIFACT_VERSION" =~ dev ]]; then
19   source $BUILD_DIRECTORY/../opnfv.properties
20 fi
21
22 importkey () {
23   # clone releng repository
24   echo "Cloning releng repository..."
25   [ -d releng ] && rm -rf releng
26   git clone https://gerrit.opnfv.org/gerrit/releng $WORKSPACE/releng/ &> /dev/null
27   #this is where we import the siging key
28   if [ -f $WORKSPACE/releng/utils/gpg_import_key.sh ]; then
29     source $WORKSPACE/releng/utils/gpg_import_key.sh
30   fi
31 }
32
33 signrpm () {
34   for artifact in $RPM_LIST $SRPM_LIST; do
35     echo "Signing artifact: ${artifact}"
36     gpg2 -vvv --batch --yes --no-tty \
37       --default-key opnfv-helpdesk@rt.linuxfoundation.org \
38       --passphrase besteffort \
39       --detach-sig $artifact
40       gsutil cp "$artifact".sig gs://$GS_URL/$(basename "$artifact".sig)
41       echo "Upload complete for ${artifact} signature"
42   done
43 }
44
45 signiso () {
46   gpg2 -vvv --batch --yes --no-tty \
47     --default-key opnfv-helpdesk@rt.linuxfoundation.org  \
48     --passphrase besteffort \
49     --detach-sig $BUILD_DIRECTORY/release/OPNFV-CentOS-7-x86_64-$OPNFV_ARTIFACT_VERSION.iso
50
51   gsutil cp $BUILD_DIRECTORY/release/OPNFV-CentOS-7-x86_64-$OPNFV_ARTIFACT_VERSION.iso.sig gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso.sig
52   echo "ISO signature Upload Complete!"
53 }
54
55 uploadiso () {
56   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
57   echo "ISO Upload Complete!"
58 }
59
60 uploadrpm () {
61   for artifact in $RPM_LIST $SRPM_LIST; do
62     echo "Uploading artifact: ${artifact}"
63     gsutil cp $artifact gs://$GS_URL/$(basename $artifact) > gsutil.iso.log
64     echo "Upload complete for ${artifact}"
65   done
66   gsutil cp $WORKSPACE/opnfv.properties gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.properties > gsutil.properties.log
67   gsutil cp $WORKSPACE/opnfv.properties gs://$GS_URL/latest.properties > gsutil.latest.log
68
69   # Make the property files viewable on the artifact site
70   gsutil -m setmeta \
71     -h "Content-Type:text/html" \
72     -h "Cache-Control:private, max-age=0, no-transform" \
73     gs://$GS_URL/latest.properties \
74     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.properties > /dev/null 2>&1
75 }
76
77 uploadsnap () {
78   # Uploads snapshot artifact and updated properties file
79   echo "Uploading snapshot artifacts"
80   SNAP_TYPE=$(echo ${JOB_NAME} | sed -n 's/^apex-\(.\+\)-promote.*$/\1/p')
81   gsutil cp $WORKSPACE/apex-${SNAP_TYPE}-snap-`date +%Y-%m-%d`.tar.gz gs://$GS_URL/ > gsutil.iso.log
82   if [ "$SNAP_TYPE" == 'csit' ]; then
83     gsutil cp $WORKSPACE/snapshot.properties gs://$GS_URL/snapshot.properties > gsutil.latest.log
84   fi
85   echo "Upload complete for Snapshot"
86 }
87
88 uploadimages () {
89   # Uploads dev tarball
90   GERRIT_PATCHSET_NUMBER=$(echo $GERRIT_REFSPEC | grep -Eo '[0-9]+$')
91   export OPNFV_ARTIFACT_VERSION="dev${GERRIT_CHANGE_NUMBER}_${GERRIT_PATCHSET_NUMBER}"
92   echo "Uploading development build tarball"
93   pushd $BUILD_DIRECTORY > /dev/null
94   tar czf apex-${OPNFV_ARTIFACT_VERSION}.tar.gz *.qcow2
95   gsutil cp apex-${OPNFV_ARTIFACT_VERSION}.tar.gz gs://$GS_URL/apex-${OPNFV_ARTIFACT_VERSION}.tar.gz > gsutil.latest.log
96   popd > /dev/null
97 }
98
99 # Always import the signing key, if it's available the artifacts will be
100 # signed before being uploaded
101 importkey
102
103 if gpg2 --list-keys | grep "opnfv-helpdesk@rt.linuxfoundation.org"; then
104   echo "Signing Key avaliable"
105   SIGN_ARTIFACT="true"
106 fi
107
108 if [ "$ARTIFACT_TYPE" == 'snapshot' ]; then
109   uploadsnap
110 elif [ "$ARTIFACT_TYPE" == 'iso' ]; then
111   if [[ "$ARTIFACT_VERSION" =~ dev ]]; then
112     echo "Skipping artifact upload for ${ARTIFACT_TYPE} due to dev build"
113     exit 0
114   fi
115   if [[ -n "$SIGN_ARTIFACT" && "$SIGN_ARTIFACT" == "true" ]]; then
116     signiso
117   fi
118   uploadiso
119 elif [ "$ARTIFACT_TYPE" == 'rpm' ]; then
120   if [[ "$ARTIFACT_VERSION" =~ dev ]]; then
121     echo "dev build detected, will upload image tarball"
122     ARTIFACT_TYPE=tarball
123     uploadimages
124   else
125     RPM_INSTALL_PATH=$BUILD_DIRECTORY/noarch
126     RPM_LIST=$RPM_INSTALL_PATH/$(basename $OPNFV_RPM_URL)
127     VERSION_EXTENSION=$(echo $(basename $OPNFV_RPM_URL) | sed 's/opnfv-apex-//')
128     for pkg in common undercloud; do # removed onos for danube
129       RPM_LIST+=" ${RPM_INSTALL_PATH}/opnfv-apex-${pkg}-${VERSION_EXTENSION}"
130     done
131     SRPM_INSTALL_PATH=$BUILD_DIRECTORY
132     SRPM_LIST=$SRPM_INSTALL_PATH/$(basename $OPNFV_SRPM_URL)
133     VERSION_EXTENSION=$(echo $(basename $OPNFV_SRPM_URL) | sed 's/opnfv-apex-//')
134     for pkg in common undercloud; do # removed onos for danube
135       SRPM_LIST+=" ${SRPM_INSTALL_PATH}/opnfv-apex-${pkg}-${VERSION_EXTENSION}"
136     done
137
138     if [[ -n "$SIGN_ARTIFACT" && "$SIGN_ARTIFACT" == "true" ]]; then
139       signrpm
140     fi
141     uploadrpm
142   fi
143 else
144   echo "ERROR: Unknown artifact type ${ARTIFACT_TYPE} to upload...exiting"
145   exit 1
146 fi
147
148 echo
149 echo "--------------------------------------------------------"
150 echo "Done!"
151 if [ "$ARTIFACT_TYPE" == 'iso' ]; then echo "ISO Artifact is available as http://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso"; fi
152 if [ "$ARTIFACT_TYPE" == 'rpm' ]; then echo "RPM Artifact is available as http://$GS_URL/$(basename $OPNFV_RPM_URL)"; fi
153 if [ "$ARTIFACT_TYPE" == 'tarball' ]; then echo "Dev tarball Artifact is available as http://$GS_URL/apex-${OPNFV_ARTIFACT_VERSION}.tar.gz)"; fi