Dockerfile 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. FROM golang:1.22-bookworm as builder
  2. ENV GOFLAGS="-mod=readonly"
  3. RUN apt-get update && apt-get -y upgrade && rm -rf /var/lib/apt/lists/*
  4. RUN mkdir -p /workspace
  5. WORKDIR /workspace
  6. ARG GOPROXY
  7. COPY go.mod go.sum ./
  8. RUN go mod download
  9. ARG COMMIT_SHA
  10. # This ARG allows to disable some optional features and it might be useful if you build the image yourself.
  11. # For example you can disable S3 and GCS support like this:
  12. # --build-arg FEATURES=nos3,nogcs
  13. ARG FEATURES
  14. COPY . .
  15. RUN set -xe && \
  16. export COMMIT_SHA=${COMMIT_SHA:-$(git describe --always --abbrev=8 --dirty)} && \
  17. go build $(if [ -n "${FEATURES}" ]; then echo "-tags ${FEATURES}"; fi) -trimpath -ldflags "-s -w -X github.com/drakkan/sftpgo/v2/internal/version.commit=${COMMIT_SHA} -X github.com/drakkan/sftpgo/v2/internal/version.date=`date -u +%FT%TZ`" -v -o sftpgo
  18. # Set to "true" to download the "official" plugins in /usr/local/bin
  19. ARG DOWNLOAD_PLUGINS=false
  20. RUN if [ "${DOWNLOAD_PLUGINS}" = "true" ]; then apt-get update && apt-get install --no-install-recommends -y curl && ./docker/scripts/download-plugins.sh; fi
  21. FROM debian:bookworm-slim
  22. # Set to "true" to install jq and the optional git and rsync dependencies
  23. ARG INSTALL_OPTIONAL_PACKAGES=false
  24. RUN apt-get update && apt-get -y upgrade && apt-get install --no-install-recommends -y ca-certificates media-types && rm -rf /var/lib/apt/lists/*
  25. 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
  26. RUN mkdir -p /etc/sftpgo /var/lib/sftpgo /usr/share/sftpgo /srv/sftpgo/data /srv/sftpgo/backups
  27. RUN groupadd --system -g 1000 sftpgo && \
  28. useradd --system --gid sftpgo --no-create-home \
  29. --home-dir /var/lib/sftpgo --shell /usr/sbin/nologin \
  30. --comment "SFTPGo user" --uid 1000 sftpgo
  31. COPY --from=builder /workspace/sftpgo.json /etc/sftpgo/sftpgo.json
  32. COPY --from=builder /workspace/templates /usr/share/sftpgo/templates
  33. COPY --from=builder /workspace/static /usr/share/sftpgo/static
  34. COPY --from=builder /workspace/openapi /usr/share/sftpgo/openapi
  35. COPY --from=builder /workspace/sftpgo /usr/local/bin/sftpgo-plugin-* /usr/local/bin/
  36. # Log to the stdout so the logs will be available using docker logs
  37. ENV SFTPGO_LOG_FILE_PATH=""
  38. # Modify the default configuration file
  39. RUN sed -i 's|"users_base_dir": "",|"users_base_dir": "/srv/sftpgo/data",|' /etc/sftpgo/sftpgo.json && \
  40. sed -i 's|"backups"|"/srv/sftpgo/backups"|' /etc/sftpgo/sftpgo.json
  41. RUN chown -R sftpgo:sftpgo /etc/sftpgo /srv/sftpgo && chown sftpgo:sftpgo /var/lib/sftpgo && chmod 700 /srv/sftpgo/backups
  42. WORKDIR /var/lib/sftpgo
  43. USER 1000:1000
  44. CMD ["sftpgo", "serve"]