roulette/docker/Dockerfile

44 lines
859 B
Docker
Raw Permalink Normal View History

2023-09-05 13:22:06 +00:00
# set app name
ARG app=roulette
# create build stage
ARG TAG
FROM --platform=$BUILDPLATFORM golang:$TAG AS build
ARG app
# install dependencies
RUN apk add --update-cache upx
2023-09-05 13:22:06 +00:00
# copy source files into the container
COPY . /src/$app/
2023-09-05 13:22:06 +00:00
# build, strip, and compress the binary
2023-09-05 13:22:06 +00:00
WORKDIR /src/$app
ARG TARGETOS TARGETARCH
RUN CGO_ENABLED=0 \
GOOS=$TARGETOS \
GOARCH=$TARGETARCH \
go build -trimpath -ldflags "-s -w" -tags timetzdata -o $app \
2023-09-05 13:22:06 +00:00
&& upx --best --lzma $app \
&& chmod 500 $app
# set up final stage
FROM scratch
ARG app
# copy in user info
COPY --chown=root:root --chmod=0400 docker/passwd /etc/passwd
2023-09-05 13:22:06 +00:00
# run as nonroot
USER nonroot
# copy in binary
COPY --from=build --chown=root:root --chmod=0005 /src/$app/$app /$app
# listen on an unprivileged port
EXPOSE 8080
# run application
ENTRYPOINT ["/roulette"]
CMD ["-r","/data"]