1
0

Dockerfile.alpine 2.2 KB

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