2023-12-09 02:03:58 +00:00
|
|
|
# syntax=docker/dockerfile:1
|
|
|
|
|
2021-12-24 22:25:38 +00:00
|
|
|
# Stage 1: Build website
|
2023-10-20 09:17:58 +00:00
|
|
|
FROM --platform=${BUILDPLATFORM} docker.io/node:21 as website-builder
|
2021-07-13 09:06:51 +00:00
|
|
|
|
2023-08-25 16:37:40 +00:00
|
|
|
ENV NODE_ENV=production
|
|
|
|
|
|
|
|
WORKDIR /work/website
|
|
|
|
|
2023-08-25 17:32:34 +00:00
|
|
|
RUN --mount=type=bind,target=/work/website/package.json,src=./website/package.json \
|
|
|
|
--mount=type=bind,target=/work/website/package-lock.json,src=./website/package-lock.json \
|
2023-12-09 02:03:58 +00:00
|
|
|
--mount=type=cache,id=npm-website,sharing=shared,target=/root/.npm \
|
2023-08-25 16:37:40 +00:00
|
|
|
npm ci --include=dev
|
|
|
|
|
2021-11-26 13:19:57 +00:00
|
|
|
COPY ./website /work/website/
|
2022-07-31 16:10:21 +00:00
|
|
|
COPY ./blueprints /work/blueprints/
|
2022-11-28 23:05:39 +00:00
|
|
|
COPY ./SECURITY.md /work/
|
2021-07-13 09:06:51 +00:00
|
|
|
|
2023-08-25 16:37:40 +00:00
|
|
|
RUN npm run build-docs-only
|
2021-07-13 09:06:51 +00:00
|
|
|
|
2021-12-24 22:25:38 +00:00
|
|
|
# Stage 2: Build webui
|
2023-10-20 09:17:58 +00:00
|
|
|
FROM --platform=${BUILDPLATFORM} docker.io/node:21 as web-builder
|
2021-05-02 22:49:16 +00:00
|
|
|
|
|
|
|
ENV NODE_ENV=production
|
2023-08-25 16:37:40 +00:00
|
|
|
|
2022-05-07 19:22:33 +00:00
|
|
|
WORKDIR /work/web
|
2021-05-02 22:49:16 +00:00
|
|
|
|
2023-08-25 17:32:34 +00:00
|
|
|
RUN --mount=type=bind,target=/work/web/package.json,src=./web/package.json \
|
|
|
|
--mount=type=bind,target=/work/web/package-lock.json,src=./web/package-lock.json \
|
2023-12-09 02:03:58 +00:00
|
|
|
--mount=type=cache,id=npm-web,sharing=shared,target=/root/.npm \
|
2023-08-25 16:37:40 +00:00
|
|
|
npm ci --include=dev
|
|
|
|
|
|
|
|
COPY ./web /work/web/
|
|
|
|
COPY ./website /work/website/
|
2023-09-12 11:06:32 +00:00
|
|
|
COPY ./gen-ts-api /work/web/node_modules/@goauthentik/api
|
2022-05-07 19:22:33 +00:00
|
|
|
|
2023-08-25 16:37:40 +00:00
|
|
|
RUN npm run build
|
2022-05-07 19:22:33 +00:00
|
|
|
|
2023-08-25 16:37:40 +00:00
|
|
|
# Stage 3: Build go proxy
|
2023-12-06 11:34:16 +00:00
|
|
|
FROM --platform=${BUILDPLATFORM} docker.io/golang:1.21.5-bookworm AS go-builder
|
2023-11-01 17:41:48 +00:00
|
|
|
|
|
|
|
ARG TARGETOS
|
|
|
|
ARG TARGETARCH
|
|
|
|
ARG TARGETVARIANT
|
|
|
|
|
|
|
|
ARG GOOS=$TARGETOS
|
|
|
|
ARG GOARCH=$TARGETARCH
|
2021-05-02 22:49:16 +00:00
|
|
|
|
2023-08-25 17:32:34 +00:00
|
|
|
WORKDIR /go/src/goauthentik.io
|
|
|
|
|
|
|
|
RUN --mount=type=bind,target=/go/src/goauthentik.io/go.mod,src=./go.mod \
|
|
|
|
--mount=type=bind,target=/go/src/goauthentik.io/go.sum,src=./go.sum \
|
|
|
|
--mount=type=cache,target=/go/pkg/mod \
|
|
|
|
go mod download
|
2021-05-02 22:49:16 +00:00
|
|
|
|
2023-08-25 17:32:34 +00:00
|
|
|
COPY ./cmd /go/src/goauthentik.io/cmd
|
|
|
|
COPY ./authentik/lib /go/src/goauthentik.io/authentik/lib
|
|
|
|
COPY ./web/static.go /go/src/goauthentik.io/web/static.go
|
2023-08-29 17:24:59 +00:00
|
|
|
COPY --from=web-builder /work/web/robots.txt /go/src/goauthentik.io/web/robots.txt
|
|
|
|
COPY --from=web-builder /work/web/security.txt /go/src/goauthentik.io/web/security.txt
|
2023-08-25 17:32:34 +00:00
|
|
|
COPY ./internal /go/src/goauthentik.io/internal
|
|
|
|
COPY ./go.mod /go/src/goauthentik.io/go.mod
|
|
|
|
COPY ./go.sum /go/src/goauthentik.io/go.sum
|
2021-05-02 22:49:16 +00:00
|
|
|
|
2023-08-25 17:32:34 +00:00
|
|
|
ENV CGO_ENABLED=0
|
2021-05-02 22:49:16 +00:00
|
|
|
|
2023-12-09 02:03:58 +00:00
|
|
|
RUN --mount=type=cache,sharing=locked,target=/go/pkg/mod \
|
|
|
|
--mount=type=cache,id=go-build-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/go-build \
|
2023-11-01 17:41:48 +00:00
|
|
|
GOARM="${TARGETVARIANT#v}" go build -o /go/authentik ./cmd/server
|
2021-05-02 22:49:16 +00:00
|
|
|
|
2023-08-25 16:37:40 +00:00
|
|
|
# Stage 4: MaxMind GeoIP
|
2023-11-01 17:41:48 +00:00
|
|
|
FROM --platform=${BUILDPLATFORM} ghcr.io/maxmind/geoipupdate:v6.0 as geoip
|
2022-12-20 21:09:30 +00:00
|
|
|
|
2023-12-20 21:16:50 +00:00
|
|
|
ENV GEOIPUPDATE_EDITION_IDS="GeoLite2-City GeoLite2-ASN"
|
2023-01-09 13:29:08 +00:00
|
|
|
ENV GEOIPUPDATE_VERBOSE="true"
|
2023-07-13 10:51:37 +00:00
|
|
|
ENV GEOIPUPDATE_ACCOUNT_ID_FILE="/run/secrets/GEOIPUPDATE_ACCOUNT_ID"
|
|
|
|
ENV GEOIPUPDATE_LICENSE_KEY_FILE="/run/secrets/GEOIPUPDATE_LICENSE_KEY"
|
2022-12-20 21:09:30 +00:00
|
|
|
|
2023-05-08 11:46:42 +00:00
|
|
|
USER root
|
2022-12-20 21:09:30 +00:00
|
|
|
RUN --mount=type=secret,id=GEOIPUPDATE_ACCOUNT_ID \
|
|
|
|
--mount=type=secret,id=GEOIPUPDATE_LICENSE_KEY \
|
|
|
|
mkdir -p /usr/share/GeoIP && \
|
2023-07-13 10:51:37 +00:00
|
|
|
/bin/sh -c "/usr/bin/entry.sh || echo 'Failed to get GeoIP database, disabling'; exit 0"
|
2022-12-20 21:09:30 +00:00
|
|
|
|
2023-08-25 16:37:40 +00:00
|
|
|
# Stage 5: Python dependencies
|
2023-12-11 04:44:19 +00:00
|
|
|
FROM docker.io/python:3.12.1-slim-bookworm AS python-deps
|
2023-08-25 16:37:40 +00:00
|
|
|
|
2023-09-12 08:22:45 +00:00
|
|
|
WORKDIR /ak-root/poetry
|
2023-08-25 16:37:40 +00:00
|
|
|
|
2023-09-12 08:22:45 +00:00
|
|
|
ENV VENV_PATH="/ak-root/venv" \
|
2023-08-25 19:44:31 +00:00
|
|
|
POETRY_VIRTUALENVS_CREATE=false \
|
2023-09-12 08:22:45 +00:00
|
|
|
PATH="/ak-root/venv/bin:$PATH"
|
2023-08-25 16:37:40 +00:00
|
|
|
|
2023-12-09 02:03:58 +00:00
|
|
|
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
|
|
|
|
|
|
|
|
RUN --mount=type=cache,id=apt-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/cache/apt \
|
2023-08-25 16:37:40 +00:00
|
|
|
apt-get update && \
|
|
|
|
# Required for installing pip packages
|
|
|
|
apt-get install -y --no-install-recommends build-essential pkg-config libxmlsec1-dev zlib1g-dev libpq-dev
|
|
|
|
|
|
|
|
RUN --mount=type=bind,target=./pyproject.toml,src=./pyproject.toml \
|
|
|
|
--mount=type=bind,target=./poetry.lock,src=./poetry.lock \
|
2023-08-25 19:44:31 +00:00
|
|
|
--mount=type=cache,target=/root/.cache/pip \
|
2023-08-25 16:37:40 +00:00
|
|
|
--mount=type=cache,target=/root/.cache/pypoetry \
|
2023-09-12 08:22:45 +00:00
|
|
|
python -m venv /ak-root/venv/ && \
|
2023-08-25 16:37:40 +00:00
|
|
|
pip3 install --upgrade pip && \
|
|
|
|
pip3 install poetry && \
|
2023-08-25 19:44:31 +00:00
|
|
|
poetry install --only=main --no-ansi --no-interaction
|
2023-08-25 16:37:40 +00:00
|
|
|
|
2022-12-20 21:09:30 +00:00
|
|
|
# Stage 6: Run
|
2023-12-11 04:44:19 +00:00
|
|
|
FROM docker.io/python:3.12.1-slim-bookworm AS final-image
|
2019-12-30 09:34:31 +00:00
|
|
|
|
2023-06-23 22:10:27 +00:00
|
|
|
ARG GIT_BUILD_HASH
|
|
|
|
ARG VERSION
|
|
|
|
ENV GIT_BUILD_HASH=$GIT_BUILD_HASH
|
|
|
|
|
2021-12-30 15:33:13 +00:00
|
|
|
LABEL org.opencontainers.image.url https://goauthentik.io
|
|
|
|
LABEL org.opencontainers.image.description goauthentik.io Main server image, see https://goauthentik.io for more info.
|
|
|
|
LABEL org.opencontainers.image.source https://github.com/goauthentik/authentik
|
2023-06-23 22:10:27 +00:00
|
|
|
LABEL org.opencontainers.image.version ${VERSION}
|
|
|
|
LABEL org.opencontainers.image.revision ${GIT_BUILD_HASH}
|
2021-12-30 15:33:13 +00:00
|
|
|
|
2023-09-11 20:01:20 +00:00
|
|
|
WORKDIR /ak-root
|
2019-12-30 09:34:31 +00:00
|
|
|
|
2023-08-25 16:37:40 +00:00
|
|
|
# We cannot cache this layer otherwise we'll end up with a bigger image
|
2019-12-30 09:34:31 +00:00
|
|
|
RUN apt-get update && \
|
2022-05-07 19:22:33 +00:00
|
|
|
# Required for runtime
|
2023-12-03 21:47:45 +00:00
|
|
|
apt-get install -y --no-install-recommends libpq5 openssl libxmlsec1-openssl libmaxminddb0 ca-certificates && \
|
2022-05-20 22:49:15 +00:00
|
|
|
# Required for bootstrap & healtcheck
|
2023-04-20 16:46:49 +00:00
|
|
|
apt-get install -y --no-install-recommends runit && \
|
2021-05-09 22:38:58 +00:00
|
|
|
apt-get clean && \
|
2023-08-25 16:37:40 +00:00
|
|
|
rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/ && \
|
2020-12-05 21:08:42 +00:00
|
|
|
adduser --system --no-create-home --uid 1000 --group --home /authentik authentik && \
|
2022-08-01 21:05:58 +00:00
|
|
|
mkdir -p /certs /media /blueprints && \
|
2021-12-25 18:18:47 +00:00
|
|
|
mkdir -p /authentik/.ssh && \
|
2023-09-11 12:22:41 +00:00
|
|
|
mkdir -p /ak-root && \
|
|
|
|
chown authentik:authentik /certs /media /authentik/.ssh /ak-root
|
2019-02-11 17:01:29 +00:00
|
|
|
|
2023-09-11 20:01:20 +00:00
|
|
|
COPY ./authentik/ /ak-root/authentik
|
|
|
|
COPY ./pyproject.toml /ak-root
|
|
|
|
COPY ./poetry.lock /ak-root
|
|
|
|
COPY ./schemas /ak-root/schemas
|
|
|
|
COPY ./locale /ak-root/locale
|
|
|
|
COPY ./tests /ak-root/tests
|
|
|
|
COPY ./manage.py /ak-root/
|
2022-08-07 17:27:03 +00:00
|
|
|
COPY ./blueprints /blueprints
|
2023-09-11 20:01:20 +00:00
|
|
|
COPY ./lifecycle/ /ak-root/lifecycle
|
2023-08-25 17:32:34 +00:00
|
|
|
COPY --from=go-builder /go/authentik /bin/authentik
|
2023-09-12 08:22:45 +00:00
|
|
|
COPY --from=python-deps /ak-root/venv /ak-root/venv
|
2023-09-11 20:01:20 +00:00
|
|
|
COPY --from=python-deps /work/venv /ak-root/venv
|
|
|
|
COPY --from=web-builder /work/web/dist/ /ak-root/web/dist/
|
|
|
|
COPY --from=web-builder /work/web/authentik/ /ak-root/web/authentik/
|
|
|
|
COPY --from=website-builder /work/website/help/ /ak-root/website/help/
|
|
|
|
COPY --from=geoip /usr/share/GeoIP /ak-root/geoip
|
2019-10-07 19:23:38 +00:00
|
|
|
|
2022-07-30 20:41:29 +00:00
|
|
|
USER 1000
|
2021-10-05 18:45:18 +00:00
|
|
|
|
2023-08-25 16:37:40 +00:00
|
|
|
ENV TMPDIR=/dev/shm/ \
|
|
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
|
|
PYTHONUNBUFFERED=1 \
|
2023-09-11 20:01:20 +00:00
|
|
|
PATH="/ak-root/venv/bin:/ak-root/lifecycle:$PATH" \
|
2023-09-11 12:22:41 +00:00
|
|
|
VENV_PATH="/ak-root/venv" \
|
2023-09-11 11:36:54 +00:00
|
|
|
POETRY_VIRTUALENVS_CREATE=false
|
2021-10-05 18:45:18 +00:00
|
|
|
|
2023-09-27 14:57:57 +00:00
|
|
|
HEALTHCHECK --interval=30s --timeout=30s --start-period=60s --retries=3 CMD [ "ak", "healthcheck" ]
|
2021-10-05 18:45:18 +00:00
|
|
|
|
2023-09-27 14:57:57 +00:00
|
|
|
ENTRYPOINT [ "dumb-init", "--", "ak" ]
|