Revert "container4nfv: Disable jobs until the project stops changing docker version"
[releng.git] / jjb / daisy4nfv / daisy4nfv-build-kolla-image.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2016 ZTE Coreporation and others.
4 # hu.zhijiang@zte.com.cn
5 # sun.jing22@zte.com.cn
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12
13 set -o errexit
14 set -o nounset
15 set -o pipefail
16
17 importkey () {
18     # clone releng repository
19     echo "Cloning releng repository..."
20     [ -d releng ] && rm -rf releng
21     git clone https://gerrit.opnfv.org/gerrit/releng ./releng/ &> /dev/null
22     #this is where we import the siging key
23     if [ -f ./releng/utils/gpg_import_key.sh ]; then
24         source ./releng/utils/gpg_import_key.sh
25     fi
26 }
27
28 upload_image_to_opnfv () {
29     image=$1
30
31     importkey
32     if gpg2 --list-keys | grep "opnfv-helpdesk@rt.linuxfoundation.org"; then
33         echo "Signing Key avaliable"
34         SIGN_ARTIFACT="true"
35     fi
36
37     if [[ -n "$SIGN_ARTIFACT" && "$SIGN_ARTIFACT" == "true" ]]; then
38         gpg2 -vvv --batch --yes --no-tty \
39             --default-key opnfv-helpdesk@rt.linuxfoundation.org  \
40             --passphrase besteffort \
41             --detach-sig $image
42         gsutil cp $image.sig gs://$GS_URL/upstream/$image.sig
43         echo "Image signature upload complete!"
44     fi
45
46     sha512sum -b $image > $image.sha512sum
47     gsutil cp $image.sha512sum gs://$GS_URL/upstream/$image.sha512sum
48
49     echo "Uploading $INSTALLER_TYPE artifact. This could take some time..."
50     echo
51     gsutil cp $image gs://$GS_URL/upstream/$image
52     gsutil -m setmeta \
53         -h "Cache-Control:private, max-age=0, no-transform" \
54         gs://$GS_URL/upstream/$image
55
56     # check if we uploaded the file successfully to see if things are fine
57     gsutil ls gs://$GS_URL/upstream/$image
58     if [[ $? -ne 0 ]]; then
59         echo "Problem while uploading artifact!"
60         exit 1
61     fi
62 }
63
64
65
66 echo "--------------------------------------------------------"
67 echo "This is diasy4nfv kolla image build job!"
68 echo "--------------------------------------------------------"
69
70 # start the build
71 cd $WORKSPACE
72 rm -rf docker_build_dir
73 mkdir -p docker_build_dir
74
75 # -j is for deciding which branch will be used when building,
76 # only for OPNFV
77 sudo -E ./ci/kolla-build.sh -j $JOB_NAME -w $WORKSPACE/docker_build_dir
78
79 if [ $? -ne 0 ]; then
80     echo
81     echo "Kolla build failed!"
82     deploy_ret=1
83 else
84     echo
85     echo "--------------------------------------------------------"
86     echo "Kolla build done!"
87 fi
88
89 image=$(ls $WORKSPACE/docker_build_dir/kolla-build-output/kolla-image-*.tgz)
90 upload_image_to_opnfv $image
91
92 echo
93 echo "--------------------------------------------------------"
94 echo "All done!"