Skip to content
Open
Changes from all commits
Commits
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
30 changes: 17 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
FROM python:3.9.7-alpine3.13
FROM python:3.9.7-alpine3.13 AS builder

RUN apk add --no-cache \
curl \
# For building dependencies. \
gcc \
musl-dev \
git \
g++ \
libffi-dev \
# For psycopg \
postgresql-dev \
# For mysql deps \
mariadb-connector-c-dev

COPY pyproject.toml poetry.lock README.md /src/
COPY ./fastapi_template /src/fastapi_template/
WORKDIR /src

RUN python -m venv --copies /src/venv
RUN /src/venv/bin/pip install poetry==1.4.2
RUN --mount=type=cache,target=/root/.cache/pypoetry \
. /src/venv/bin/activate && poetry install --only main

FROM python:3.9.7-alpine3.13

RUN apk add --no-cache git ncurses
RUN adduser --disabled-password fastapi_template
RUN mkdir /projects /src
RUN chown -R fastapi_template:fastapi_template /projects /src
USER fastapi_template

COPY --from=builder /src/venv /src/venv/
COPY ./fastapi_template /src/fastapi_template/
WORKDIR /src

ENV PATH ${PATH}:/home/fastapi_template/.local/bin

RUN pip install poetry==1.4.2

COPY . /src/
RUN pip install .
ENV PATH ${PATH}:/src/venv/bin

USER root
RUN rm -rfv /src
RUN apk del curl
USER fastapi_template

VOLUME /projects
WORKDIR /projects

ENTRYPOINT ["/home/fastapi_template/.local/bin/fastapi_template"]
ENTRYPOINT ["/src/venv/bin/fastapi_template"]