Skip to content

Commit e4855c2

Browse files
author
Doug Greiman
committed
Create a "runtime builder" image that builds other Docker images
This builder will be called by the Google Cloud SDK during "gcloud app deploy" to create Docker images for AppEngine Flex applications.
1 parent 58e8abb commit e4855c2

File tree

6 files changed

+55
-12
lines changed

6 files changed

+55
-12
lines changed

build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ echo "Using base image name ${FULL_BASE_IMAGE}"
113113

114114
# Generate Dockerfiles
115115
for outfile in \
116+
builder/gen-dockerfile/Dockerfile \
116117
python-interpreter-builder/Dockerfile \
117118
runtime-image/Dockerfile \
118119
tests/benchmark/Dockerfile \
@@ -123,6 +124,14 @@ for outfile in \
123124
envsubst <"${outfile}".in >"${outfile}" '$DEBIAN_BASE_IMAGE $FULL_BASE_IMAGE $GOOGLE_CLOUD_PROJECT_FOR_TESTS'
124125
done
125126

127+
# Make some files available to the runtime builder Docker context
128+
for file in \
129+
gen_dockerfile.py \
130+
validation_utils.py \
131+
; do
132+
cp -a "scripts/${file}" "builder/gen-dockerfile/${file}"
133+
done
134+
126135
# Build images and push to GCR
127136
if [ "${build}" -eq 1 ]; then
128137
echo "Building images"

builder/gen-dockerfile/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Dockerfile
2+
*.py
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM ${FULL_BASE_IMAGE}
2+
LABEL python_version=python3.5
3+
RUN virtualenv --no-download /env -p python3.5
4+
5+
# Set virtualenv environment variables. This is equivalent to running
6+
# source /env/bin/activate
7+
ENV VIRTUAL_ENV /env
8+
ENV PATH /env/bin:$PATH
9+
ADD requirements.txt /builder/
10+
RUN pip install -r /builder/requirements.txt
11+
ADD . /builder/
12+
WORKDIR /workspace
13+
ENTRYPOINT [ "python", "/builder/gen_dockerfile.py" ]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pyyaml

builder/python.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This is a cloudbuild.yaml template for the runtime builder
2+
steps:
3+
- # Generate application Dockerfile
4+
name: 'gcr.io/gcp-runtimes/python/gen-dockerfile:latest'
5+
args: [
6+
'--base-image=gcr.io/google-appengine/python:latest'
7+
]
8+
- # Use that Dockerfile to create final application image
9+
name: 'gcr.io/cloud-builders/docker:latest'
10+
args: ['build', '-t', '$_OUTPUT_IMAGE', '.']
11+
images:
12+
- '$_OUTPUT_IMAGE'

cloudbuild.yaml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
timeout: 7200s
22
steps:
3-
- name: gcr.io/cloud-builders/docker:latest
4-
# Compile Python interpreters from source
3+
- # Compile Python interpreters from source
4+
name: gcr.io/cloud-builders/docker:latest
55
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/interpreter-builder:${_TAG}',
66
'--no-cache', '/workspace/python-interpreter-builder/']
7-
- name: ${_DOCKER_NAMESPACE}/python/interpreter-builder:${_TAG}
8-
# Copy interpreters back to workspace
7+
- # Copy interpreters back to workspace
8+
name: ${_DOCKER_NAMESPACE}/python/interpreter-builder:${_TAG}
99
args: ['cp', '/interpreters.tar.gz', '/workspace/runtime-image/interpreters.tar.gz']
10-
- name: gcr.io/cloud-builders/docker:latest
11-
# Build base runtime image
10+
- # Build base runtime image
11+
name: gcr.io/cloud-builders/docker:latest
1212
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python:${_TAG}',
1313
'--no-cache', '/workspace/runtime-image/']
14-
- name: gcr.io/gcp-runtimes/structure_test:latest
15-
# Validate structure of base runtime image
14+
- # Validate structure of base runtime image
15+
name: gcr.io/gcp-runtimes/structure_test:latest
1616
args: [
1717
'-i', '${_DOCKER_NAMESPACE}/python:${_TAG}',
1818
'--config', '/workspace/tests/virtualenv/virtualenv_default.yaml',
@@ -25,11 +25,17 @@ steps:
2525
'--config', '/workspace/tests/license-test/license-test.yaml',
2626
'-v'
2727
]
28-
- name: gcr.io/cloud-builders/docker:latest
29-
# Run google client library unit tests against base runtime image
28+
- # Build image to run google client library unit tests
29+
name: gcr.io/cloud-builders/docker:latest
3030
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/tests/google-cloud-python:${_TAG}',
3131
'--no-cache', '/workspace/tests/google-cloud-python/']
32-
- name: ${_DOCKER_NAMESPACE}/python/tests/google-cloud-python:${_TAG}
32+
- # Run google client library unit tests
33+
name: ${_DOCKER_NAMESPACE}/python/tests/google-cloud-python:${_TAG}
34+
- # Build runtime builder image
35+
name: gcr.io/cloud-builders/docker:latest
36+
args: ['build', '--tag=${_DOCKER_NAMESPACE}/python/builder/gen-dockerfile:${_TAG}',
37+
'--no-cache', '/workspace/builder/gen-dockerfile/']
3338
images: [
34-
'${_DOCKER_NAMESPACE}/python:${_TAG}'
39+
'${_DOCKER_NAMESPACE}/python:${_TAG}',
40+
'${_DOCKER_NAMESPACE}/python/builder/gen-dockerfile:${_TAG}',
3541
]

0 commit comments

Comments
 (0)