-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.python
More file actions
41 lines (36 loc) · 1.96 KB
/
Copy pathDockerfile.python
File metadata and controls
41 lines (36 loc) · 1.96 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
# Wrap-your-app template (Python) — drop this into your app repo as `Dockerfile`.
#
# EdgeGuard binds the platform-injected $PORT and proxies to your app on $APP_PORT.
# Your app must bind the port from its environment. The wrap command below tells
# uvicorn/gunicorn to listen on $APP_PORT (EdgeGuard also exports PORT=$APP_PORT for
# frameworks that read PORT directly).
# ---- 1. Obtain the EdgeGuard binary -----------------------------------------
# Option A (smallest image): copy the prebuilt binary from the released image.
# COPY --from=mancube/eggrd:latest /usr/local/bin/edgeguard /usr/local/bin/edgeguard
# Option B: install the published crate from crates.io (package `eggrd`, binary `edgeguard`).
FROM rust:1.94-slim AS edgeguard
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/*
RUN cargo install eggrd --root /out
# ---- 2. Build your app ------------------------------------------------------
FROM python:3.12-slim AS app
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# ---- 3. Final runtime image -------------------------------------------------
FROM python:3.12-slim
WORKDIR /app
RUN useradd -r -u 10001 appuser
# Wildcard the minor version so bumping the python:3.x base image doesn't break this path.
COPY --from=app /usr/local/lib/python3.*/site-packages /usr/local/lib/python3.*/site-packages
COPY --from=app /app /app
COPY --from=edgeguard /out/bin/edgeguard /usr/local/bin/edgeguard
# Place edgeguard.toml at your repo root before building (grab the template from
# EdgeGuard's edgeguard.toml at the repo root).
COPY edgeguard.toml /etc/edgeguard.toml
ENV APP_PORT=3000
USER appuser
# Replace the module path with your app. Note the shell-style $APP_PORT — the wrap
# command is run via `sh -c`, so env expansion works.
ENTRYPOINT ["edgeguard", "--config", "/etc/edgeguard.toml", "--wrap", "uvicorn app.main:app --host 127.0.0.1 --port $APP_PORT"]