Dockerfile 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Default to Go 1.24
  2. ARG GO_VERSION=1.24
  3. FROM golang:${GO_VERSION}-alpine as build
  4. # Necessary to run 'go get' and to compile the linked binary
  5. RUN apk add git musl-dev mailcap
  6. WORKDIR /go/src/github.com/dutchcoders/transfer.sh
  7. COPY go.mod go.sum ./
  8. RUN go mod download
  9. COPY . .
  10. # build & install server
  11. RUN CGO_ENABLED=0 go build -tags netgo -ldflags "-X github.com/dutchcoders/transfer.sh/cmd.Version=$(git describe --tags) -a -s -w -extldflags '-static'" -o /go/bin/transfersh
  12. ARG PUID=5000 \
  13. PGID=5000 \
  14. RUNAS
  15. RUN mkdir -p /tmp/useradd /tmp/empty && \
  16. if [ ! -z "$RUNAS" ]; then \
  17. echo "${RUNAS}:x:${PUID}:${PGID}::/nonexistent:/sbin/nologin" >> /tmp/useradd/passwd && \
  18. echo "${RUNAS}:!:::::::" >> /tmp/useradd/shadow && \
  19. echo "${RUNAS}:x:${PGID}:" >> /tmp/useradd/group && \
  20. echo "${RUNAS}:!::" >> /tmp/useradd/groupshadow; else touch /tmp/useradd/unused; fi
  21. FROM scratch AS final
  22. LABEL maintainer="Andrea Spacca <andrea.spacca@gmail.com>"
  23. ARG RUNAS
  24. COPY --from=build /etc/mime.types /etc/mime.types
  25. COPY --from=build /tmp/empty /tmp
  26. COPY --from=build /tmp/useradd/* /etc/
  27. COPY --from=build --chown=${RUNAS} /go/bin/transfersh /go/bin/transfersh
  28. COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
  29. USER ${RUNAS}
  30. ENTRYPOINT ["/go/bin/transfersh", "--listener", ":8080"]
  31. EXPOSE 8080