Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python 3.8 and Poetry #4

Merged
merged 7 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ $RECYCLE.BIN/
# End of https://www.gitignore.io/api/osx,vim,emacs,linux,python,windows,sublimetext,visualstudiocode

# Tests generated files
test_pipenv
test_poetry
testsite
Pipfile
Pipfile.lock
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ env:
matrix:
- PYTHON_VERSION=3.6
- PYTHON_VERSION=3.7
- PYTHON_VERSION=3.8

script:
- make "python$PYTHON_VERSION"
Expand Down
15 changes: 12 additions & 3 deletions 3.6/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ FROM ubuntu:bionic

ARG PYTHON_VERSION
ARG PIPENV_VERSION
ARG POETRY_VERSION

ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHON_BIN=/usr/bin/python
ENV PIP_BIN=/usr/bin/pip
ENV PIPENV_VENV_IN_PROJECT=yes
ENV DEV_USER=dev

RUN apt-get update \
&& apt-get upgrade --quiet --yes \
Expand All @@ -18,13 +20,14 @@ RUN apt-get update \
locales \
python${PYTHON_VERSION} \
python3-distutils \
python${PYTHON_VERSION}-venv \
software-properties-common \
tzdata \
unzip \
&& apt-get autoremove --quiet --yes \
&& apt-get clean \
&& curl --silent https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION} \
&& pip3 install pipenv==${PIPENV_VERSION}
&& pip3 install pipenv==${PIPENV_VERSION} poetry==${POETRY_VERSION}

# Set the locale
RUN locale-gen en_US
Expand All @@ -48,15 +51,21 @@ EXPOSE 8000
WORKDIR /var/www/app

# Create less privileged user
RUN groupadd --gid 1000 dev \
&& useradd --uid 1000 --gid dev --shell /bin/bash --create-home dev
RUN groupadd --gid 1000 ${DEV_USER} \
&& useradd --uid 1000 --gid ${DEV_USER} --shell /bin/bash --create-home ${DEV_USER}

# Fix permissions issues
RUN chmod --recursive a+wrx /var/www/app
RUN chmod a+wrx ${PYTHON_BIN}
RUN chmod a+wrx ${PYTHON_BIN}3
RUN chmod a+wrx ${PIP_BIN}

# Copy Poetry configuration file
COPY config/poetry/config.toml /root/.config/pypoetry/config.toml
COPY config/poetry/config.toml /home/${DEV_USER}/.config/pypoetry/config.toml
RUN chmod -R 775 /root/.config
RUN chown -R ${DEV_USER}:${DEV_USER} /home/${DEV_USER}/.config && chmod -R 775 /home/${DEV_USER}/.config

# Label schema related variables and metadata
ARG BUILD_DATE
ARG VCS_REF
Expand Down
15 changes: 12 additions & 3 deletions 3.7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ FROM ubuntu:bionic

ARG PYTHON_VERSION
ARG PIPENV_VERSION
ARG POETRY_VERSION

ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHON_BIN=/usr/bin/python
ENV PIP_BIN=/usr/bin/pip
ENV PIPENV_VENV_IN_PROJECT=yes
ENV DEV_USER=dev

RUN apt-get update \
&& apt-get upgrade --quiet --yes \
Expand All @@ -18,13 +20,14 @@ RUN apt-get update \
locales \
python${PYTHON_VERSION} \
python3-distutils \
python${PYTHON_VERSION}-venv \
software-properties-common \
tzdata \
unzip \
&& apt-get autoremove --quiet --yes \
&& apt-get clean \
&& curl --silent https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION} \
&& pip3 install pipenv==${PIPENV_VERSION}
&& pip3 install pipenv==${PIPENV_VERSION} poetry==${POETRY_VERSION}

# Set the locale
RUN locale-gen en_US
Expand All @@ -47,14 +50,20 @@ EXPOSE 8000
WORKDIR /var/www/app

# Create less privileged user
RUN groupadd --gid 1000 dev \
&& useradd --uid 1000 --gid dev --shell /bin/bash --create-home dev
RUN groupadd --gid 1000 ${DEV_USER} \
&& useradd --uid 1000 --gid ${DEV_USER} --shell /bin/bash --create-home ${DEV_USER}

# Fix permissions issues
RUN chmod --recursive a+wrx /var/www/app
RUN chmod a+wrx ${PYTHON_BIN}
RUN chmod a+wrx ${PYTHON_BIN}3

# Copy Poetry configuration file
COPY config/poetry/config.toml /root/.config/pypoetry/config.toml
COPY config/poetry/config.toml /home/${DEV_USER}/.config/pypoetry/config.toml
RUN chmod -R 775 /root/.config
RUN chown -R ${DEV_USER}:${DEV_USER} /home/${DEV_USER}/.config && chmod -R 775 /home/${DEV_USER}/.config

# Label schema related variables and metadata
ARG BUILD_DATE
ARG VCS_REF
Expand Down
86 changes: 86 additions & 0 deletions 3.8/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# vim: set syntax=dockerfile:

FROM ubuntu:bionic

ARG PYTHON_VERSION
ARG PIPENV_VERSION
ARG POETRY_VERSION

ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHON_BIN=/usr/bin/python
ENV PIP_BIN=/usr/bin/pip
ENV PIPENV_VENV_IN_PROJECT=yes
ENV DEV_USER=dev

RUN apt-get update \
&& apt-get upgrade --quiet --yes \
&& apt-get update --quiet \
&& apt-get install --quiet --yes \
curl \
locales \
python${PYTHON_VERSION} \
python3-distutils \
python${PYTHON_VERSION}-venv \
software-properties-common \
tzdata \
unzip \
&& apt-get autoremove --quiet --yes \
&& apt-get clean \
&& curl --silent https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION} \
&& pip3 install pipenv==${PIPENV_VERSION} poetry==${POETRY_VERSION}

# Set the locale
RUN locale-gen en_US
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# Set timezone
RUN rm /etc/localtime
RUN ln -s /usr/share/zoneinfo/Europe/Zurich /etc/localtime

# Create symbolic link to Python 3 binaries
RUN ln -sf $(which python${PYTHON_VERSION}) ${PYTHON_BIN}
RUN ln -sf $(which python${PYTHON_VERSION}) ${PYTHON_BIN}3

EXPOSE 8000

# Mount your app source code directory into that folder
WORKDIR /var/www/app

# Create less privileged user
RUN groupadd --gid 1000 ${DEV_USER} \
&& useradd --uid 1000 --gid ${DEV_USER} --shell /bin/bash --create-home ${DEV_USER}

# Fix permissions issues
RUN chmod --recursive a+wrx /var/www/app
RUN chmod a+wrx ${PYTHON_BIN}
RUN chmod a+wrx ${PYTHON_BIN}3

# Copy Poetry configuration file
COPY config/poetry/config.toml /root/.config/pypoetry/config.toml
COPY config/poetry/config.toml /home/${DEV_USER}/.config/pypoetry/config.toml
RUN chmod -R 775 /root/.config
RUN chown -R ${DEV_USER}:${DEV_USER} /home/${DEV_USER}/.config && chmod -R 775 /home/${DEV_USER}/.config

# Label schema related variables and metadata
ARG BUILD_DATE
ARG VCS_REF

LABEL maintainer="Julien M'Poy <julien.mpoy@gmail.com>" \
org.label-schema.build-date=${BUILD_DATE} \
org.label-schema.schema-version="1.0" \
org.label-schema.url="https://github.com/groovytron/python-container" \
org.label-schema.vcs-ref=${VCS_REF} \
org.label-schema.vcs-url="https://github.com/groovytron/python-container" \
org.opencontainers.image.authors="Julien M'Poy <julien.mpoy@gmail.com>" \
org.opencontainers.image.created=${BUILD_DATE} \
org.opencontainers.image.description="Python container for local Python web development" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.revision=${VCS_REF} \
org.opencontainers.image.source="https://github.com/groovytron/python-container" \
org.opencontainers.image.title="Python Container" \
org.opencontainers.image.url="https://github.com/groovytron/python-container" \
org.opencontainers.image.vendor="Julien M'Poy <julien.mpoy@gmail.com>" \
org.opencontainers.image.version="3.8"
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

## 2.0.0

- feature: add image for Python 3.8 (issue #3)
- feature: add poetry to manage dependencies (issue #2)

## 1.0.0

- feature: add images for Python 3.6 and Python 3.7
- feature: pipenv is embedded to manage dependencies
- feature: added [Open Containers Initiative's annotations](https://github.com/opencontainers/image-spec/blob/bd4f8fcb0979a663d8b97a1d4d9b030b3d2ca1fa/annotations.md) to images (issue #1)
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BUILD_NAME=python
COMPOSE_BUILD_NAME=python-container
VERSIONS=3.7 3.6
VERSIONS=3.8 3.7 3.6
ALL=$(addprefix python,$(VERSIONS))
VCS_REF="$(shell git rev-parse HEAD)"
BUILD_DATE="$(shell date -u +"%Y-%m-%dT%H:%m:%SZ")"
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

Docker container allowing you to build and test your Python project. _This container mainly targets Python web project developments but you can try to make it work with your project even if your project is not using web technologies_.


## Supported tags and respective `Dockerfile` links

- `3.7`, `latest` ([3.7/Dockerfile](https://github.com/groovytron/python-container/blob/master/3.7/Dockerfile))
- `3.8`, `latest` ([3.8/Dockerfile](https://github.com/groovytron/python-container/blob/master/3.8/Dockerfile))
- `3.7` ([3.7/Dockerfile](https://github.com/groovytron/python-container/blob/master/3.7/Dockerfile))
- `3.6` ([3.6/Dockerfile](https://github.com/groovytron/python-container/blob/master/3.6/Dockerfile))

[`pipenv`](https://github.com/pypa/pipenv) is installed in every image to make Python dependencies installation easier.
[`poetry`](https://python-poetry.org/) is installed in every image to make Python dependencies installation easier. [`pipenv`](https://github.com/pypa/pipenv) is also installed if you prefer to use this solution for dependencies management.

## Use the container

Expand All @@ -28,9 +28,11 @@ To run the container and open a bash in your python project run the following co

- The python interpreter is usable through the `python` or `python3`
- You can install python packages using either `pip` or `pip3`
- `pipenv` is installed in the container if you want to manage your dependencies using that tool
- You can manage your dependencies using either `poetry` or `pipenv`

**Note**: as the `PIPENV_VENV_IN_PROJECT` environment variable is set, `pipenv` will create the virtual environment in a folder called `.venv` in your project directory. This configuration is applied to `root` and `dev` users.

**Note that as the `PIPENV_VENV_IN_PROJECT` environment variable is set, `pipenv` will create the virtual environment in a folder called `.venv` in your project directory.**
**Note**: as poetry's configuration is contained into [config/poetry/config.toml](https://github.com/groovytron/python-container/blob/master/config/poetry/config.toml) and [`virtualenvs.in-project`](https://python-poetry.org/docs/configuration/#virtualenvsin-project-boolean) is set to `true`, `poetry` will create the virtual environment in a folder called `.venv` in your project directory. This configuration is applied to `root` and `dev` users.

## Contributing

Expand All @@ -44,9 +46,7 @@ If you want to improve one of these images, your will need the following softwar
- `docker-compose` (if you want to build images using the file [build.yml](https://github.com/groovytron/python-container/blob/master/build.yml))
- `make` (if you want to build images using the file [build.yml](https://github.com/groovytron/python-container/blob/master/build.yml) and abstract from it with the [Makefile](https://github.com/groovytron/python-container/blob/master/Makefile))

Once you have the above softwares installed, run `make python3.7` to build the `python3.7` image.
To build all the images, run `make all`.
If you want to clean your builds, simply run `make clean`.
Once you have the above softwares installed, run `make python3.7` to build the `python3.7` image. To build all the images, run `make all`. If you want to clean your builds, simply run `make clean`.

## License

Expand Down
13 changes: 13 additions & 0 deletions build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
version: '3'

services:
python3.8:
image: ${COMPOSE_BUILD_NAME}:3.8
build:
dockerfile: 3.8/Dockerfile
context: .
args:
- BUILD_DATE=$BUILD_DATE
- PIPENV_VERSION=2018.11.26
- POETRY_VERSION=1.0.5
- PYTHON_VERSION=3.8
- VCS_REF=$VCS_REF
python3.7:
image: ${COMPOSE_BUILD_NAME}:3.7
build:
Expand All @@ -10,6 +21,7 @@ services:
args:
- BUILD_DATE=$BUILD_DATE
- PIPENV_VERSION=2018.11.26
- POETRY_VERSION=1.0.5
- PYTHON_VERSION=3.7
- VCS_REF=$VCS_REF
python3.6:
Expand All @@ -20,5 +32,6 @@ services:
args:
- BUILD_DATE=$BUILD_DATE
- PIPENV_VERSION=2018.11.26
- POETRY_VERSION=1.0.5
- PYTHON_VERSION=3.6
- VCS_REF=$VCS_REF
2 changes: 2 additions & 0 deletions config/poetry/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[virtualenvs]
in-project = true
25 changes: 23 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
#!/bin/bash

PROJECT_NAME=testsite
PIPENV_PROJECT_DIR=test_pipenv
POETRY_PROJECT_DIR=test_poetry

python --version
python3 --version
pip --version
pip3 --version
pipenv --version
poetry --version

# Create repository folders
mkdir -p "$PIPENV_PROJECT_DIR" "$POETRY_PROJECT_DIR"

# Pipenv test
cd "$PIPENV_PROJECT_DIR"

pipenv install django || exit 1
echo 'Creating test django project...'
echo 'Creating test django project with pipenv...'

pipenv run django-admin startproject "$PROJECT_NAME" || exit 1
echo 'Django project created.'
echo 'Django project created with pipenv.'

# Poetry test
cd "../$POETRY_PROJECT_DIR"

poetry init --no-interaction

poetry add Django || exit 1
echo 'Creating test django project using poetry...'

poetry run django-admin startproject "$PROJECT_NAME" || exit 1
echo 'Django project created with poetry.'