Skip to content

Commit

Permalink
Implement Multi stage build for sdk image for powermax (#34)
Browse files Browse the repository at this point in the history
* Implement docker multi stage build

* Fixed the lint issue

* Implement docker multi stage build

* Fixed the lint issue
  • Loading branch information
HarishH-DELL authored Jan 22, 2024
1 parent 847285b commit 1c3cedc
Show file tree
Hide file tree
Showing 5 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
Expand Up @@ -2,3 +2,5 @@ vendor/
cmd/*/bin/
**/.vscode/
**/.idea/

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
23 changes: 20 additions & 3 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-metrics-powermax
ENV CMD_PATH cmd/metrics-powermax/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-metrics-powermax" \
summary="Dell Container Storage Modules (CSM) for Observability - Metrics for PowerMax" \
description="Provides insight into storage usage and performance as it relates to the CSI (Container Storage Interface) Driver for Dell PowerMax" \
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 @@ -32,7 +32,7 @@ test:
.PHONY: docker
docker: download-csm-common
$(eval include csm-common.mk)
SERVICE=cmd/metrics-powermax docker build -t csm-metrics-powermax -f Dockerfile --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) cmd/metrics-powermax/
docker build -t csm-metrics-powermax -f Dockerfile --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) .

.PHONY: push
push:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Once all prerequisites are on the Linux host, follow the steps below to clone an

1. Clone the repository using the following command: `git clone https://github.com/dell/csm-metrics-powermax.git`
2. Set the DOCKER_REPO environment variable to point to the local Docker repository, for example: `export DOCKER_REPO=<ip-address>:<port>`
3. In the csm-metrics-powermax directory, run the following command to build the Docker image called csm-metrics-powermax: `make clean build docker`
3. In the csm-metrics-powermax directory, run the following command to build the Docker image called csm-metrics-powermax: `make docker`
4. Tag (with the "latest" tag) and push the image to the local Docker repository by running the following command: `make tag push`

__Note:__ Linux support only. If you are using a local insecure docker registry, ensure you configure the insecure registries on each of the Kubernetes worker nodes to allow access to the local docker repository.
Expand Down

0 comments on commit 1c3cedc

Please sign in to comment.