Dockerfile.distroless 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. FROM golang:1.17-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/sftpgo /usr/local/bin/
  31. COPY --from=builder /etc/mime.types /etc/mime.types
  32. # Log to the stdout so the logs will be available using docker logs
  33. ENV SFTPGO_LOG_FILE_PATH=""
  34. # templates and static paths are inside the container
  35. ENV SFTPGO_HTTPD__TEMPLATES_PATH=/usr/share/sftpgo/templates
  36. ENV SFTPGO_HTTPD__STATIC_FILES_PATH=/usr/share/sftpgo/static
  37. # These env vars are required to avoid the following error when calling user.Current():
  38. # unable to get the current user: user: Current requires cgo or $USER set in environment
  39. ENV USER=sftpgo
  40. ENV HOME=/var/lib/sftpgo
  41. WORKDIR /var/lib/sftpgo
  42. USER 1000:1000
  43. CMD ["sftpgo", "serve"]