Skip to content

Commit

Permalink
Docker: allow selection between root and non-root UID/GID at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
lkubb committed Oct 9, 2021
1 parent 4558308 commit 78e236d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Dockerfile
Expand Up @@ -14,23 +14,26 @@ ENV GO111MODULE=on
# build & install server
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

ARG PUID=1000 \
PGID=1000
ARG PUID=5000 \
PGID=5000 \
RUNAS

RUN mkdir -p /tmp/useradd && \
echo "transfersh:x:${PUID}:${PGID}::/nonexistent:/sbin/nologin" >> /tmp/useradd/passwd && \
echo "transfersh:!:::::::" >> /tmp/useradd/shadow && \
echo "transfersh:x:${PGID}:" >> /tmp/useradd/group && \
echo "transfersh:!::" >> /tmp/useradd/groupshadow
if [ ! -z "$RUNAS" ]; then \
echo "${RUNAS}:x:${PUID}:${PGID}::/nonexistent:/sbin/nologin" >> /tmp/useradd/passwd && \
echo "${RUNAS}:!:::::::" >> /tmp/useradd/shadow && \
echo "${RUNAS}:x:${PGID}:" >> /tmp/useradd/group && \
echo "${RUNAS}:!::" >> /tmp/useradd/groupshadow; fi

FROM scratch AS final
LABEL maintainer="Andrea Spacca <andrea.spacca@gmail.com>"
ARG RUNAS

COPY --from=build /tmp/useradd/* /etc/
COPY --from=build --chown=transfersh /go/bin/transfersh /go/bin/transfersh
COPY --from=build --chown=${RUNAS} /go/bin/transfersh /go/bin/transfersh
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

USER transfersh
USER ${RUNAS}

ENTRYPOINT ["/go/bin/transfersh", "--listener", ":8080"]

Expand Down

0 comments on commit 78e236d

Please sign in to comment.