From df8eb71df31599f2c72a408b2127dfee564ff13b Mon Sep 17 00:00:00 2001 From: David Buxton Date: Tue, 10 Mar 2020 14:55:13 +0000 Subject: [PATCH] Run tests using Cloud Build for CI. The Cloud Build runner uses a custom Docker image which includes the Cloud SDK tools, and multiple versions of Python. --- cloud-build/Dockerfile | 60 +++++++++++++++++++++++++++++++++++++ cloud-build/README.md | 26 ++++++++++++++++ cloud-build/cloudbuild.yaml | 26 ++++++++++++++++ cloudbuild.yaml | 31 +++++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 cloud-build/Dockerfile create mode 100644 cloud-build/README.md create mode 100644 cloud-build/cloudbuild.yaml create mode 100644 cloudbuild.yaml diff --git a/cloud-build/Dockerfile b/cloud-build/Dockerfile new file mode 100644 index 0000000..764f9a0 --- /dev/null +++ b/cloud-build/Dockerfile @@ -0,0 +1,60 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Based on https://github.com/dhermes/python-multi +FROM gcr.io/google.com/cloudsdktool/cloud-sdk:latest + +ENV DEBIAN_FRONTEND noninteractive + +# Install dependencies. +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + make \ + build-essential \ + libssl-dev \ + zlib1g-dev \ + libbz2-dev \ + libreadline-dev \ + libsqlite3-dev \ + wget \ + curl \ + llvm \ + libncurses5-dev \ + xz-utils \ + tk-dev \ + libxml2-dev \ + libxmlsec1-dev \ + git \ + ca-certificates \ + libffi-dev \ + && apt-get clean autoclean \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* \ + && rm -f /var/cache/apt/archives/*.deb + +# Install ``pyenv``. +RUN git clone https://github.com/pyenv/pyenv /root/.pyenv + +# Install the desired versions of Python. +RUN for PYTHON_VERSION in 3.7.6 3.8.2; do \ + set -ex \ + && /root/.pyenv/bin/pyenv install ${PYTHON_VERSION} \ + && /root/.pyenv/versions/${PYTHON_VERSION}/bin/python -m pip install --upgrade pip \ + ; done + +# Add to PATH, in order of lowest precedence to highest. +ENV PATH /root/.pyenv/versions/3.7.6/bin:${PATH} +ENV PATH /root/.pyenv/versions/3.8.2/bin:${PATH} + +CMD ["python3.8"] diff --git a/cloud-build/README.md b/cloud-build/README.md new file mode 100644 index 0000000..d0f59ad --- /dev/null +++ b/cloud-build/README.md @@ -0,0 +1,26 @@ +Cloud build image +================= + +The Cloud Build trigger uses a custom image saved to the project's container registry. This image has executables for Python versions 3.7 and 3.8. + +Use the files in this directory to create or update the custom image. + + +Build +----- + + cd cloud-build + gcloud builds submit \ + --project gae-secure-scaffold-python3 \ + --config cloudbuild.yaml + + +The Docker image is based on https://github.com/dhermes/python-multi + + +Continuous integration +---------------------- + +The CI pipeline uses the Cloud Build GitHub app, and a Cloud Build trigger configured to fire when pull requests are made. + +Cloud Build dashboard: https://console.cloud.google.com/cloud-build/dashboard?project=gae-secure-scaffold-python3 diff --git a/cloud-build/cloudbuild.yaml b/cloud-build/cloudbuild.yaml new file mode 100644 index 0000000..a9b10e5 --- /dev/null +++ b/cloud-build/cloudbuild.yaml @@ -0,0 +1,26 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +steps: + + - name: "gcr.io/cloud-builders/docker" + args: + - "build" + - "--tag" + - "gcr.io/$PROJECT_ID/multi-python-ci" + - "." + +images: + + - "gcr.io/$PROJECT_ID/multi-python-ci" diff --git a/cloudbuild.yaml b/cloudbuild.yaml new file mode 100644 index 0000000..3731e73 --- /dev/null +++ b/cloudbuild.yaml @@ -0,0 +1,31 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +steps: + + # See cloud-build/README.md for creating this image. + - name: 'gcr.io/$PROJECT_ID/multi-python-ci' + id: 'Create a virtualenv' + entrypoint: 'python' + args: ['-m', 'venv', '.venv'] + + - name: 'gcr.io/$PROJECT_ID/multi-python-ci' + id: 'Install testing tools' + entrypoint: '.venv/bin/pip' + args: ['install', 'nox'] + + # nox is configured with noxfile.py + - name: 'gcr.io/$PROJECT_ID/multi-python-ci' + id: 'Run tests' + entrypoint: '.venv/bin/nox'