Base Python image that meets kubeyard requirements.
For more information, please read kubeyard documentation.
Create a Dockerfile in your kubeyard project:
FROM socialwifi/kubeyard-python
COPY requirements /requirements
RUN /usr/local/bin/install_requirements
COPY source /package
RUN pip install --no-deps --editable .
RUN mv *.egg-info $SITE_PACKAGES_DIR
CMD ["start_service"]If you want to leverage Docker cache mounts, you can use the following example:
# syntax=docker/dockerfile:1
FROM socialwifi/kubeyard-python
COPY requirements/apt.txt /requirements/
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
ENABLE_APT_CACHE="1" /usr/local/bin/install_apt_requirements
COPY requirements/python.txt /requirements/
RUN --mount=type=cache,target=/root/.cache/pip \
ENABLE_PIP_CACHE="1" /usr/local/bin/install_pip_requirements
COPY source /package
RUN pip install --no-deps --editable .
RUN mv *.egg-info $SITE_PACKAGES_DIR
CMD ["start_service"]More details about Docker cache mounts can be found here.
As can be seen in the above example, we are using some helper scripts and variables. The important ones are:
Variables:
SITE_PACKAGES_DIR- directory where all packages are installed (follows the Python version)
Scripts:
install_requirements- script that installs all requirements (Python ones withpipand system ones withapt) fromrequirementsdirectoryfreeze_requirements- script that generates therequirements.txtfilerun_tests- script that runs code analysis and tests
For static analysis we are using flake8 and isort.
We are using flake8 and isort separately due to code fixing -
When isort is trying to fix imports it uses only own config files, flake8 configs are omitted.
We are using pytest for running tests.
We are using pip-tools for freezing requirements - it gives much more readable output file with all dependencies listed.