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