Skip to content

Commit 2441091

Browse files
✨ Feature/implement poetry (#351)
* change requirments file * add script to build and test webapp using poetry * add webapp script and remove other python version * change permission of build_webapp * change permissions again * change permission again * enable tty mode * modify flow a bit * change base image * handle exit code better * add debug flag * Add curl for dev and can be useful for PRD * Reformat to avoid duplication, use build stage * Adapt to using build stage, rm explicit startapp * Add python standard ignores * Change directory and add install requirements * fix DEVFLAG argument * Switch to simple python docker image Co-authored-by: Ant <[email protected]>
1 parent cf8f3eb commit 2441091

File tree

9 files changed

+137
-181
lines changed

9 files changed

+137
-181
lines changed

.github/workflows/docker_image.yml

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,41 +31,19 @@ jobs:
3131
- name: Set env
3232
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
3333

34-
- name: Build image and push python 3.8 version to Docker Hub
35-
uses: docker/build-push-action@v2
36-
with:
37-
# relative path to the place where source code with Dockerfile is located
38-
context: .
39-
# Note: tags has to be all lower-case
40-
tags: |
41-
satel/python-base:${{env.RELEASE_VERSION}}-python3.8
42-
build-args: |
43-
IMAGE_VERSION=python:3.8.13-slim
44-
REQUIREMENTS_VERSION=3.8
45-
push: true
46-
47-
- name: Build image and push python 3.9 version to Docker Hub
48-
uses: docker/build-push-action@v2
49-
with:
50-
# relative path to the place where source code with Dockerfile is located
51-
context: .
52-
# Note: tags has to be all lower-case
53-
tags: |
54-
satel/python-base:${{env.RELEASE_VERSION}}-python3.9
55-
build-args: |
56-
IMAGE_VERSION=python:3.9.12-slim
57-
REQUIREMENTS_VERSION=3.9
58-
push: true
59-
6034
- name: Build image and push python 3.10 version to Docker Hub
6135
uses: docker/build-push-action@v2
6236
with:
6337
# relative path to the place where source code with Dockerfile is located
6438
context: .
6539
# Note: tags has to be all lower-case
6640
tags: |
67-
satel/python-base:${{env.RELEASE_VERSION}}-python3.10
41+
satel/python-base:${{env.RELEASE_VERSION}}
6842
build-args: |
6943
IMAGE_VERSION=python:3.10.4-slim
70-
REQUIREMENTS_VERSION=3.10
7144
push: true
45+
46+
- name: Build and test webapp with latest docker-python-base version
47+
working-directory: ./tests/
48+
run: ./build_webapp.sh
49+
shell: bash

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
ENV
2+
3+
# Byte-compiled / optimized / DLL files
4+
__pycache__/
5+
*.py[cod]
6+
*$py.class

Dockerfile

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
ARG IMAGE_VERSION=python:3.10.4-slim
22
FROM $IMAGE_VERSION
33

4-
ARG REQUIREMENTS_VERSION=3.10
5-
64
# Create user and home directory
75
# Create base directory
8-
RUN apt-get update && apt-get upgrade -y &&\
9-
useradd -u 1000 -ms /bin/bash -d /home/python python &&\
10-
mkdir -p /python && chown python:nogroup /python
6+
RUN apt-get update && apt-get upgrade -y \
7+
&& apt-get install -y curl \
8+
&& useradd -u 1000 -ms /bin/bash -d /home/python python \
9+
&& mkdir -p /python && chown python:nogroup /python
1110

11+
#RUN pip install uvicorn==0.17.6
1212
# Copy the needed files
1313
COPY entrypoint.sh test_suite.sh /python/
14-
COPY requirements_${REQUIREMENTS_VERSION}.txt /python/requirements.txt
1514

1615
ENTRYPOINT ["/python/entrypoint.sh"]
1716

1817
# Add convenient aliases
1918
# Install python packages
20-
RUN echo "#!/bin/bash\n/python/entrypoint.sh startapp" >> /bin/startapp && chmod a+x /bin/startapp &&\
21-
echo "#!/bin/bash\n/python/entrypoint.sh developapp" >> /bin/developapp && chmod a+x /bin/developapp &&\
22-
echo "#!/bin/bash\n/python/entrypoint.sh validatecode" >> /bin/validatecode && chmod a+x /bin/validatecode &&\
23-
echo "#!/bin/bash\n/python/entrypoint.sh validatecodeonce" >> /bin/validatecodeonce && chmod a+x /bin/validatecodeonce &&\
24-
echo "#!/bin/bash\n/python/entrypoint.sh runtests" >> /bin/runtests && chmod a+x /bin/runtests &&\
25-
pip install -r /python/requirements.txt
26-
19+
RUN echo "#!/bin/bash\n/python/entrypoint.sh startapp" >> /bin/startapp && chmod a+x /bin/startapp \
20+
&& echo "#!/bin/bash\n/python/entrypoint.sh developapp" >> /bin/developapp && chmod a+x /bin/developapp \
21+
&& echo "#!/bin/bash\n/python/entrypoint.sh validatecode" >> /bin/validatecode && chmod a+x /bin/validatecode \
22+
&& echo "#!/bin/bash\n/python/entrypoint.sh validatecodeonce" >> /bin/validatecodeonce && chmod a+x /bin/validatecodeonce \
23+
&& echo "#!/bin/bash\n/python/entrypoint.sh runtests" >> /bin/runtests && chmod a+x /bin/runtests
2724
# Change users
2825
USER python
2926

requirements_3.10.txt

Lines changed: 0 additions & 46 deletions
This file was deleted.

requirements_3.8.txt

Lines changed: 0 additions & 46 deletions
This file was deleted.

requirements_3.9.txt

Lines changed: 0 additions & 46 deletions
This file was deleted.

tests/Dockerfile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
FROM satel/python-base:latest
1+
ARG IMAGE_VERSION=satel/python-base:latest
2+
3+
# 1. Export the requirements file from poetry
4+
FROM python:3.10.5-slim AS requirements-stage
5+
6+
RUN pip install poetry
7+
COPY ./pyproject.toml ./poetry.lock* ./
8+
9+
# Generate the requirement file
10+
ARG DEVFLAG
11+
RUN poetry export -f requirements.txt --output /tmp/requirements.txt $DEVFLAG --without-hashes
12+
13+
# 2. Build the image we want using the requirements file from the first stage
14+
FROM $IMAGE_VERSION
215

316
# Copy the files for the server
17+
COPY --from=requirements-stage /tmp/requirements.txt /python/app/requirements.txt
18+
RUN pip install -r /python/app/requirements.txt
419
COPY ./ /python/app

tests/build_webapp.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
docker build --build-arg DEVFLAG=--dev -t webapp_dev .
4+
5+
docker build -t webapp_prd .
6+
7+
docker run webapp_dev validatecodeonce; STATUS1=$?
8+
9+
docker run -p 8000:8000 -d webapp_prd
10+
11+
sleep 5
12+
13+
curl -L http://localhost:8000/; STATUS2=$?
14+
15+
TOTAL=$((STATUS1 + STATUS2))
16+
exit $TOTAL

tests/pyproject.toml

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,86 @@
1+
[tool.poetry]
2+
name = "docker-python-base"
3+
version = "202206"
4+
description = "A library to facilitate base for Satel webapp's python backend"
5+
authors = ["Anthony Hillairet <[email protected]>"]
6+
maintainers = ["Anthony Hillairet <[email protected]>", "Rahul Patidar <[email protected]>"]
7+
license = "MIT"
8+
readme = "README.md"
9+
exclude = []
10+
classifiers = [ "License :: OSI Approved :: MIT License",]
11+
homepage = "https://satelcreative.github.io/docker-python-base"
12+
repository = "https://github.com/SatelCreative/docker-python-base"
13+
14+
15+
16+
[tool.poetry.dependencies]
17+
anyio = "3.5.0"
18+
argh = "0.26.2"
19+
asgiref ="3.5.1"
20+
attrs = "21.4.0"
21+
click = "8.1.3"
22+
colorama = "0.4.4"
23+
coverage = "6.3.2"
24+
fastapi = "0.75.2"
25+
h11 = "0.13.0"
26+
idna = "3.3"
27+
iniconfig= "1.1.1"
28+
isort = "5.10.1"
29+
loguru = "0.6.0"
30+
mccabe = "0.6.1"
31+
nest-asyncio = "1.5.5"
32+
packaging = "21.3"
33+
pathspec = "0.9.0"
34+
platformdirs = "2.5.2"
35+
pluggy = "1.0.0"
36+
py = "1.11.0"
37+
pycodestyle = "2.8.0"
38+
pydantic = "1.9.0"
39+
pyflakes = "2.4.0"
40+
pyparsing = "3.0.8"
41+
python = "^3.10"
42+
PyYAML = "6.0"
43+
sniffio = "1.2.0"
44+
starlette = "0.17.1"
45+
tabulate = "0.8.9"
46+
testfixtures = "6.18.5"
47+
toml = "0.10.2"
48+
tomli = "2.0.1"
49+
typing_extensions = "4.2.0"
50+
uvicorn = "0.17.6"
51+
watchdog = "2.1.7"
52+
53+
54+
[tool.poetry.dev-dependencies]
55+
black= "22.3.0"
56+
flake8 = "4.0.1"
57+
flake8-isort = "4.1.1"
58+
flake8-print= "5.0.0"
59+
flake8-quotes = "3.3.1"
60+
mypy = "0.950"
61+
mypy-extensions = "0.4.3"
62+
interrogate = "1.5.0"
63+
pytest= "7.1.2"
64+
pytest-asyncio= "0.18.3"
65+
pytest-cov= "3.0.0"
66+
pytest-mock= "3.7.0"
67+
68+
69+
70+
71+
[tool.isort]
72+
profile = "black"
73+
known_third_party = ["fastapi", "pydantic", "starlette"]
74+
75+
[tool.mypy]
76+
plugins = "pydantic.mypy"
77+
show_error_codes = true
78+
79+
# https://mypy.readthedocs.io/en/stable/config_file.html#using-a-pyproject-toml-file
80+
[[tool.mypy.overrides]]
81+
ignore_missing_imports = true
82+
module = []
83+
184
[tool.interrogate]
285
ignore-init-method = true
386
ignore-init-module = true
@@ -9,4 +92,4 @@ ignore-module = true
992
ignore-nested-functions = true
1093
ignore-nested-classes = true
1194
ignore-setters = true
12-
fail-under = 95
95+
fail-under = 95

0 commit comments

Comments
 (0)