Skip to content

Commit

Permalink
Really update to Python 3.7 (zalando-stups#21) (zalando-stups#22) (za…
Browse files Browse the repository at this point in the history
…lando-stups#24) and force pip3.7 to be default pip (zalando-stups#23)
  • Loading branch information
Dmytro Zavalkin committed Mar 24, 2020
1 parent 01759f1 commit 58dd981
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 51 deletions.
38 changes: 25 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
FROM registry.opensource.zalan.do/stups/ubuntu:latest
MAINTAINER Zalando SE
ARG UBUNTU_VERSION=latest

# Install python tools and dev packages
RUN apt-get update \
&& apt-get install -q -y --no-install-recommends python3.7-dev python3-pip python3-setuptools python3-wheel gcc \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
FROM registry.opensource.zalan.do/stups/ubuntu:$UBUNTU_VERSION
LABEL maintainer="Zalando SE"

# set python 3 as the default python version
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1 \
&& update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
RUN pip3 install --upgrade pip requests setuptools pipenv
# Install python 3.7 tools and dev packages
RUN apt-get update && \
apt-get install -q -y --no-install-recommends \
python3.7 \
python3.7-dev \
python3-pip && \
python3.7 -m pip install --no-cache-dir --upgrade --force-reinstall pip setuptools wheel && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# make requests library use the Debian CA bundle (includes Zalando CA)
# Set python 3.7 as the default python version and pip 3.7 as the default pip version
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1 && \
update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1 && \
rm -f /usr/bin/pip3 && \
update-alternatives --install /usr/bin/pip3 pip3 /usr/local/bin/pip3.7 1 && \
update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.7 1

# Check that default python and pip commands have correct versions
RUN python -V | grep 'Python 3.7' && \
pip -V | grep '(python 3.7)'

# Make requests library use the Debian CA bundle (includes Zalando CA)
ENV REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt

CMD python3
CMD python

RUN purge.sh
5 changes: 0 additions & 5 deletions Dockerfile.test

This file was deleted.

5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Zalando Docker Python Image
===========================

This Docker base image contains Python 3.6 and the Zalando CA certificate.
This Docker base image contains Python 3.7 and the Zalando CA certificate.
Versions of this image will be immutable, i.e. there is no "latest" tag, but instead version numbers are incremented
like::

<PYTHON_VERSION>-<COUNTER> (example: "3.6.1-1")
<PYTHON_VERSION>-<COUNTER> (example: "3.7.1-1")

Build the Docker image:

Expand All @@ -17,4 +17,3 @@ Build the Docker image:
You can find the `latest Python Docker image in our open source registry`_.

.. _latest Python Docker image in our open source registry: https://registry.opensource.zalan.do/teams/stups/artifacts/python/tags

48 changes: 23 additions & 25 deletions delivery.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
version: "2017-09-20"
dependencies:
- id: base
type: docker
ref: registry.opensource.zalan.do/stups/ubuntu
- id: base_ubuntu
type: docker
ref: registry.opensource.zalan.do/stups/ubuntu
pipeline:
- id: build
type: script
env:
IMAGE: registry-write.opensource.zalan.do/stups/python
commands:
- desc: 'Install Docker'
cmd: 'curl -sSL https://delivery.cloud.zalando.com/utils/ensure-docker | sh'
- desc: 'Build'
- desc: Build the docker image
cmd: |
# use the resolved Ubuntu base image version
echo "Ubuntu base image version: ${DEP_BASE_VERSION}"
sed -i "s,:latest,:${DEP_BASE_VERSION}," Dockerfile
image=python-temp:${CDP_BUILD_VERSION}
docker build -t $image --squash .
sed -i "s,UNTESTED,$image,g" Dockerfile.test
docker build -t $image-test -f Dockerfile.test .
# get current Python version
out=$(docker run $image-test)
echo "$out"
# e.g. "Python Version: CPython 3.6.1"
version=$(echo "$out" | grep 'Python Version:' | awk '{ print $4}')
release=registry-write.opensource.zalan.do/stups/python:$version-${CDP_TARGET_BRANCH_COUNTER}
docker tag $image $release
IS_PR_BUILD=${CDP_PULL_REQUEST_NUMBER+"true"}
if [[ ${IS_PR_BUILD} != "true" ]]
then
docker push $release
# Use the resolved Ubuntu base image version
echo "Ubuntu base image version: ${DEP_BASE_UBUNTU_VERSION}"
docker build --squash \
--tag ${IMAGE}:local \
--build-arg UBUNTU_VERSION=${DEP_BASE_UBUNTU_VERSION} \
.
# Get current Python version
PYTHON_VERSION=$(docker run ${IMAGE}:local python -V | awk '{ print $2}')
echo "Successfully built docker image with Python version: ${PYTHON_VERSION}"
# Tag and push the image (but only if it is a master branch)
if [ -z "$CDP_PULL_REQUEST_NUMBER" ]; then
TAG=${PYTHON_VERSION}-${CDP_TARGET_BRANCH_COUNTER}
docker tag ${IMAGE}:local ${IMAGE}:${TAG}
docker push ${IMAGE}:${TAG}
else
echo "Image not pushed because the build is not a push to master"
echo "Image not pushed because the build is not a push to master"
fi
5 changes: 0 additions & 5 deletions test.py

This file was deleted.

0 comments on commit 58dd981

Please sign in to comment.