Dockerfile.alpine 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. FROM golang:1.18-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 --dirty)} && \
  17. 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
  18. FROM alpine:3.16
  19. # Set to "true" to install jq and the optional git and rsync dependencies
  20. ARG INSTALL_OPTIONAL_PACKAGES=false
  21. RUN 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. # set up nsswitch.conf for Go's "netgo" implementation
  24. # https://github.com/gliderlabs/docker-alpine/issues/367#issuecomment-424546457
  25. RUN test ! -e /etc/nsswitch.conf && echo 'hosts: files dns' > /etc/nsswitch.conf
  26. RUN mkdir -p /etc/sftpgo /var/lib/sftpgo /usr/share/sftpgo /srv/sftpgo/data /srv/sftpgo/backups
  27. RUN addgroup -g 1000 -S sftpgo && \
  28. adduser -u 1000 -h /var/lib/sftpgo -s /sbin/nologin -G sftpgo -S -D -H -g "SFTPGo user" sftpgo
  29. COPY --from=builder /workspace/sftpgo.json /etc/sftpgo/sftpgo.json
  30. COPY --from=builder /workspace/templates /usr/share/sftpgo/templates
  31. COPY --from=builder /workspace/static /usr/share/sftpgo/static
  32. COPY --from=builder /workspace/openapi /usr/share/sftpgo/openapi
  33. COPY --from=builder /workspace/sftpgo /usr/local/bin/
  34. # Log to the stdout so the logs will be available using docker logs
  35. ENV SFTPGO_LOG_FILE_PATH=""
  36. # Modify the default configuration file
  37. RUN sed -i 's|"users_base_dir": "",|"users_base_dir": "/srv/sftpgo/data",|' /etc/sftpgo/sftpgo.json && \
  38. sed -i 's|"backups"|"/srv/sftpgo/backups"|' /etc/sftpgo/sftpgo.json
  39. RUN chown -R sftpgo:sftpgo /etc/sftpgo /srv/sftpgo && chown sftpgo:sftpgo /var/lib/sftpgo && chmod 700 /srv/sftpgo/backups
  40. WORKDIR /var/lib/sftpgo
  41. USER 1000:1000
  42. CMD ["sftpgo", "serve"]