| 1 |
# MIT License |
| 2 |
|
| 3 |
# Copyright (c) 2020 Michael Oliver |
| 4 |
|
| 5 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 |
# of this software and associated documentation files (the "Software"), to deal |
| 7 |
# in the Software without restriction, including without limitation the rights |
| 8 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
# copies of the Software, and to permit persons to whom the Software is |
| 10 |
# furnished to do so, subject to the following conditions: |
| 11 |
|
| 12 |
# The above copyright notice and this permission notice shall be included in all |
| 13 |
# copies or substantial portions of the Software. |
| 14 |
|
| 15 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 |
# SOFTWARE. |
| 22 |
|
| 23 |
## ----------------------------------------------------------------------------- |
| 24 |
## Base image with VENV |
| 25 |
|
| 26 |
# The following code was based on |
| 27 |
# https://github.com/michaeloliverx/python-poetry-docker-example/blob/master/docker/Dockerfile |
| 28 |
|
| 29 |
FROM python:3.8-slim as python-base |
| 30 |
|
| 31 |
# Configure environment |
| 32 |
|
| 33 |
ENV PYTHONUNBUFFERED=1 \ |
| 34 |
PYTHONFAULTHANDLER=1 \ |
| 35 |
PYTHONDONTWRITEBYTECODE=1 \ |
| 36 |
PIP_NO_CACHE_DIR=off \ |
| 37 |
PIP_DISABLE_PIP_VERSION_CHECK=on \ |
| 38 |
PIP_DEFAULT_TIMEOUT=100 \ |
| 39 |
POETRY_HOME="/opt/poetry" \ |
| 40 |
POETRY_VIRTUALENVS_IN_PROJECT=true \ |
| 41 |
POETRY_NO_INTERACTION=1 \ |
| 42 |
PYSETUP_PATH="/baler-root/baler" \ |
| 43 |
VENV_PATH="/baler-root/baler/.venv" |
| 44 |
|
| 45 |
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH" |
| 46 |
|
| 47 |
# System deps: |
| 48 |
RUN pip install "poetry" |
| 49 |
|
| 50 |
# Copy only requirements to cache them in docker layer |
| 51 |
WORKDIR $PYSETUP_PATH |
| 52 |
COPY ./poetry.lock ./pyproject.toml ./ |
| 53 |
|
| 54 |
# Project initialization: |
| 55 |
RUN poetry remove torch && \ |
| 56 |
poetry install --no-interaction --no-ansi |
| 57 |
|
| 58 |
# Creating folders, and files for the project: |
| 59 |
COPY ./baler/ README.md ./tests/ ./ |
| 60 |
|
| 61 |
# Creating python wheel |
| 62 |
RUN poetry build |
| 63 |
|
| 64 |
## ----------------------------------------------------------------------------- |
| 65 |
## Baler layer |
| 66 |
|
| 67 |
FROM python:3.8-slim |
| 68 |
|
| 69 |
# Copy virtual environment |
| 70 |
WORKDIR /baler-root/baler |
| 71 |
COPY --from=python-base /baler-root/baler/dist/*.whl ./ |
| 72 |
|
| 73 |
# Install wheel |
| 74 |
RUN pip install *.whl && \ |
| 75 |
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu |
| 76 |
|
| 77 |
# Copy source |
| 78 |
COPY --from=python-base /baler-root/baler/modules/ ./modules |
| 79 |
COPY --from=python-base /baler-root/baler/*.py /baler-root/baler/README.md ./ |
| 80 |
|
| 81 |
# Configure run time |
| 82 |
ENV PYTHONUNBUFFERED=1 |
| 83 |
WORKDIR /baler-root/ |
| 84 |
|
| 85 |
# Install fixuid |
| 86 |
COPY fixuid.sh fixuid.sh |
| 87 |
RUN ["./fixuid.sh"] |
| 88 |
|
| 89 |
COPY entrypoint.sh entrypoint.sh |
| 90 |
ENTRYPOINT ["./entrypoint.sh"] |