Dockerfile.alpine 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. FROM golang:1.15-alpine 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) -ldflags "-s -w -X github.com/drakkan/sftpgo/version.commit=${COMMIT_SHA} -X github.com/drakkan/sftpgo/version.date=`date -u +%FT%TZ`" -v -o sftpgo
  18. FROM alpine:3.12
  19. RUN apk add --update --no-cache ca-certificates tzdata mailcap
  20. # set up nsswitch.conf for Go's "netgo" implementation
  21. # https://github.com/gliderlabs/docker-alpine/issues/367#issuecomment-424546457
  22. RUN test ! -e /etc/nsswitch.conf && echo 'hosts: files dns' > /etc/nsswitch.conf
  23. RUN mkdir -p /etc/sftpgo /var/lib/sftpgo /usr/share/sftpgo /srv/sftpgo
  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/sftpgo /usr/local/bin/
  30. # Log to the stdout so the logs will be available using docker logs
  31. ENV SFTPGO_LOG_FILE_PATH=""
  32. # templates and static paths are inside the container
  33. ENV SFTPGO_HTTPD__TEMPLATES_PATH=/usr/share/sftpgo/templates
  34. ENV SFTPGO_HTTPD__STATIC_FILES_PATH=/usr/share/sftpgo/static
  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. sed -i "s|\"bind_address\": \"127.0.0.1\",|\"bind_address\": \"\",|" /etc/sftpgo/sftpgo.json
  39. RUN chown -R sftpgo:sftpgo /etc/sftpgo && chown sftpgo:sftpgo /var/lib/sftpgo /srv/sftpgo
  40. WORKDIR /var/lib/sftpgo
  41. USER 1000:1000
  42. CMD ["sftpgo", "serve"]