-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
48 lines (35 loc) · 1.25 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
FROM python:3.12.3-alpine AS base
# set the working directory.
WORKDIR /app
# add image metadata.
LABEL maintainer="Mango Habanero <main@mango-habanero.dev>"
LABEL description="Base image for portfolio backend."
LABEL repository="https://github.com/PhilipWafula/mango-habanero-be"
LABEL homepage="https://mango-habanero.dev"
ARG SOURCE_COMMIT
LABEL revision=${SOURCE_COMMIT:-unknown}
# create a group and user.
RUN addgroup -S app && adduser -S app -G app
# set environment variables.
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
POETRY_VIRTUALENVS_CREATE=false \
PATH="/root/.local/bin:$PATH"
# install system dependencies.
RUN apk update && apk add --no-cache curl \
&& rm -rf /etc/apk/cache/*
# install poetry.
RUN curl -sSL https://install.python-poetry.org | python3 -
# copy dependecy files.
COPY pyproject.toml poetry.lock ./
# copy the project (done before install to ensure console scripts are available).
COPY ./src /app/src/
RUN poetry install --no-ansi --no-interaction --only main
# grant permissions.
RUN chown -R app:app /app
# switch to the app user.
USER app
# set the entrypoint.
EXPOSE 8000
# run the application.
CMD ["mhcli", "server", "start", "--interface", "asgi", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]