Skip to content

Commit

Permalink
build docker image from scratch to reduce runtime dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrossbach committed Jul 29, 2024
1 parent 99194db commit a7e483e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@

FROM registry.access.redhat.com/ubi8/ubi-minimal AS builder
RUN microdnf install -y shadow-utils && microdnf clean all
RUN set -o pipefail && groupadd -r -g 1000 gouser && useradd -r -u 1000 -g gouser -m -d /opt/gouser -s /bin/bash gouser && cat /etc/passwd | grep gouser > /etc/passwd_gouser
FROM alpine AS builder
RUN apk update && apk upgrade && apk add --no-cache ca-certificates
RUN update-ca-certificates
RUN set -o pipefail && addgroup --gid 1000 gouser && adduser --disabled-password --no-create-home --ingroup gouser gouser
RUN cat /etc/passwd
RUN cat /etc/passwd | grep gouser > /etc/passwd_gouser

FROM scratch
ARG VERSION
ENV VERSION=${VERSION}
COPY noah-mqtt /
COPY LICENSE /
COPY --from=builder /etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd_gouser /etc/passwd
USER gouser
ENTRYPOINT ["/noah-mqtt"]
6 changes: 6 additions & 0 deletions cmd/noah-mqtt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ import (
"noah-mqtt/internal/service"
"os"
"os/signal"
"os/user"
"syscall"
)

func main() {
cfg := config.Get()
slog.Info("noah-mqtt started", slog.String("version", cfg.Version))

if currentUser, err := user.Current(); err == nil {
slog.Info("running as", slog.String("username", currentUser.Username), slog.String("uid", currentUser.Uid))
}

service.Start()

cancelChan := make(chan os.Signal, 1)
Expand Down

0 comments on commit a7e483e

Please sign in to comment.