forked from cloudendpoints/esp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release-publish
executable file
·130 lines (112 loc) · 4.62 KB
/
release-publish
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
#
# Copyright (C) Extensible Service Proxy Authors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
################################################################################
#
# This script will:
# * download the debian package with the given SHA and
# add it to Debian package repository
# * download a Docker image with the given SHA, re-tag it with
# release version and publish it in Cloud Container Registry.
#
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
. ${ROOT}/script/all-utilities || { echo "Cannot load Bash utilities"; exit 1; }
function usage() {
[[ -n "${1}" ]] && echo "${1}"
cat <<EOF
usage: ${BASH_SOURCE[0]} -s <commit sha> [options]"
options are:
-g <path_to_gcloud>
-u <path_to_gsutil>
EOF
exit 1
}
PREFIX='google-cloud-endpoints-jessie'
GSUTIL="$(which gsutil)" || GSUTIL=~/google-cloud-sdk/bin/gsutil
GCLOUD="$(which gcloud)" || GCLOUD=~/google-cloud-sdk/bin/gcloud
SHA=""
while getopts :g:u:s: arg; do
case ${arg} in
g) GCLOUD="${OPTARG}";;
u) GSUTIL="${OPTARG}";;
s) SHA="${OPTARG}";;
*) usage "Invalid option: -${OPTARG}";;
esac
done
[[ -n "${SHA}" ]] \
|| usage "Must provide commit sha via '-s' parameter."
[[ "${SHA}" =~ ^[0-9a-f]{40}$ ]] \
|| usage "Invalid SHA: ${SHA}."
[[ -x "${GCLOUD}" ]] \
|| usage "Cannot find gcloud (${GCLOUD}), provide it via '-g' flag."
[[ -x "${GSUTIL}" ]] \
|| usage "Cannot find gsutil (${GSUTIL}), provide it via '-u' flag."
which rapture > /dev/null 2>&1 \
|| error_exit "rapture client not installed on this machine."
set -x
VERSION="$(command cat ${ROOT}/src/nginx/version)" \
|| error_exit "Cannot find release version (${ROOT}/src/nginx/version)"
CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
if RELEASE_BRANCH_SHA="$(git rev-parse upstream/${CURRENT_BRANCH})"; then
if [[ "${SHA}" != "${RELEASE_BRANCH_SHA}" ]]; then
printf "\e[31m
WARNING: Release branch commit (${RELEASE_BRANCH_SHA}) doesn't match ${SHA}.
\e[0m"
fi
else
printf "\e[31m
WARNING: Cannot find release branch origin/release-${VERSION}.
\e[0m"
fi
function push_docker_image() {
local source_image="${1}"
local target_image="${2}"
docker_tag "${source_image}" "${target_image}" \
|| { echo "Could not tag ${source_image} to ${target_image}."; return 1; }
echo "Pushing ${target_image} to Cloud Container Registry."
"${GCLOUD}" docker -- push "${target_image}" \
|| { echo "Cloud Container Registry push of ${target_image} failed."; return 1; }
return 0;
}
push_docker_image \
"gcr.io/endpoints-jenkins/endpoints-runtime:debian-git-${SHA}" \
"gcr.io/endpoints-release/endpoints-runtime:${VERSION}" \
|| error_exit "Docker image push failed."
SOURCE_PKG="gs://endpoints-jenkins.appspot.com/${SHA}/artifacts/endpoints-runtime-amd64.deb"
TARGET_PKG="$(command mktemp -d)/endpoints-runtime-amd64.deb"
"${GSUTIL}" cp "${SOURCE_PKG}" "${TARGET_PKG}" \
|| error_exit "Could not fetch ${SOURCE_PKG}."
OUTPUT="$(rapture --universe=cloud-apt addpkg ${PREFIX} ${TARGET_PKG})"
DIRECT_REPO=$(echo "${OUTPUT}" | grep "(direct)" | cut -d ' ' -f 1)
echo "${OUTPUT}"
echo
echo "The following direct package repository was created by rapture: "
echo "DIRECT_REPO=${DIRECT_REPO}"
printf '\e[31m
***************************************************************************
* Please paste the script output verbatim into the release bug. *
***************************************************************************
\e[0m'