Merge "leverage executor to test_project.py in TestAPI"
[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   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
54   echo "ISO Upload Complete!"
55 }
56
57 uploadrpm () {
58   for artifact in $RPM_LIST $SRPM_LIST; do
59     echo "Uploading artifact: ${artifact}"
60     gsutil cp $artifact gs://$GS_URL/$(basename $artifact) > gsutil.iso.log
61     echo "Upload complete for ${artifact}"
62   done
63   gsutil cp $WORKSPACE/opnfv.properties gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.properties > gsutil.properties.log
64   gsutil cp $WORKSPACE/opnfv.properties gs://$GS_URL/latest.properties > gsutil.latest.log
65 }
66
67 uploadsnap () {
68   # Uploads snapshot artifact and updated properties file
69   echo "Uploading snapshot artifacts"
70   SNAP_TYPE=$(echo ${JOB_NAME} | sed -n 's/^apex-\(.\+\)-promote.*$/\1/p')
71   gsutil cp $WORKSPACE/apex-${SNAP_TYPE}-snap-`date +%Y-%m-%d`.tar.gz gs://$GS_URL/ > gsutil.iso.log
72   if [ "$SNAP_TYPE" == 'csit' ]; then
73     gsutil cp $WORKSPACE/snapshot.properties gs://$GS_URL/snapshot.properties > gsutil.latest.log
74   fi
75   echo "Upload complete for Snapshot"
76 }
77
78 if gpg2 --list-keys | grep "opnfv-helpdesk@rt.linuxfoundation.org"; then
79   echo "Signing Key avaliable"
80   SIGN_ARTIFACT="true"
81 fi
82
83 if [ "$ARTIFACT_TYPE" == 'snapshot' ]; then
84   uploadsnap
85 elif [ "$ARTIFACT_TYPE" == 'iso' ]; then
86   if [[ -n "$SIGN_ARTIFACT" && "$SIGN_ARTIFACT" == "true" ]]; then
87     signiso
88   fi
89   uploadiso
90 elif [ "$ARTIFACT_TYPE" == 'rpm' ]; then
91   RPM_INSTALL_PATH=$BUILD_DIRECTORY/noarch
92   RPM_LIST=$RPM_INSTALL_PATH/$(basename $OPNFV_RPM_URL)
93   VERSION_EXTENSION=$(echo $(basename $OPNFV_RPM_URL) | sed 's/opnfv-apex-//')
94   for pkg in common undercloud; do # removed onos for danube
95     RPM_LIST+=" ${RPM_INSTALL_PATH}/opnfv-apex-${pkg}-${VERSION_EXTENSION}"
96   done
97   SRPM_INSTALL_PATH=$BUILD_DIRECTORY
98   SRPM_LIST=$SRPM_INSTALL_PATH/$(basename $OPNFV_SRPM_URL)
99   VERSION_EXTENSION=$(echo $(basename $OPNFV_SRPM_URL) | sed 's/opnfv-apex-//')
100   for pkg in common undercloud; do # removed onos for danube
101     SRPM_LIST+=" ${SRPM_INSTALL_PATH}/opnfv-apex-${pkg}-${VERSION_EXTENSION}"
102   done
103
104   if [[ -n "$SIGN_ARTIFACT" && "$SIGN_ARTIFACT" == "true" ]]; then
105     signrpm
106   fi
107   uploadrpm
108 else
109   echo "ERROR: Unknown artifact type ${ARTIFACT_TYPE} to upload...exiting"
110   exit 1
111 fi
112
113 echo
114 echo "--------------------------------------------------------"
115 echo "Done!"
116 if [ "$ARTIFACT_TYPE" == 'iso' ]; then echo "ISO Artifact is available as http://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso"; fi
117 if [ "$ARTIFACT_TYPE" == 'rpm' ]; then echo "RPM Artifact is available as http://$GS_URL/$(basename $OPNFV_RPM_URL)"; fi