Skip to content

Commit dc5ed39

Browse files
authored
Add testing Dockerfile and Cloud Build configuration (GoogleCloudPlatform#3776)
* copy dockerfile from testing-infra-docker * remove python3.4 and python3.5 for faster builds * add cloudbuild.yaml * update directory in cloudbuild.yaml * add license header and timeout to cloudbuild.yaml * add libmagickwand-dev to installed packages * tag images with commit hash
1 parent 41eefe2 commit dc5ed39

File tree

2 files changed

+185
-0
lines changed

2 files changed

+185
-0
lines changed

.kokoro/docker/Dockerfile

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM ubuntu:16.04
16+
17+
ENV DEBIAN_FRONTEND noninteractive
18+
19+
# Ensure local Python is preferred over distribution Python.
20+
ENV PATH /usr/local/bin:$PATH
21+
22+
# http://bugs.python.org/issue19846
23+
# At the moment, setting "LANG=C" on a Linux system fundamentally breaks
24+
# Python 3.
25+
ENV LANG C.UTF-8
26+
27+
# Install dependencies.
28+
RUN apt-get update \
29+
&& apt-get install -y --no-install-recommends \
30+
apt-transport-https \
31+
build-essential \
32+
ca-certificates \
33+
curl \
34+
git \
35+
graphviz \
36+
libbz2-dev \
37+
libdb5.3-dev \
38+
libexpat1-dev \
39+
libffi-dev \
40+
liblzma-dev \
41+
libmagickwand-dev \
42+
libreadline-dev \
43+
libsnappy-dev \
44+
libssl-dev \
45+
libsqlite3-dev \
46+
portaudio19-dev \
47+
redis-server \
48+
software-properties-common \
49+
ssh \
50+
sudo \
51+
tcl \
52+
tcl-dev \
53+
tk \
54+
tk-dev \
55+
uuid-dev \
56+
wget \
57+
zlib1g-dev \
58+
&& apt-get clean autoclean \
59+
&& apt-get autoremove -y \
60+
&& rm -rf /var/lib/apt/lists/* \
61+
&& rm -f /var/cache/apt/archives/*.deb
62+
63+
# Install docker
64+
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
65+
66+
RUN add-apt-repository \
67+
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
68+
$(lsb_release -cs) \
69+
stable"
70+
71+
RUN apt-get update \
72+
&& apt-get install -y --no-install-recommends \
73+
docker-ce \
74+
&& apt-get clean autoclean \
75+
&& apt-get autoremove -y \
76+
&& rm -rf /var/lib/apt/lists/* \
77+
&& rm -f /var/cache/apt/archives/*.deb
78+
79+
# Install Microsoft ODBC 17 Driver and unixodbc for testing SQL Server samples
80+
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
81+
&& curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list \
82+
&& apt-get update \
83+
&& ACCEPT_EULA=Y apt-get install -y --no-install-recommends \
84+
msodbcsql17 \
85+
unixodbc-dev \
86+
&& apt-get clean autoclean \
87+
&& apt-get autoremove -y \
88+
&& rm -rf /var/lib/apt/lists/* \
89+
&& rm -f /var/cache/apt/archives/*.deb
90+
91+
# Install the desired versions of Python.
92+
RUN for PYTHON_VERSION in 2.7.17 3.6.9 3.7.5 3.8.0; do \
93+
set -ex \
94+
&& wget --no-check-certificate -O python-${PYTHON_VERSION}.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
95+
&& wget --no-check-certificate -O python-${PYTHON_VERSION}.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
96+
&& export GNUPGHOME="$(mktemp -d)" \
97+
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys \
98+
# 2.7.17 (Benjamin Peterson)
99+
C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF \
100+
# 3.4.10, 3.5.9 (Larry Hastings)
101+
97FC712E4C024BBEA48A61ED3A5CA953F73C700D \
102+
# 3.6.9, 3.7.5 (Ned Deily)
103+
0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D \
104+
# 3.8.0 (Łukasz Langa)
105+
E3FF2839C048B25C084DEBE9B26995E310250568 \
106+
&& gpg --batch --verify python-${PYTHON_VERSION}.tar.xz.asc python-${PYTHON_VERSION}.tar.xz \
107+
&& rm -r "$GNUPGHOME" python-${PYTHON_VERSION}.tar.xz.asc \
108+
&& mkdir -p /usr/src/python-${PYTHON_VERSION} \
109+
&& tar -xJC /usr/src/python-${PYTHON_VERSION} --strip-components=1 -f python-${PYTHON_VERSION}.tar.xz \
110+
&& rm python-${PYTHON_VERSION}.tar.xz \
111+
&& cd /usr/src/python-${PYTHON_VERSION} \
112+
&& ./configure \
113+
--enable-shared \
114+
# This works only on Python 2.7 and throws a warning on every other
115+
# version, but seems otherwise harmless.
116+
--enable-unicode=ucs4 \
117+
--with-system-ffi \
118+
--without-ensurepip \
119+
&& make -j$(nproc) \
120+
&& make install \
121+
&& ldconfig \
122+
; done \
123+
&& rm -rf /usr/src/python* \
124+
&& rm -rf ~/.cache/
125+
126+
127+
# Install pip on Python 3.6 only.
128+
# If the environment variable is called "PIP_VERSION", pip explodes with
129+
# "ValueError: invalid truth value '<VERSION>'"
130+
ENV PYTHON_PIP_VERSION 10.0.1
131+
RUN wget --no-check-certificate -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
132+
&& python3.6 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
133+
# we use "--force-reinstall" for the case where the version of pip we're trying to install is the same as the version bundled with Python
134+
# ("Requirement already up-to-date: pip==8.1.2 in /usr/local/lib/python3.6/site-packages")
135+
# https://github.com/docker-library/python/pull/143#issuecomment-241032683
136+
&& pip3 install --no-cache-dir --upgrade --force-reinstall "pip==$PYTHON_PIP_VERSION" \
137+
# then we use "pip list" to ensure we don't have more than one pip version installed
138+
# https://github.com/docker-library/python/pull/100
139+
&& [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ]
140+
141+
# Ensure Pip for 3.8.0
142+
RUN python3.8 /tmp/get-pip.py
143+
RUN rm /tmp/get-pip.py
144+
145+
# Install "virtualenv", since the vast majority of users of this image
146+
# will want it.
147+
RUN pip install --no-cache-dir virtualenv
148+
149+
# Setup Cloud SDK
150+
ENV CLOUD_SDK_VERSION 272.0.0
151+
# Use system python for cloud sdk.
152+
ENV CLOUDSDK_PYTHON python3.6
153+
RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-$CLOUD_SDK_VERSION-linux-x86_64.tar.gz
154+
RUN tar xzf google-cloud-sdk-$CLOUD_SDK_VERSION-linux-x86_64.tar.gz
155+
RUN /google-cloud-sdk/install.sh
156+
ENV PATH /google-cloud-sdk/bin:$PATH
157+
158+
# Enable redis-server on boot.
159+
RUN sudo systemctl enable redis-server.service
160+
161+
CMD ["python3.6"]

.kokoro/docker/cloudbuild.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
timeout: 7200s # 2 hours
16+
17+
steps:
18+
- name: 'gcr.io/cloud-builders/docker'
19+
args: ['build', '-t', 'gcr.io/$PROJECT_ID/python-samples-testing-docker', '.']
20+
dir: '.kokoro/docker'
21+
- name: gcr.io/cloud-builders/docker
22+
args: ['tag', 'gcr.io/$PROJECT_ID/python-samples-testing-docker', 'gcr.io/$PROJECT_ID/python-samples-testing-docker:$SHORT_SHA']
23+
images:
24+
- 'gcr.io/$PROJECT_ID/python-samples-testing-docker'

0 commit comments

Comments
 (0)