-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathlinux-build-docker
executable file
·117 lines (100 loc) · 4.68 KB
/
linux-build-docker
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
#!/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.
#
################################################################################
#
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
. ${ROOT}/script/all-utilities || { echo "Cannot load Bash utilities"; exit 1; }
PLATFORM="flex"
DEB="${ROOT}/bazel-bin/src/nginx/main/endpoints-server-proxy.deb"
DOCKERFILE="Dockerfile"
while getopts :c:d:i:s:t:p: arg; do
case ${arg} in
c) CONFIG="${OPTARG}";;
d) DEB="${OPTARG}";;
i) IMAGE="${OPTARG}";;
s) SERVERLESS_IMAGE="${OPTARG}";;
t) SECURE_IMAGE="${OPTARG}";;
p) PLATFORM="${OPTARG}";;
*) error_exit "Unrecognized argument -${OPTARG}";;
esac
done
[[ -n "${IMAGE}" ]] || error_exit "Specify required image argument via '-i'"
[[ -f "${DEB}" ]] || error_exit "Cannot find Debian package ${DEB}"
echo "Checking if docker image ${IMAGE} exists.."
gcloud docker -- pull "${IMAGE}" \
&& { echo "Image ${IMAGE} already exists; skipping"; exit 0; }
echo "Building Endpoints Runtime docker image."
DOCKERFILE_PATH="./docker/${PLATFORM}"
# Use same Dockerfile as Flex team to build Flex docker image.
if [[ "${PLATFORM}" == "flex" ]]; then
FLEX_DIR=$(mktemp -d /tmp/flex_XXXXX)
git clone https://github.com/GoogleCloudPlatform/appengine-sidecars-docker $FLEX_DIR
# Update the Dockerfile to use local deb image
DIMG="endpoints-runtime.deb"
sed -i -e "s|endpoints-runtime||" \
-e 's|ARG BASE_IMAGE_TAG=latest||' \
-e 's|${BASE_IMAGE_TAG}|latest|' \
-e "s|EXPOSE 8080|\nADD ${DIMG} ${DIMG}\nRUN apt-get update --fix-missing -qq \&\& \\\ \n apt-get install -qqy python \&\& \\\ \n dpkg -i /${DIMG}\n&|" \
"$FLEX_DIR/nginx_proxy/Dockerfile"
DOCKERFILE_PATH="$FLEX_DIR/nginx_proxy"
cat "$FLEX_DIR/nginx_proxy/Dockerfile"
fi
rm -f "${DOCKERFILE_PATH}/endpoints-runtime.deb"
cp "${DEB}" "${DOCKERFILE_PATH}/endpoints-runtime.deb"
retry -n 3 docker build --no-cache -t "${IMAGE}" \
-f "${DOCKERFILE_PATH}/${DOCKERFILE}" \
"${DOCKERFILE_PATH}/" \
|| error_exit "Docker image build failed."
echo "Pushing Docker image: ${IMAGE}"
# Try 10 times, shortest wait is 10 seconds, exponential back-off.
retry -n 10 -s 10 \
gcloud docker -- push "${IMAGE}" \
|| error_exit "Failed to upload Docker image to gcr."
# Build secure docker image
if [[ -n "${SECURE_IMAGE}" ]]; then
echo "Building secure docker image."
sed -e "s|\${PARENT_IMAGE}|${IMAGE}|g" \
"${ROOT}/docker/secure/Dockerfile.template" > "${ROOT}/docker/secure/Dockerfile"
retry -n 3 docker build --no-cache -t "${SECURE_IMAGE}" ./docker/secure/ \
|| error_exit "Failed to build secure Docker Image."
echo "Pushing secure Docker image: ${SECURE_IMAGE}"
retry -n 10 -s 10 \
gcloud docker -- push "${SECURE_IMAGE}" \
|| error_exit "Failed to upload secure Docker image to gcr."
fi
# Build serverless docker image
if [[ -n "${SERVERLESS_IMAGE}" && -n "${SECURE_IMAGE}" ]]; then
echo "Building serverless docker image."
sed -e "s|\${PARENT_IMAGE}|${SECURE_IMAGE}|g" \
"${ROOT}/docker/serverless/Dockerfile.template" > "${ROOT}/docker/serverless/Dockerfile"
retry -n 3 docker build --no-cache -t "${SERVERLESS_IMAGE}" ./docker/serverless/ \
|| error_exit "Failed to build serverless Docker Image."
echo "Pushing serverless Docker image: ${SERVERLESS_IMAGE}"
retry -n 10 -s 10 \
gcloud docker -- push "${SERVERLESS_IMAGE}" \
|| error_exit "Failed to upload serverless Docker image to gcr."
fi