Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrink uptermd Docker image by 5 MB, 20% #225

Merged
merged 2 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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