Skip to content

Fixes ncurses problem and reduces image size. #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
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"]