1
- # == Build User Guide
1
+ # === STEP 1 === Build User Guide
2
2
3
- FROM python:3 .12 as guide_builder
3
+ FROM ghcr.io/astral-sh/uv:python3 .12-bookworm-slim AS guide_builder
4
4
5
5
RUN mkdir /guide
6
- WORKDIR /back/
7
- COPY back/docs /back/docs
8
- COPY back/guide_requirements.txt /back/guide_requirements.txt
9
- COPY back/mkdocs-guide.yml /back/mkdocs-guide.yml
10
- RUN pip install -r guide_requirements.txt
11
- RUN mkdocs build -f mkdocs-guide.yml -d /guide
12
6
13
- # == Build Front End
7
+ WORKDIR /guide
14
8
15
- FROM node:latest as web_builder
9
+ RUN --mount=type=cache,target=/root/.cache/uv \
10
+ --mount=type=bind,source=back/uv.lock,target=uv.lock \
11
+ --mount=type=bind,source=back/pyproject.toml,target=pyproject.toml \
12
+ uv sync --frozen --no-install-project --dev
13
+
14
+ COPY back/docs /guide/docs
15
+ COPY back/mkdocs-guide.yml /guide/mkdocs-guide.yml
16
+
17
+ RUN uv run mkdocs build -f mkdocs-guide.yml -d /guide/out/
18
+
19
+ # === STEP 2 === Build Front End
20
+
21
+ FROM node:latest AS frontend_builder
16
22
17
23
RUN mkdir /statics
18
24
19
- WORKDIR /front/
25
+ WORKDIR /front
20
26
21
- COPY front/ /front/
27
+ COPY front/ /front
22
28
23
29
RUN npm install
24
30
25
31
RUN npm run build
26
32
27
- # == Run the web server
33
+ # === STEP 3 === Build whombat
28
34
29
- FROM python:3.12
35
+ # Run the web server
36
+ # Use a Python image with uv pre-installed
37
+ FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
30
38
31
- WORKDIR back/
39
+ # Install the project into `/app`
40
+ WORKDIR /app
32
41
33
- # Install libsndfile1
34
- RUN apt-get update && apt-get install -y \
35
- libsndfile1 \
36
- build-essential \
37
- libffi-dev \
38
- python3-dev
42
+ # Enable bytecode compilation
43
+ ENV UV_COMPILE_BYTECODE=1
39
44
40
- # Set the working directory to /code
41
- WORKDIR /code
45
+ # Copy from the cache instead of linking since it's a mounted volume
46
+ ENV UV_LINK_MODE=copy
42
47
43
- # Copy the current directory contents into the container at /code
48
+ # Install the project's dependencies using the lockfile and settings
49
+ RUN --mount=type=cache,target=/root/.cache/uv \
50
+ --mount=type=bind,source=back/uv.lock,target=uv.lock \
51
+ --mount=type=bind,source=back/pyproject.toml,target=pyproject.toml \
52
+ uv sync --frozen --no-install-project --no-dev
53
+
54
+ # Then, add the rest of the project source code and install it
55
+ # Installing separately from its dependencies allows optimal layer caching
56
+ ADD back /app
44
57
45
58
# Copy the guide
46
- COPY --from=guide_builder /guide/ /code /src/whombat/user_guide/
59
+ COPY --from=guide_builder /guide/out/ /app /src/whombat/user_guide/
47
60
48
61
# Copy the statics
49
- COPY --from=web_builder /front/out/ /code/src/whombat/statics/
62
+ COPY --from=frontend_builder /front/out/ /app/src/whombat/statics/
63
+
64
+ RUN --mount=type=cache,target=/root/.cache/uv \
65
+ uv sync --frozen --no-dev
50
66
51
- # Install the Python dependencies
52
- COPY back/requirements.txt /code/requirements.txt
53
- RUN pip install -r requirements.txt
67
+ # === STEP 4 === Final Image
54
68
55
- # Copy the source code
56
- COPY back/src /code/src
57
- COPY back/app.py /code/app.py
58
- COPY back/pyproject.toml /code/pyproject.toml
59
- COPY back/alembic.ini /code/alembic.ini
60
- COPY back/README.md /code/README.md
61
- COPY back/LICENSE /code/LICENSE
69
+ # Then, use a final image without uv
70
+ FROM python:3.12-slim-bookworm
62
71
63
- # Install Whombat
64
- RUN pip install --no-deps .
72
+ # Copy the application from the builder
73
+ COPY --from=builder --chown=app:app /app /app
74
+
75
+ # Place executables in the environment at the front of the path
76
+ ENV PATH="/app/.venv/bin:$PATH"
65
77
66
78
# Create a directory for audio files
67
79
RUN mkdir /audio
@@ -84,5 +96,8 @@ ENV WHOMBAT_DOMAIN "localhost"
84
96
# Expose the port for the web server
85
97
EXPOSE 5000
86
98
99
+ # Reset the entrypoint, don't invoke `uv`
100
+ ENTRYPOINT []
101
+
87
102
# Run the command to start the web server
88
- CMD ["python" , "app.py " ]
103
+ CMD ["whombat " ]
0 commit comments