diff --git a/.gitignore b/.gitignore index cf80b28..9ef108a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ vendor/ cmd/*/bin/ **/.vscode/ **/.idea/ + +csm-common.mk \ No newline at end of file diff --git a/.golangci.yaml b/.golangci.yaml index 56f5332..d20d7e0 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -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 diff --git a/Dockerfile b/Dockerfile index c9d1e3a..1b8c4e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,22 @@ 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/mockgen@v1.6.0 +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" \ @@ -7,6 +24,6 @@ LABEL vendor="Dell Inc." \ 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"] \ No newline at end of file diff --git a/Makefile b/Makefile index d41fd3f..300defe 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/README.md b/README.md index 65b1d21..0721b0d 100644 --- a/README.md +++ b/README.md @@ -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=:` -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.