-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathrobot-release
executable file
·157 lines (141 loc) · 6.14 KB
/
robot-release
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/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.
#
################################################################################
#
RELEASE_TAR=''
RELEASE_DEB=''
RELEASE_JSON=''
SKIP_TESTS='false'
# Generic docker image format. Docker image name is computed using:
# git show -q HEAD --pretty=format:"${RELEASE_FLEX_IMAGE_FORMAT}"
# The format string can therefore contain format placeholders:
# https://git-scm.com/docs/git-show
RELEASE_FLEX_IMAGE_FORMAT='gcr.io/endpointsv2/endpoints-runtime-flex:debian-git-%H'
RELEASE_GENERIC_IMAGE_FORMAT='gcr.io/endpointsv2/endpoints-runtime'
RELEASE_GENERIC_IMAGE_FORMAT+=':debian-git-%H'
RELEASE_SERVERLESS_IMAGE_FORMAT='gcr.io/endpointsv2/endpoints-runtime-serverless'
RELEASE_SERVERLESS_IMAGE_FORMAT+=':debian-git-%H'
RELEASE_SECURE_IMAGE_FORMAT='gcr.io/endpointsv2/endpoints-runtime-secure'
RELEASE_SECURE_IMAGE_FORMAT+=':debian-git-%H'
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
. ${ROOT}/script/all-utilities || { echo 'Cannot load Bash utilities'; exit 1; }
CONFIG=''
while getopts :c:d:f:g:h:j:m:r:s:t:v: arg; do
case ${arg} in
c) CONFIG="${OPTARG}";;
d) RELEASE_DEB="${OPTARG}";;
f) RELEASE_FLEX_IMAGE_FORMAT="${OPTARG}";;
g) RELEASE_GENERIC_IMAGE_FORMAT="${OPTARG}";;
h) RELEASE_SERVERLESS_IMAGE_FORMAT="${OPTARG}";;
j) RELEASE_JSON="${OPTARG}";;
m) RELEASE_FLEX_IMAGE_FORMAT="${OPTARG}";;
s) RELEASE_SECURE_IMAGE_FORMAT="${OPTARG}";;
t) RELEASE_TAR="${OPTARG}";;
*) echo "Invalid argument -${OPTARG}, ignoring.";;
esac
done
[[ -n "${CONFIG}" ]] \
&& CONFIG="${ROOT}/${CONFIG}" \
&& echo "Using server config ${CONFIG}"
( echo 'Building and installing dependencies.'
${ROOT}/script/linux-build-dependencies \
|| error_exit 'Failed to build and install dependencies.'
) || error_exit 'Build of dependencies failed.'
${BAZEL} ${BAZEL_ARGS} clean \
|| error_exit 'Failed to ${BAZEL} ${BAZEL_ARGS} clean before the release build.'
read ENDPOINTS_RUNTIME_VERSION < ${ROOT}/src/nginx/version
BAZEL_VERSION="$(${BAZEL} ${BAZEL_ARGS} version \
| grep '^Build label: ' | sed 's/^Build label: //')"
echo "Bazel ${BAZEL_VERSION}" > "${ROOT}/src/nginx/main/built_using"
DEB="${ROOT}/bazel-bin/src/nginx/main/endpoints-server-proxy.deb"
NGINX="${ROOT}/bazel-bin/src/nginx/main/nginx-esp"
# Placeholder for debian package.
TMP_DEBIAN_DIR="$(mktemp -d)" # Create a temp directory
TMP_DEBIAN_PACKAGE="${TMP_DEBIAN_DIR}/endpoints-server-proxy.deb"
if [[ -n "${RELEASE_DEB}" ]]; then
echo "Attempting to download ${RELEASE_DEB}."
rm -f "${TMP_DEBIAN_PACKAGE}"
gsutil cp "${RELEASE_DEB}" "${TMP_DEBIAN_PACKAGE}" \
|| echo "Failed to download ${RELEASE_DEB}. Building it."
fi
if ! [[ -e "${TMP_DEBIAN_PACKAGE}" ]]; then
echo 'Building debug nginx....'
${BAZEL} ${BAZEL_ARGS} build ${BAZEL_BUILD_ARGS} \
-c dbg //src/nginx/main:nginx-esp
echo 'Copying debug nginx...'
cp -f "${NGINX}" "${ROOT}/start_esp/nginx-debug"
echo 'Building Endpoints Runtime .deb package.'
${BAZEL} ${BAZEL_ARGS} build ${BAZEL_BUILD_ARGS} \
--config=release //src/nginx/main:endpoints-server-proxy \
|| error_exit 'Failed to build Endpoints Runtime .deb package.'
if [[ -n "${RELEASE_DEB}" ]]; then
echo "Uploading ${DEB} to ${RELEASE_DEB}"
retry -n 3 gsutil -h Content-Type:application/x-deb cp \
${DEB} \
${RELEASE_DEB} \
|| error_exit 'Debian package upload failed.'
fi
cp -f "${DEB}" "${TMP_DEBIAN_PACKAGE}" \
|| error_exit "Could not copy ${DEB} to ${TMP_DEBIAN_PACKAGE}"
fi
# Build docker container image for FLEX deployment.
if [[ -n "${RELEASE_FLEX_IMAGE_FORMAT}" ]]; then
FLEX_IMAGE="$(git show -q HEAD \
--pretty=format:"${RELEASE_FLEX_IMAGE_FORMAT}")"
${ROOT}/script/linux-build-docker -d "${TMP_DEBIAN_PACKAGE}" \
-i "${FLEX_IMAGE}" -p flex \
|| error_exit 'Failed to build a Flex Docker Image.'
fi
# Build docker container image for GKE/GCE deployment.
if [[ -n "${RELEASE_GENERIC_IMAGE_FORMAT}" ]]; then
GENERIC_IMAGE="$(git show -q HEAD \
--pretty=format:"${RELEASE_GENERIC_IMAGE_FORMAT}")"
SERVERLESS_IMAGE="$(git show -q HEAD \
--pretty=format:"${RELEASE_SERVERLESS_IMAGE_FORMAT}")"
SECURE_IMAGE="$(git show -q HEAD \
--pretty=format:"${RELEASE_SECURE_IMAGE_FORMAT}")"
${ROOT}/script/linux-build-docker -c "${CONFIG}" \
-d "${TMP_DEBIAN_PACKAGE}" -i "${GENERIC_IMAGE}" \
-s "${SERVERLESS_IMAGE}" -t "${SECURE_IMAGE}" -p generic \
|| error_exit 'Failed to build a generic Docker Image.'
fi
if [[ -n "${RELEASE_JSON}" ]]; then
{
echo "Uploading results to ${RELEASE_JSON}."
retry -n 3 gsutil -h Content-Type:application/json cp \
- "${RELEASE_JSON}" <<__EOF__
{
"docker": "${FLEX_IMAGE}",
"flexDocker": "${FLEX_IMAGE}",
"genericDocker": "${GENERIC_IMAGE}",
"serverlessDocker": "${SERVERLESS_IMAGE}",
"releaseDeb": "${RELEASE_DEB}",
"versionedDeb": "${RELEASE_DEB}"
}
__EOF__
} || error_exit 'Docker status upload failed.'
fi