Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
88 lines (68 loc) · 2.27 KB
/
Copy pathDockerfile
File metadata and controls
88 lines (68 loc) · 2.27 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
###########
# BUILDER #
###########
# pull official base image
FROM python:3.14-slim-bookworm AS builder
# install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# install system dependencies
RUN apt-get update \
&& apt-get -y install ca-certificates curl gnupg \
&& apt-get clean
# install node
ENV NODE_MAJOR=24
RUN mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
apt-get update && apt-get install nodejs -y
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# export production dependencies and install them
COPY pyproject.toml uv.lock ./
RUN uv export --no-hashes --no-dev > requirements.txt \
&& uv pip install --system --no-cache -r requirements.txt
# install Node.js dependencies
COPY package.json package-lock.json ./
RUN npm install
# build Tailwind
COPY . .
RUN npm run tailwind:build
#########
# FINAL #
#########
# pull official base image
FROM python:3.14-slim-bookworm
# install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# upgrade system packages
RUN apt-get update && apt-get upgrade -y && apt-get clean
# create directory for the app user
RUN mkdir -p /home/app
# create the app user
RUN addgroup --system app && adduser --system --group app
# create the appropriate directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
# set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV ENVIRONMENT=prod
ENV TESTING=0
ENV PYTHONPATH=$APP_HOME
# install dependencies
COPY --from=builder /usr/src/app/requirements.txt .
RUN uv pip install --system --no-cache -r requirements.txt
# copy project
COPY . $APP_HOME
COPY --from=builder /usr/src/app/party_app/static/css/output.css /home/app/web/party_app/static/css/output.css
# chown all the files to the app user
RUN chown -R app:app $HOME
# change to the app user
USER app
# serve the application
CMD exec fastapi run party_app/main.py --port $PORT --proxy-headers --forwarded-allow-ips="*"