Hi, what do you think about such workflow:
I build custom alpine container and its size is ~5x smaller in the end, if I additionally strip unnecessary debug information using go build with -ldflags="-s -w"
What is more, one could also want to have more secure container, so that inside there is another dedicated user (for instance named feedpushr).
REPOSITORY TAG IMAGE ID CREATED SIZE
patched-feedpushr 3.4.0-rootless xxxxxxxxxxxx 4 days ago 42.2 MB
ncarlier/feedpushr 3.4.0 26dd59e5bc42 16 months ago 213 MB
How about tags x.x.x-alpine x.x.x-alpine-rootless?
#########################################
# Build stage
#########################################
FROM golang:1.23-alpine AS builder
# Repository location
ARG REPOSITORY=github.com/ncarlier
# Artifact name
ARG ARTIFACT=feedpushr
# Copy sources into the container
ADD . /go/src/$REPOSITORY/$ARTIFACT
# Set working directory
WORKDIR /go/src/$REPOSITORY/$ARTIFACT
# Build the binary
RUN make build plugins
AND now 2 flavors:
#########################################
# Distribution root
#########################################
FROM alpine:latest
# Repository location
ARG REPOSITORY=github.com/ncarlier
# Artifact name
ARG ARTIFACT=feedpushr
# Install project files
COPY --from=builder /go/src/$REPOSITORY/$ARTIFACT/release/ /usr/local/share/$ARTIFACT/
# Install binary
COPY --from=builder /go/src/$REPOSITORY/$ARTIFACT/release/$ARTIFACT /usr/local/bin/$ARTIFACT
# Define working directory
WORKDIR /usr/local/share/$ARTIFACT
# Define entrypoint
ENTRYPOINT [ "feedpushr" ]
#########################################
# Distribution rootless
#########################################
FROM alpine:latest
# Repository location
ARG REPOSITORY=github.com/ncarlier
# Artifact name
ARG ARTIFACT=feedpushr
# Install project files
COPY --from=builder /go/src/$REPOSITORY/$ARTIFACT/release/ /usr/local/share/$ARTIFACT/
# Install binary
COPY --from=builder /go/src/$REPOSITORY/$ARTIFACT/release/$ARTIFACT /usr/local/bin/$ARTIFACT
RUN addgroup -g 1000 feedpushr &&\
adduser -D -H -u 1000 -G feedpushr feedpushr &&\
chown -R feedpushr:feedpushr /usr/local/share/$ARTIFACT
# Switch user to rootless
USER 1000
# Define working directory
WORKDIR /usr/local/share/$ARTIFACT
# Define entrypoint
ENTRYPOINT [ "feedpushr" ]
Hi, what do you think about such workflow:
I build custom alpine container and its size is ~5x smaller in the end, if I additionally strip unnecessary debug information using go build with
-ldflags="-s -w"What is more, one could also want to have more secure container, so that inside there is another dedicated user (for instance named feedpushr).
How about tags
x.x.x-alpinex.x.x-alpine-rootless?AND now 2 flavors: