-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
58 lines (43 loc) · 1.37 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
49
50
51
52
53
54
55
56
57
58
# The configuration of the server within the container
ARG HOST=0.0.0.0
ARG PORT=3000
### STAGE 1: Build Frontend ###
FROM node:21 as frontend-builder
WORKDIR /app/frontend
# Install (and hopefully hit cached) node_modules
COPY frontend/package*.json ./
RUN npm ci
# Now copy over the source code and build it with Vite
# The static site files should be located at /app/frontend/dist in the container
COPY frontend .
RUN npm run build
### STAGE 2: Build Backend and Run ###
FROM python:3.12-slim
# Reexport args for this layer
ARG HOST
ARG PORT
WORKDIR /app/
COPY --from=frontend-builder /app/frontend/dist ./frontend/dist
# Install ffmpeg
RUN apt-get update
RUN apt-get install -y ffmpeg
# Install Python dependencies
COPY Pipfile Pipfile.lock .
RUN pip3 install pipenv
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy --ignore-pipfile
# Copy the source code
# TODO: will probably want this in a separate `src` directory, especially
# if more modules are added
COPY main.py .
# Set up uvicorn environment defined by ARGS
ENV UVICORN_HOST=${HOST}
ENV UVICORN_PORT=${PORT}
ENV PYTHON_ENV=production
# create a non root user, give it access to the application files, and switch to it
RUN groupadd -r nonroot
RUN useradd -r -g nonroot nonroot
RUN chown -R nonroot:nonroot /app
USER nonroot
EXPOSE $PORT
CMD ["pipenv", "run", "uvicorn", "main:app"]
# CMD ["tail", "-f", "/dev/null"]