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

docker: reduce images size #7

Merged
merged 1 commit into from
Jan 6, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- uses: hadolint/[email protected]
with:
recursive: true
ignore: DL3041
ignore: DL3018

shellcheck:
runs-on: ubuntu-latest
Expand Down
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 as builder

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
RUN apk add --no-cache libc6-compat
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