Dockerfile 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. FROM golang:1.18-bullseye as builder
  2. ENV 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 example you can disable S3 and GCS support like this:
  11. # --build-arg FEATURES=nos3,nogcs
  12. ARG FEATURES
  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. FROM debian:bullseye-slim
  18. # Set to "true" to install jq and the optional git and rsync dependencies
  19. ARG INSTALL_OPTIONAL_PACKAGES=false
  20. RUN apt-get update && apt-get install --no-install-recommends -y ca-certificates media-types && rm -rf /var/lib/apt/lists/*
  21. RUN if [ "${INSTALL_OPTIONAL_PACKAGES}" = "true" ]; then apt-get update && apt-get install --no-install-recommends -y jq git rsync && rm -rf /var/lib/apt/lists/*; fi
  22. RUN mkdir -p /etc/sftpgo /var/lib/sftpgo /usr/share/sftpgo /srv/sftpgo/data /srv/sftpgo/backups
  23. RUN groupadd --system -g 1000 sftpgo && \
  24. useradd --system --gid sftpgo --no-create-home \
  25. --home-dir /var/lib/sftpgo --shell /usr/sbin/nologin \
  26. --comment "SFTPGo user" --uid 1000 sftpgo
  27. COPY --from=builder /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. # Log to the stdout so the logs will be available using docker logs
  33. ENV SFTPGO_LOG_FILE_PATH=""
  34. # Modify the default configuration file
  35. RUN sed -i 's|"users_base_dir": "",|"users_base_dir": "/srv/sftpgo/data",|' /etc/sftpgo/sftpgo.json && \
  36. sed -i 's|"backups"|"/srv/sftpgo/backups"|' /etc/sftpgo/sftpgo.json
  37. RUN chown -R sftpgo:sftpgo /etc/sftpgo /srv/sftpgo && chown sftpgo:sftpgo /var/lib/sftpgo && chmod 700 /srv/sftpgo/backups
  38. WORKDIR /var/lib/sftpgo
  39. USER 1000:1000
  40. CMD ["sftpgo", "serve"]