Dockerfile 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. FROM golang:1.19-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 --abbrev=8 --dirty)} && \
  16. 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
  17. # Set to "true" to download the "official" plugins in /usr/local/bin
  18. ARG DOWNLOAD_PLUGINS=false
  19. RUN if [ "${DOWNLOAD_PLUGINS}" = "true" ]; then apt-get update && apt-get install --no-install-recommends -y curl && ./docker/scripts/download-plugins.sh; fi
  20. RUN apt-get update && apt-get install --no-install-recommends -y openssh-server && rm -rf /var/lib/apt/lists/*
  21. FROM debian:bullseye-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 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 /etc/ssh/moduli /etc/sftpgo/moduli
  33. COPY --from=builder /workspace/templates /usr/share/sftpgo/templates
  34. COPY --from=builder /workspace/static /usr/share/sftpgo/static
  35. COPY --from=builder /workspace/openapi /usr/share/sftpgo/openapi
  36. COPY --from=builder /workspace/sftpgo /usr/local/bin/sftpgo-plugin-* /usr/local/bin/
  37. # Log to the stdout so the logs will be available using docker logs
  38. ENV SFTPGO_LOG_FILE_PATH=""
  39. # Modify the default configuration file
  40. RUN sed -i 's|"users_base_dir": "",|"users_base_dir": "/srv/sftpgo/data",|' /etc/sftpgo/sftpgo.json && \
  41. sed -i 's|"backups"|"/srv/sftpgo/backups"|' /etc/sftpgo/sftpgo.json
  42. RUN chown -R sftpgo:sftpgo /etc/sftpgo /srv/sftpgo && chown sftpgo:sftpgo /var/lib/sftpgo && chmod 700 /srv/sftpgo/backups
  43. WORKDIR /var/lib/sftpgo
  44. USER 1000:1000
  45. CMD ["sftpgo", "serve"]