Skip to content

Commit

Permalink
docker: reduce images size
Browse files Browse the repository at this point in the history
By introducing multi-stage build
And switching to alpine
And using grpcurl from docker

x20 size reduction !

$ docker images | grep smbios
ghcr.io/opiproject/opi-smbios-bridge   main            f5c93b419b0a   3 hours ago     1.55GB
opi-smbios-bridge                      main            dd66706d37d1   12 days ago     73.1MB

Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb committed Jan 6, 2023
1 parent 3170660 commit ab0c8b3
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
# syntax=docker/dockerfile:1
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2022 Dell Inc, or its subsidiaries.

# Alpine is chosen for its small footprint
# compared to Ubuntu
FROM docker.io/library/golang:1.19.4
FROM docker.io/library/golang:1.19.4-alpine3.17 as builder
RUN apk add --no-cache build-base

WORKDIR /app

# install curl (healthcheck)
RUN go install github.com/fullstorydev/grpcurl/cmd/[email protected]

# Download necessary Go modules
COPY go.mod ./
COPY go.sum ./
RUN go mod download

# build an app
COPY *.go ./
RUN go build -v -buildmode=plugin -o /opi-smbios-bridge.so ./inventory.go
RUN go build -v -buildmode=plugin -o /opi-smbios-bridge.so ./inventory.go \
&& go build -v -buildmode=default -o /opi-smbios-bridge ./main.go

# second stage to reduce image size
FROM alpine:3.17
COPY --from=builder /opi-smbios-bridge /
COPY --from=builder /opi-smbios-bridge.so /
COPY --from=docker.io/fullstorydev/grpcurl:v1.8.7-alpine /bin/grpcurl /usr/local/bin/
EXPOSE 50051
CMD [ "go", "run", "main.go", "-port=50051" ]
HEALTHCHECK CMD grpcurl -plaintext localhost:50051 list || exit 1
CMD [ "/opi-smbios-bridge", "-port=50051" ]
HEALTHCHECK CMD grpcurl -plaintext localhost:50051 list || exit 1

0 comments on commit ab0c8b3

Please sign in to comment.