Dockerfile.distroless 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. FROM golang:1.18-bullseye as builder
  2. ENV CGO_ENABLED=0 GOFLAGS="-mod=readonly"
  3. RUN mkdir -p /workspace
  4. WORKDIR /workspace
  5. ARG GOPROXY
  6. COPY go.mod go.sum ./
  7. RUN go mod download
  8. ARG COMMIT_SHA
  9. # This ARG allows to disable some optional features and it might be useful if you build the image yourself.
  10. # For this variant we disable SQLite support since it requires CGO and so a C runtime which is not installed
  11. # in distroless/static-* images
  12. ARG FEATURES=nosqlite
  13. COPY . .
  14. RUN set -xe && \
  15. export COMMIT_SHA=${COMMIT_SHA:-$(git describe --always --dirty)} && \
  16. go build $(if [ -n "${FEATURES}" ]; then echo "-tags ${FEATURES}"; fi) -trimpath -ldflags "-s -w -X github.com/drakkan/sftpgo/v2/version.commit=${COMMIT_SHA} -X github.com/drakkan/sftpgo/v2/version.date=`date -u +%FT%TZ`" -v -o sftpgo
  17. # Modify the default configuration file
  18. RUN sed -i 's|"users_base_dir": "",|"users_base_dir": "/srv/sftpgo/data",|' sftpgo.json && \
  19. sed -i 's|"backups"|"/srv/sftpgo/backups"|' sftpgo.json && \
  20. sed -i 's|"sqlite"|"bolt"|' sftpgo.json
  21. RUN apt-get update && apt-get install --no-install-recommends -y media-types && rm -rf /var/lib/apt/lists/*
  22. RUN mkdir /etc/sftpgo /var/lib/sftpgo /srv/sftpgo
  23. FROM gcr.io/distroless/static-debian11
  24. COPY --from=builder --chown=1000:1000 /etc/sftpgo /etc/sftpgo
  25. COPY --from=builder --chown=1000:1000 /srv/sftpgo /srv/sftpgo
  26. COPY --from=builder --chown=1000:1000 /var/lib/sftpgo /var/lib/sftpgo
  27. COPY --from=builder --chown=1000:1000 /workspace/sftpgo.json /etc/sftpgo/sftpgo.json
  28. COPY --from=builder /workspace/templates /usr/share/sftpgo/templates
  29. COPY --from=builder /workspace/static /usr/share/sftpgo/static
  30. COPY --from=builder /workspace/openapi /usr/share/sftpgo/openapi
  31. COPY --from=builder /workspace/sftpgo /usr/local/bin/
  32. COPY --from=builder /etc/mime.types /etc/mime.types
  33. # Log to the stdout so the logs will be available using docker logs
  34. ENV SFTPGO_LOG_FILE_PATH=""
  35. # These env vars are required to avoid the following error when calling user.Current():
  36. # unable to get the current user: user: Current requires cgo or $USER set in environment
  37. ENV USER=sftpgo
  38. ENV HOME=/var/lib/sftpgo
  39. WORKDIR /var/lib/sftpgo
  40. USER 1000:1000
  41. CMD ["sftpgo", "serve"]