diff --git a/.github/workflows/docker_image.yml b/.github/workflows/docker_image.yml index 909f768..e25b803 100644 --- a/.github/workflows/docker_image.yml +++ b/.github/workflows/docker_image.yml @@ -31,32 +31,6 @@ 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: @@ -64,8 +38,12 @@ jobs: 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 diff --git a/.gitignore b/.gitignore index fffbb82..e128797 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ ENV + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class diff --git a/Dockerfile b/Dockerfile index f2c5120..6f72308 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/requirements_3.10.txt b/requirements_3.10.txt deleted file mode 100644 index 3bcea5d..0000000 --- a/requirements_3.10.txt +++ /dev/null @@ -1,46 +0,0 @@ -anyio==3.5.0 -argh==0.26.2 -asgiref==3.5.1 -attrs==21.4.0 -black==22.3.0 -click==8.1.3 -colorama==0.4.4 -coverage==6.3.2 -fastapi==0.75.2 -flake8==4.0.1 -flake8-isort==4.1.1 -flake8-print==5.0.0 -flake8-quotes==3.3.1 -h11==0.13.0 -idna==3.3 -iniconfig==1.1.1 -interrogate==1.5.0 -isort==5.10.1 -loguru==0.6.0 -mccabe==0.6.1 -mypy==0.950 -mypy-extensions==0.4.3 -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 -pytest==7.1.2 -pytest-asyncio==0.18.3 -pytest-cov==3.0.0 -pytest-mock==3.7.0 -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 diff --git a/requirements_3.8.txt b/requirements_3.8.txt deleted file mode 100644 index 3bcea5d..0000000 --- a/requirements_3.8.txt +++ /dev/null @@ -1,46 +0,0 @@ -anyio==3.5.0 -argh==0.26.2 -asgiref==3.5.1 -attrs==21.4.0 -black==22.3.0 -click==8.1.3 -colorama==0.4.4 -coverage==6.3.2 -fastapi==0.75.2 -flake8==4.0.1 -flake8-isort==4.1.1 -flake8-print==5.0.0 -flake8-quotes==3.3.1 -h11==0.13.0 -idna==3.3 -iniconfig==1.1.1 -interrogate==1.5.0 -isort==5.10.1 -loguru==0.6.0 -mccabe==0.6.1 -mypy==0.950 -mypy-extensions==0.4.3 -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 -pytest==7.1.2 -pytest-asyncio==0.18.3 -pytest-cov==3.0.0 -pytest-mock==3.7.0 -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 diff --git a/requirements_3.9.txt b/requirements_3.9.txt deleted file mode 100644 index 3bcea5d..0000000 --- a/requirements_3.9.txt +++ /dev/null @@ -1,46 +0,0 @@ -anyio==3.5.0 -argh==0.26.2 -asgiref==3.5.1 -attrs==21.4.0 -black==22.3.0 -click==8.1.3 -colorama==0.4.4 -coverage==6.3.2 -fastapi==0.75.2 -flake8==4.0.1 -flake8-isort==4.1.1 -flake8-print==5.0.0 -flake8-quotes==3.3.1 -h11==0.13.0 -idna==3.3 -iniconfig==1.1.1 -interrogate==1.5.0 -isort==5.10.1 -loguru==0.6.0 -mccabe==0.6.1 -mypy==0.950 -mypy-extensions==0.4.3 -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 -pytest==7.1.2 -pytest-asyncio==0.18.3 -pytest-cov==3.0.0 -pytest-mock==3.7.0 -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 diff --git a/tests/Dockerfile b/tests/Dockerfile index 37986a0..266fa8b 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -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 diff --git a/tests/build_webapp.sh b/tests/build_webapp.sh new file mode 100755 index 0000000..b62f47c --- /dev/null +++ b/tests/build_webapp.sh @@ -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 diff --git a/tests/pyproject.toml b/tests/pyproject.toml index 9f61a50..ff1e170 100644 --- a/tests/pyproject.toml +++ b/tests/pyproject.toml @@ -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 "] +maintainers = ["Anthony Hillairet ", "Rahul Patidar "] +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 @@ -9,4 +92,4 @@ ignore-module = true ignore-nested-functions = true ignore-nested-classes = true ignore-setters = true -fail-under = 95 +fail-under = 95 \ No newline at end of file