From 055a24a8207065b92b517082fb986df142adcb60 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Tue, 9 Nov 2021 13:12:53 +0100 Subject: [PATCH] Add docker related files --- Dockerfile | 42 ++++++++++++++++++++++++++++++++++++++++++ docker-compose.yaml | 6 ++++++ 2 files changed, 48 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0c32edc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +## Build venv +FROM python:3.10.0-buster AS venv + +# https://python-poetry.org/docs/#installation +ENV POETRY_VERSION=1.1.11 +RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python - + +ENV PATH /root/.local/bin:$PATH + +ARG POETRY_OPTIONS + +WORKDIR /app + +COPY pyproject.toml poetry.lock ./ + +RUN python -m venv --copies /app/venv \ + && . /app/venv/bin/activate \ + && poetry install $POETRY_OPTIONS + + +## Get git versions +FROM alpine/git:v2.26.2 AS git +ADD . /app +WORKDIR /app +RUN git rev-parse HEAD | tee /version + + +## Beginning of runtime image +FROM python:3.10.0-slim-buster as final + +RUN echo "Europe/Paris" > /etc/timezone + +COPY --from=venv /app/venv /app/venv/ +ENV PATH /app/venv/bin:$PATH + +WORKDIR /app +COPY main.py pyproject.toml ./ +COPY --from=git /version /app/.version + +HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)" + +CMD ["uvicorn", "main:app"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..863a696 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,6 @@ +version: "2.4" + +services: + app: + build: . + restart: always