Skip to content

Commit 4910e0b

Browse files
committed
feat: multi-stage build without uv runtime dependency
1 parent c997750 commit 4910e0b

2 files changed

Lines changed: 39 additions & 19 deletions

File tree

Dockerfile

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
1-
FROM eclipse-temurin:21.0.9_10-jre-noble
1+
FROM ubuntu:noble AS builder
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt-get update \
6+
&& apt-get -y install --no-install-recommends \
7+
python3.12 \
8+
&& rm -rf /var/lib/apt/lists/*
29

3-
# install astral uv
410
COPY --from=ghcr.io/astral-sh/uv:0.10 /uv /usr/local/bin/
511

12+
WORKDIR /build
13+
14+
COPY pyproject.toml uv.lock ./
15+
16+
ENV UV_PYTHON=/usr/bin/python3.12 \
17+
UV_PYTHON_PREFERENCE=only-system \
18+
UV_LINK_MODE=copy \
19+
UV_PROJECT_ENVIRONMENT=/photon/.venv
20+
21+
RUN uv sync --locked --no-dev --no-install-project
22+
23+
24+
FROM eclipse-temurin:21.0.9_10-jre-noble
25+
626
ARG DEBIAN_FRONTEND=noninteractive
727
ARG PHOTON_VERSION
828
ARG PUID=9011
929
ARG PGID=9011
1030

1131
RUN apt-get update \
12-
&& apt-get -y install --no-install-recommends \
13-
lbzip2 \
14-
gosu \
15-
python3.12 \
16-
curl \
17-
&& rm -rf /var/lib/apt/lists/*
32+
&& apt-get -y install --no-install-recommends \
33+
lbzip2 \
34+
gosu \
35+
python3.12 \
36+
curl \
37+
&& rm -rf /var/lib/apt/lists/*
1838

1939
RUN groupadd -g ${PGID} -o photon && \
2040
useradd -l -u ${PUID} -g photon -o -s /bin/false -m -d /photon photon
@@ -27,24 +47,24 @@ ADD https://github.com/komoot/photon/releases/download/${PHOTON_VERSION}/photon-
2747

2848
COPY src/ ./src/
2949
COPY entrypoint.sh .
30-
COPY pyproject.toml .
31-
COPY uv.lock .
32-
RUN gosu photon uv sync --locked
50+
COPY --from=builder /photon/.venv /photon/.venv
3351

52+
ENV PATH="/photon/.venv/bin:${PATH}" \
53+
VIRTUAL_ENV=/photon/.venv
3454

3555
RUN chmod 644 /photon/photon.jar && \
3656
chown -R photon:photon /photon
3757

3858
LABEL org.opencontainers.image.title="photon-docker" \
39-
org.opencontainers.image.description="Unofficial docker image for the Photon Geocoder" \
40-
org.opencontainers.image.url="https://github.com/rtuszik/photon-docker" \
41-
org.opencontainers.image.source="https://github.com/rtuszik/photon-docker" \
42-
org.opencontainers.image.documentation="https://github.com/rtuszik/photon-docker#readme"
59+
org.opencontainers.image.description="Unofficial docker image for the Photon Geocoder" \
60+
org.opencontainers.image.url="https://github.com/rtuszik/photon-docker" \
61+
org.opencontainers.image.source="https://github.com/rtuszik/photon-docker" \
62+
org.opencontainers.image.documentation="https://github.com/rtuszik/photon-docker#readme"
4363

4464
EXPOSE 2322
4565

4666
HEALTHCHECK --interval=30s --timeout=10s --start-period=240s --retries=3 \
47-
CMD curl -f http://localhost:2322/status || exit 1
67+
CMD curl -f http://localhost:2322/status || exit 1
4868

4969
ENTRYPOINT ["/bin/sh", "entrypoint.sh"]
50-
CMD ["uv", "run", "-m", "src.process_manager"]
70+
CMD ["/photon/.venv/bin/python", "-m", "src.process_manager"]

src/process_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def handle_shutdown(self, signum, _frame):
7979

8080
def run_initial_setup(self):
8181
logger.info("Running initial setup...")
82-
result = subprocess.run(["uv", "run", "--no-sync", "-m", "src.entrypoint", "setup"], check=False, cwd="/photon") # noqa S603
82+
result = subprocess.run([sys.executable, "-m", "src.entrypoint", "setup"], check=False, cwd="/photon") # noqa S603
8383

8484
if result.returncode != 0:
8585
logger.error("Setup failed!")
@@ -218,7 +218,7 @@ def run_update(self):
218218
if config.UPDATE_STRATEGY == "SEQUENTIAL":
219219
self.stop_photon()
220220

221-
result = subprocess.run(["uv", "run", "--no-sync", "-m", "src.updater"], check=False, cwd="/photon") # noqa S603
221+
result = subprocess.run([sys.executable, "-m", "src.updater"], check=False, cwd="/photon") # noqa S603
222222

223223
if result.returncode == 0:
224224
logger.info("Update process completed, verifying Photon health...")

0 commit comments

Comments
 (0)