111 lines
5.4 KiB
Docker
111 lines
5.4 KiB
Docker
# This Source Code Form is subject to the terms of the Mozilla Public
|
||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||
#
|
||
# Ianitor Domi on Docker (T4): one image with both programs; deploy/docker/compose.yaml runs
|
||
# it twice (edge, and control in edge's network so the API stays on loopback).
|
||
#
|
||
# docker build -f deploy/docker/Dockerfile -t ianitor . the image
|
||
# docker build -f deploy/docker/Dockerfile --target ci -t ianitor-ci . Linux test runner
|
||
#
|
||
# Build context: the repository (see .dockerignore: no target/, node_modules/ or .git/).
|
||
|
||
ARG RUST=1.99-bookworm
|
||
ARG CADDY=2.11.7
|
||
ARG PEBBLE=v2.6.0
|
||
|
||
# ------------------------------------------------------------------ Rust toolchain + native deps
|
||
FROM rust:${RUST} AS rust
|
||
RUN apt-get update \
|
||
&& apt-get install -y --no-install-recommends cmake git ca-certificates \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
|
||
# ------------------------------------------------------------------ Caddy (the fallback, and the diff suite's other engine)
|
||
FROM debian:bookworm-slim AS caddy
|
||
ARG CADDY
|
||
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
WORKDIR /caddy
|
||
RUN curl -fsSLo caddy.tar.gz "https://github.com/caddyserver/caddy/releases/download/v${CADDY}/caddy_${CADDY}_linux_amd64.tar.gz" \
|
||
&& curl -fsSLo sums.txt "https://github.com/caddyserver/caddy/releases/download/v${CADDY}/caddy_${CADDY}_checksums.txt" \
|
||
&& grep " caddy_${CADDY}_linux_amd64.tar.gz\$" sums.txt | sed "s/caddy_${CADDY}_linux_amd64.tar.gz/caddy.tar.gz/" | sha512sum -c - \
|
||
&& tar -xzf caddy.tar.gz caddy && ./caddy version
|
||
|
||
# ------------------------------------------------------------------ the Linux test runner (layers 1–3 in CI)
|
||
FROM rust AS ci
|
||
ARG PEBBLE
|
||
RUN apt-get update && apt-get install -y --no-install-recommends curl unzip \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
COPY --from=caddy /caddy/caddy /usr/local/bin/caddy
|
||
RUN set -e; cd /tmp; for b in pebble pebble-challtestsrv; do \
|
||
curl -fsSLo "$b.tar.gz" "https://github.com/letsencrypt/pebble/releases/download/${PEBBLE}/$b-linux-amd64.tar.gz"; \
|
||
mkdir "$b.d"; tar -xzf "$b.tar.gz" -C "$b.d"; \
|
||
install -m 0755 "$(find "$b.d" -type f -name "$b" | head -n1)" "/usr/local/bin/$b"; \
|
||
done; rm -rf /tmp/*; pebble -version || true
|
||
ENV CARGO_TARGET_DIR=/target
|
||
WORKDIR /src
|
||
COPY . .
|
||
CMD ["cargo", "test", "--workspace", "--locked"]
|
||
|
||
# ------------------------------------------------------------------ release build
|
||
FROM rust AS build
|
||
# Two jobs: the default (every core) runs Docker Desktop out of memory on Pingora's crates.
|
||
ARG JOBS=2
|
||
ENV CARGO_BUILD_JOBS=${JOBS}
|
||
WORKDIR /src
|
||
COPY . .
|
||
RUN cargo build --release --locked -p ianitor-edge \
|
||
&& cargo build --release --locked -p ianitor-control --no-default-features \
|
||
&& strip target/release/ianitor-edge target/release/ianitor-control
|
||
|
||
FROM node:22-bookworm-slim AS web
|
||
RUN corepack enable
|
||
WORKDIR /src
|
||
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
||
COPY apps/web/package.json apps/web/package.json
|
||
COPY packages/ui/package.json packages/ui/package.json
|
||
RUN pnpm install --frozen-lockfile
|
||
COPY apps/web apps/web
|
||
COPY packages/ui packages/ui
|
||
RUN pnpm --filter web build
|
||
|
||
# ------------------------------------------------------------------ the Linux release files
|
||
# docker build -f deploy/docker/Dockerfile --target dist --output type=local,dest=target/dist .
|
||
FROM debian:bookworm-slim AS dist-files
|
||
WORKDIR /out
|
||
COPY --from=build /src/target/release/ianitor-edge /src/target/release/ianitor-control /tmp/bin/
|
||
COPY --from=web /src/apps/web/dist /tmp/web
|
||
COPY deploy/linux /tmp/linux
|
||
COPY Cargo.toml /tmp/Cargo.toml
|
||
RUN set -e; v=$(sed -n 's/^version = "\(.*\)"/\1/p' /tmp/Cargo.toml | head -n1); d="ianitor-$v"; \
|
||
mkdir -p "$d/bin" "$d/lib"; cp /tmp/bin/* "$d/bin/"; cp -r /tmp/web "$d/web"; \
|
||
cp /tmp/linux/setup.sh /tmp/linux/*.service "$d/lib/"; \
|
||
tar --owner=0 --group=0 --numeric-owner --sort=name --mtime=@0 -czf "ianitor-$v-linux-x86_64.tar.gz" "$d"; \
|
||
sed "s/__VERSION__/$v/" /tmp/linux/install.sh > install.sh; rm -rf "$d"
|
||
FROM scratch AS dist
|
||
COPY --from=dist-files /out/ /
|
||
|
||
# ------------------------------------------------------------------ the image
|
||
FROM debian:bookworm-slim
|
||
RUN apt-get update \
|
||
&& apt-get install -y --no-install-recommends git ca-certificates tini \
|
||
&& rm -rf /var/lib/apt/lists/* \
|
||
&& useradd --system --uid 10001 --home-dir /var/lib/ianitor --shell /usr/sbin/nologin ianitor \
|
||
&& mkdir -p /var/lib/ianitor /run/ianitor /usr/share/ianitor \
|
||
&& chown ianitor:ianitor /var/lib/ianitor /run/ianitor
|
||
COPY --from=build /src/target/release/ianitor-edge /src/target/release/ianitor-control /usr/local/bin/
|
||
COPY --from=web /src/apps/web/dist /usr/share/ianitor/web
|
||
COPY deploy/docker/entrypoint.sh /usr/local/bin/ianitor-entrypoint
|
||
COPY deploy/linux/setup.sh /usr/local/lib/ianitor/setup.sh
|
||
LABEL org.opencontainers.image.title="Ianitor Domi" \
|
||
org.opencontainers.image.description="Reverse proxy on Pingora with the Domi CA, a web UI and branch previews for Fabrica" \
|
||
org.opencontainers.image.licenses="MPL-2.0" \
|
||
org.opencontainers.image.source="https://gitea.marek-novak.cz/mnovak/Ianitor"
|
||
USER ianitor
|
||
VOLUME ["/var/lib/ianitor"]
|
||
# Docker lets an unprivileged user bind 80 and 443 inside the container
|
||
# (net.ipv4.ip_unprivileged_port_start = 0 by default since Docker 20.10).
|
||
EXPOSE 80 443
|
||
ENTRYPOINT ["tini", "--", "/usr/local/bin/ianitor-entrypoint"]
|
||
CMD ["edge"]
|