Skip to content

Commit

Permalink
Implement docker multi stage build
Browse files Browse the repository at this point in the history
  • Loading branch information
HarishH-DELL committed Jan 18, 2024
1 parent 0bae103 commit 4143ddf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
vendor/
cmd/*/bin/

csm-common.mk
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
run:
timeout: 20m
issue-exit-code: 0 # we will change this later
issues-exit-code: 0 # we will change this later
tests: true
skip-dirs-use-default: true
modules-download-mode: readonly
Expand Down
25 changes: 21 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
ARG BASEIMAGE

# Build the sdk binary
FROM golang:1.21 as builder

# Set envirment variable
ENV APP_NAME csm-topology
ENV CMD_PATH cmd/topology/main.go

# Copy application data into image
COPY . /go/src/$APP_NAME
WORKDIR /go/src/$APP_NAME

# Build the binary
RUN go install github.com/golang/mock/[email protected]
RUN go generate ./...
RUN CGO_ENABLED=0 GOOS=linux go build -o /go/src/service /go/src/$APP_NAME/$CMD_PATH

# Build the sdk image
FROM $BASEIMAGE as final
LABEL vendor="Dell Inc." \
name="csm-topology" \
summary="Dell Container Storage Modules (CSM) for Observability - Topology" \
summary="Dell Container Storage Modules (CSM) for Observability - Metrics for Topology" \
description="Provides Kubernetes administrators with the topology data related to containerized storage that is provisioned by CSI (Container Storage Interface) Drivers for Dell storage products" \
version="2.0.0" \
license="Apache-2.0"
ARG SERVICE
COPY $SERVICE/bin/service /service
ENTRYPOINT ["/service"]

COPY --from=builder /go/src/service /
ENTRYPOINT ["/service"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test:
.PHONY: docker
docker: download-csm-common
$(eval include csm-common.mk)
SERVICE=cmd/topology docker build -t csm-topology -f Dockerfile --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) cmd/topology
docker build -t csm-topology -f Dockerfile --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) .

.PHONY: tag
tag:
Expand Down

0 comments on commit 4143ddf

Please sign in to comment.