Dockerfile.alpine 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. FROM golang:1.19-alpine3.16 AS builder
  2. ENV GOFLAGS="-mod=readonly"
  3. RUN apk add --update --no-cache bash ca-certificates curl git gcc g++
  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. RUN apk add --update --no-cache openssh-client-common
  19. FROM alpine:3.16
  20. # Set to "true" to install jq and the optional git and rsync dependencies
  21. ARG INSTALL_OPTIONAL_PACKAGES=false
  22. RUN apk add --update --no-cache ca-certificates tzdata mailcap
  23. RUN if [ "${INSTALL_OPTIONAL_PACKAGES}" = "true" ]; then apk add --update --no-cache jq git rsync; fi
  24. RUN mkdir -p /etc/sftpgo /var/lib/sftpgo /usr/share/sftpgo /srv/sftpgo/data /srv/sftpgo/backups
  25. RUN addgroup -g 1000 -S sftpgo && \
  26. adduser -u 1000 -h /var/lib/sftpgo -s /sbin/nologin -G sftpgo -S -D -H -g "SFTPGo user" sftpgo
  27. COPY --from=builder /workspace/sftpgo.json /etc/sftpgo/sftpgo.json
  28. COPY --from=builder /etc/ssh/moduli /etc/sftpgo/moduli
  29. COPY --from=builder /workspace/templates /usr/share/sftpgo/templates
  30. COPY --from=builder /workspace/static /usr/share/sftpgo/static
  31. COPY --from=builder /workspace/openapi /usr/share/sftpgo/openapi
  32. COPY --from=builder /workspace/sftpgo /usr/local/bin/
  33. # Log to the stdout so the logs will be available using docker logs
  34. ENV SFTPGO_LOG_FILE_PATH=""
  35. # Modify the default configuration file
  36. RUN sed -i 's|"users_base_dir": "",|"users_base_dir": "/srv/sftpgo/data",|' /etc/sftpgo/sftpgo.json && \
  37. sed -i 's|"backups"|"/srv/sftpgo/backups"|' /etc/sftpgo/sftpgo.json
  38. RUN chown -R sftpgo:sftpgo /etc/sftpgo /srv/sftpgo && chown sftpgo:sftpgo /var/lib/sftpgo && chmod 700 /srv/sftpgo/backups
  39. WORKDIR /var/lib/sftpgo
  40. USER 1000:1000
  41. CMD ["sftpgo", "serve"]