FROM golang:1.26-trixie@sha256:bdca99a00bc16590cb1a0bb4e698f5fc5d6a64e4d5eef13d9f18a0ee08e5fa65 AS builder
WORKDIR /workspace
ENV GOFLAGS=-mod=readonly GOMAXPROCS=4
COPY upstream/ ./
COPY sftpgo-pkce.patch /tmp/sftpgo-pkce.patch
RUN git apply --check /tmp/sftpgo-pkce.patch && git apply /tmp/sftpgo-pkce.patch
COPY pkce_flow_test.go internal/httpd/pkce_flow_test.go
COPY sftpgo-portal.patch /tmp/sftpgo-portal.patch
RUN git apply --check /tmp/sftpgo-portal.patch && git apply /tmp/sftpgo-portal.patch
COPY portal/*.go internal/httpd/
COPY portal/ui/ internal/httpd/portalassets/
RUN go mod download && go mod verify
RUN gofmt -w internal/httpd/oidc.go internal/httpd/pkce_flow_test.go internal/httpd/alpnexa_portal*.go && (cd tests/eventsearcher && go build -trimpath -o eventsearcher .)
# A separate ephemeral test filesystem keeps application reserve checks independent of shared build-cache occupancy.
RUN --mount=type=tmpfs,target=/tmp,size=12884901888 go test ./internal/httpd -run 'TestFiledrivePortal|TestFiledrivePublic|TestFiledriveShortlink|TestFiledrivePKCE|TestOIDCAuthRequestBoundToBrowser|TestOIDCLoginNextRedirect|TestMemoryOIDCManager|TestDbOIDCManager' -count=1 -timeout=180s -v
RUN go build -trimpath -ldflags '-s -w -X github.com/drakkan/sftpgo/v2/internal/version.commit=62ae9ba3-alpnexa-portal7 -X github.com/drakkan/sftpgo/v2/internal/version.date=2026-10-01T00:00:00Z' -o /out/sftpgo .
FROM ghcr.io/drakkan/sftpgo:v2.7.6@sha256:1edd28d80de2a008863fbfc58c8ff7db47b1b410bae48d4e6076192337809b11
COPY --from=builder /out/sftpgo /usr/local/bin/sftpgo
LABEL org.opencontainers.image.source="https://code.alpnexa.com/Alpnexa/filedrive" org.opencontainers.image.revision="62ae9ba3957e9ed52b44a4f885e805e2d7b35972+alpnexa-portal7"
