Skip to content

✨ Feature/implement poetry #351

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

Merged
merged 21 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 6 additions & 28 deletions .github/workflows/docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,19 @@ jobs:
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Build image and push python 3.8 version to Docker Hub
uses: docker/build-push-action@v2
with:
# relative path to the place where source code with Dockerfile is located
context: .
# Note: tags has to be all lower-case
tags: |
satel/python-base:${{env.RELEASE_VERSION}}-python3.8
build-args: |
IMAGE_VERSION=python:3.8.13-slim
REQUIREMENTS_VERSION=3.8
push: true

- name: Build image and push python 3.9 version to Docker Hub
uses: docker/build-push-action@v2
with:
# relative path to the place where source code with Dockerfile is located
context: .
# Note: tags has to be all lower-case
tags: |
satel/python-base:${{env.RELEASE_VERSION}}-python3.9
build-args: |
IMAGE_VERSION=python:3.9.12-slim
REQUIREMENTS_VERSION=3.9
push: true

- name: Build image and push python 3.10 version to Docker Hub
uses: docker/build-push-action@v2
with:
# relative path to the place where source code with Dockerfile is located
context: .
# Note: tags has to be all lower-case
tags: |
satel/python-base:${{env.RELEASE_VERSION}}-python3.10
satel/python-base:${{env.RELEASE_VERSION}}
build-args: |
IMAGE_VERSION=python:3.10.4-slim
REQUIREMENTS_VERSION=3.10
push: true

- name: Build and test webapp with latest docker-python-base version
working-directory: ./tests/
run: ./build_webapp.sh
shell: bash
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
ENV

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
23 changes: 10 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
ARG IMAGE_VERSION=python:3.10.4-slim
FROM $IMAGE_VERSION

ARG REQUIREMENTS_VERSION=3.10

# Create user and home directory
# Create base directory
RUN apt-get update && apt-get upgrade -y &&\
useradd -u 1000 -ms /bin/bash -d /home/python python &&\
mkdir -p /python && chown python:nogroup /python
RUN apt-get update && apt-get upgrade -y \
&& apt-get install -y curl \
&& useradd -u 1000 -ms /bin/bash -d /home/python python \
&& mkdir -p /python && chown python:nogroup /python

#RUN pip install uvicorn==0.17.6
# Copy the needed files
COPY entrypoint.sh test_suite.sh /python/
COPY requirements_${REQUIREMENTS_VERSION}.txt /python/requirements.txt

ENTRYPOINT ["/python/entrypoint.sh"]

# Add convenient aliases
# Install python packages
RUN echo "#!/bin/bash\n/python/entrypoint.sh startapp" >> /bin/startapp && chmod a+x /bin/startapp &&\
echo "#!/bin/bash\n/python/entrypoint.sh developapp" >> /bin/developapp && chmod a+x /bin/developapp &&\
echo "#!/bin/bash\n/python/entrypoint.sh validatecode" >> /bin/validatecode && chmod a+x /bin/validatecode &&\
echo "#!/bin/bash\n/python/entrypoint.sh validatecodeonce" >> /bin/validatecodeonce && chmod a+x /bin/validatecodeonce &&\
echo "#!/bin/bash\n/python/entrypoint.sh runtests" >> /bin/runtests && chmod a+x /bin/runtests &&\
pip install -r /python/requirements.txt

RUN echo "#!/bin/bash\n/python/entrypoint.sh startapp" >> /bin/startapp && chmod a+x /bin/startapp \
&& echo "#!/bin/bash\n/python/entrypoint.sh developapp" >> /bin/developapp && chmod a+x /bin/developapp \
&& echo "#!/bin/bash\n/python/entrypoint.sh validatecode" >> /bin/validatecode && chmod a+x /bin/validatecode \
&& echo "#!/bin/bash\n/python/entrypoint.sh validatecodeonce" >> /bin/validatecodeonce && chmod a+x /bin/validatecodeonce \
&& echo "#!/bin/bash\n/python/entrypoint.sh runtests" >> /bin/runtests && chmod a+x /bin/runtests
# Change users
USER python

Expand Down
46 changes: 0 additions & 46 deletions requirements_3.10.txt

This file was deleted.

46 changes: 0 additions & 46 deletions requirements_3.8.txt

This file was deleted.

46 changes: 0 additions & 46 deletions requirements_3.9.txt

This file was deleted.

17 changes: 16 additions & 1 deletion tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
FROM satel/python-base:latest
ARG IMAGE_VERSION=satel/python-base:latest

# 1. Export the requirements file from poetry
FROM python:3.10.5-slim AS requirements-stage

RUN pip install poetry
COPY ./pyproject.toml ./poetry.lock* ./

# Generate the requirement file
ARG DEVFLAG
RUN poetry export -f requirements.txt --output /tmp/requirements.txt $DEVFLAG --without-hashes

# 2. Build the image we want using the requirements file from the first stage
FROM $IMAGE_VERSION

# Copy the files for the server
COPY --from=requirements-stage /tmp/requirements.txt /python/app/requirements.txt
RUN pip install -r /python/app/requirements.txt
COPY ./ /python/app
16 changes: 16 additions & 0 deletions tests/build_webapp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

docker build --build-arg DEVFLAG=--dev -t webapp_dev .

docker build -t webapp_prd .

docker run webapp_dev validatecodeonce; STATUS1=$?

docker run -p 8000:8000 -d webapp_prd

sleep 5

curl -L http://localhost:8000/; STATUS2=$?

TOTAL=$((STATUS1 + STATUS2))
exit $TOTAL
85 changes: 84 additions & 1 deletion tests/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,86 @@
[tool.poetry]
name = "docker-python-base"
version = "202206"
description = "A library to facilitate base for Satel webapp's python backend"
authors = ["Anthony Hillairet <[email protected]>"]
maintainers = ["Anthony Hillairet <[email protected]>", "Rahul Patidar <[email protected]>"]
license = "MIT"
readme = "README.md"
exclude = []
classifiers = [ "License :: OSI Approved :: MIT License",]
homepage = "https://satelcreative.github.io/docker-python-base"
repository = "https://github.com/SatelCreative/docker-python-base"



[tool.poetry.dependencies]
anyio = "3.5.0"
argh = "0.26.2"
asgiref ="3.5.1"
attrs = "21.4.0"
click = "8.1.3"
colorama = "0.4.4"
coverage = "6.3.2"
fastapi = "0.75.2"
h11 = "0.13.0"
idna = "3.3"
iniconfig= "1.1.1"
isort = "5.10.1"
loguru = "0.6.0"
mccabe = "0.6.1"
nest-asyncio = "1.5.5"
packaging = "21.3"
pathspec = "0.9.0"
platformdirs = "2.5.2"
pluggy = "1.0.0"
py = "1.11.0"
pycodestyle = "2.8.0"
pydantic = "1.9.0"
pyflakes = "2.4.0"
pyparsing = "3.0.8"
python = "^3.10"
PyYAML = "6.0"
sniffio = "1.2.0"
starlette = "0.17.1"
tabulate = "0.8.9"
testfixtures = "6.18.5"
toml = "0.10.2"
tomli = "2.0.1"
typing_extensions = "4.2.0"
uvicorn = "0.17.6"
watchdog = "2.1.7"


[tool.poetry.dev-dependencies]
black= "22.3.0"
flake8 = "4.0.1"
flake8-isort = "4.1.1"
flake8-print= "5.0.0"
flake8-quotes = "3.3.1"
mypy = "0.950"
mypy-extensions = "0.4.3"
interrogate = "1.5.0"
pytest= "7.1.2"
pytest-asyncio= "0.18.3"
pytest-cov= "3.0.0"
pytest-mock= "3.7.0"




[tool.isort]
profile = "black"
known_third_party = ["fastapi", "pydantic", "starlette"]

[tool.mypy]
plugins = "pydantic.mypy"
show_error_codes = true

# https://mypy.readthedocs.io/en/stable/config_file.html#using-a-pyproject-toml-file
[[tool.mypy.overrides]]
ignore_missing_imports = true
module = []

[tool.interrogate]
ignore-init-method = true
ignore-init-module = true
Expand All @@ -9,4 +92,4 @@ ignore-module = true
ignore-nested-functions = true
ignore-nested-classes = true
ignore-setters = true
fail-under = 95
fail-under = 95