2023-02-09 08:33:33 +00:00
|
|
|
FROM golang:1.20-bullseye as builder
|
2021-09-06 17:10:28 +00:00
|
|
|
|
|
|
|
ENV CGO_ENABLED=0 GOFLAGS="-mod=readonly"
|
|
|
|
|
|
|
|
RUN mkdir -p /workspace
|
|
|
|
WORKDIR /workspace
|
|
|
|
|
|
|
|
ARG GOPROXY
|
|
|
|
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
RUN go mod download
|
|
|
|
|
|
|
|
ARG COMMIT_SHA
|
|
|
|
|
|
|
|
# This ARG allows to disable some optional features and it might be useful if you build the image yourself.
|
2021-09-07 17:52:28 +00:00
|
|
|
# For this variant we disable SQLite support since it requires CGO and so a C runtime which is not installed
|
|
|
|
# in distroless/static-* images
|
2022-12-18 14:21:32 +00:00
|
|
|
ARG FEATURES
|
2021-09-06 17:10:28 +00:00
|
|
|
|
|
|
|
COPY . .
|
|
|
|
|
|
|
|
RUN set -xe && \
|
2022-09-08 11:44:14 +00:00
|
|
|
export COMMIT_SHA=${COMMIT_SHA:-$(git describe --always --abbrev=8 --dirty)} && \
|
2022-07-24 14:18:54 +00:00
|
|
|
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
|
2021-09-06 17:10:28 +00:00
|
|
|
|
|
|
|
# Modify the default configuration file
|
2022-02-25 16:38:15 +00:00
|
|
|
RUN sed -i 's|"users_base_dir": "",|"users_base_dir": "/srv/sftpgo/data",|' sftpgo.json && \
|
|
|
|
sed -i 's|"backups"|"/srv/sftpgo/backups"|' sftpgo.json && \
|
|
|
|
sed -i 's|"sqlite"|"bolt"|' sftpgo.json
|
2021-09-06 17:10:28 +00:00
|
|
|
|
2023-04-19 11:41:59 +00:00
|
|
|
RUN apt-get update && apt-get install --no-install-recommends -y media-types openssh-server libcap2-bin && setcap cap_net_bind_service=+ep /workspace/sftpgo && rm -rf /var/lib/apt/lists/*
|
2021-09-06 17:10:28 +00:00
|
|
|
|
|
|
|
RUN mkdir /etc/sftpgo /var/lib/sftpgo /srv/sftpgo
|
|
|
|
|
|
|
|
FROM gcr.io/distroless/static-debian11
|
|
|
|
|
|
|
|
COPY --from=builder --chown=1000:1000 /etc/sftpgo /etc/sftpgo
|
|
|
|
COPY --from=builder --chown=1000:1000 /srv/sftpgo /srv/sftpgo
|
|
|
|
COPY --from=builder --chown=1000:1000 /var/lib/sftpgo /var/lib/sftpgo
|
|
|
|
COPY --from=builder --chown=1000:1000 /workspace/sftpgo.json /etc/sftpgo/sftpgo.json
|
2022-11-18 17:13:03 +00:00
|
|
|
COPY --from=builder --chown=1000:1000 /etc/ssh/moduli /etc/sftpgo/moduli
|
2021-09-06 17:10:28 +00:00
|
|
|
COPY --from=builder /workspace/templates /usr/share/sftpgo/templates
|
|
|
|
COPY --from=builder /workspace/static /usr/share/sftpgo/static
|
2021-11-21 08:32:51 +00:00
|
|
|
COPY --from=builder /workspace/openapi /usr/share/sftpgo/openapi
|
2021-09-06 17:10:28 +00:00
|
|
|
COPY --from=builder /workspace/sftpgo /usr/local/bin/
|
|
|
|
COPY --from=builder /etc/mime.types /etc/mime.types
|
|
|
|
|
|
|
|
# Log to the stdout so the logs will be available using docker logs
|
|
|
|
ENV SFTPGO_LOG_FILE_PATH=""
|
2021-09-07 17:52:28 +00:00
|
|
|
# These env vars are required to avoid the following error when calling user.Current():
|
|
|
|
# unable to get the current user: user: Current requires cgo or $USER set in environment
|
|
|
|
ENV USER=sftpgo
|
|
|
|
ENV HOME=/var/lib/sftpgo
|
2021-09-06 17:10:28 +00:00
|
|
|
|
|
|
|
WORKDIR /var/lib/sftpgo
|
|
|
|
USER 1000:1000
|
|
|
|
|
|
|
|
CMD ["sftpgo", "serve"]
|