-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
61 lines (49 loc) · 1.45 KB
/
Dockerfile
File metadata and controls
61 lines (49 loc) · 1.45 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
# Backend build stage
FROM python:3.10-bullseye AS build1
SHELL ["/bin/bash", "-c"]
# Create venv
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Install only dependencies to prevent cache invalidation
WORKDIR /usr/src/app
ENV FLIT_ROOT_INSTALL=1
COPY requirements.txt .
COPY backend/pyproject.toml backend/
COPY backend/src/api/__init__.py backend/src/api/
RUN --mount=type=cache,target=/root/.cache \
pip install -U pip \
&& pip install wheel \
&& pip install flit \
&& flit -f backend/pyproject.toml install --only-deps \
&& pip install -r <(grep -v backend/. requirements.txt)
# Install backend module
COPY backend backend
RUN pip install backend/.
# Frontend build stage
FROM node:current-alpine AS build2
# Install only dependencies to prevent cache invalidation
WORKDIR /usr/src/app
COPY frontend/package.json frontend/package-lock.json ./
RUN --mount=type=cache,target=/root/.npm \
npm install
# Build static html files
COPY frontend .
RUN npm run build
# Web server execution
FROM python:3.10-bullseye AS run
# Copy python venv
ENV VIRTUAL_ENV=/opt/venv
COPY --from=build1 /opt/venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# Copy static html files
ENV STATIC_DIR=/srv/www
COPY --from=build2 /usr/src/app/dist $STATIC_DIR
# Enforce production environment
ENV API_ENV=production
# Expose port
EXPOSE 80
# Run web server
WORKDIR /app
COPY app.py .
ENTRYPOINT [ "uvicorn", "app:app"]
CMD ["--host", "0.0.0.0", "--port", "80"]