Skip to content

Commit

Permalink
Shrink uptermd Docker image by 5 MB, 20% (#225)
Browse files Browse the repository at this point in the history
* Update uptermd Docker image to use SCRATCH

The output `.tar` is 21M, need to see how that compares to the existing one

* Add missing `USER` directive
  • Loading branch information
bcspragu committed Feb 3, 2024
1 parent f4a2ff8 commit bb763d6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Because changes to just the Dockerfile force a more or less total rebuild,
# which doesn't need to be the case.
Dockerfile.uptermd
34 changes: 27 additions & 7 deletions Dockerfile.uptermd
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
FROM golang:alpine as builder
FROM golang:1.21 as builder

RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid 65532 \
noroot

WORKDIR /build

COPY go.mod .
COPY go.sum .

RUN go mod download
RUN go mod verify

WORKDIR $GOPATH/src/github.com/owenthereal/upterm
COPY . .
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
RUN go install ./cmd/uptermd/...
RUN go build -o uptermd ./cmd/uptermd

# Prepare for image
FROM alpine:latest
FROM scratch

MAINTAINER Owen Ou
LABEL org.opencontainers.image.source https://github.com/owenthereal/upterm

RUN adduser -D uptermd
USER uptermd

WORKDIR /app
ENV PATH="/app:${PATH}"

COPY --from=builder /go/bin/* /app
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder /build/uptermd .

USER noroot:noroot

# sshd
EXPOSE 2222
Expand Down

0 comments on commit bb763d6

Please sign in to comment.