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

Feature/multistage go build #39

Merged
merged 10 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
#
# Copyright © 2022 - 2023 Dell Inc. or its subsidiaries. All Rights Reserved.
# Copyright © 2022 - 2024 Dell Inc. or its subsidiaries. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,7 +32,25 @@ endif


.PHONY: all
all: go-build

all: help

# include an overrides file, which sets up default values and allows user overrides
include overrides.mk

# Help target, prints usefule information
help:
@echo
@echo "The following targets are commonly used:"
@echo
@echo "go-build - Builds the code locally"
@echo "check - Runs the suite of code checking tools: lint, format, etc"
@echo "clean - Cleans the local build"
@echo "docker - Builds the code within a golang container and then creates the driver image"
@echo "push - Pushes the built container to a target registry"
@echo "test - Runs the unit tests"
@echo
@make -s overrides-help

ifneq (on,$(GO111MODULE))
export GO111MODULE := on
Expand Down
19 changes: 15 additions & 4 deletions docker-files/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
#
# Copyright © 2023 Dell Inc. or its subsidiaries. All Rights Reserved.
# Copyright © 2023 - 2024 Dell Inc. or its subsidiaries. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,17 +14,28 @@
#
#
# Dockerfile to build CSI Metadata Retriever sidecar
# some arguments that must be supplied
ARG GOVERSION
ARG BASEIMAGE

FROM $BASEIMAGE
# Stage to build the driver
FROM golang:${GOVERSION} as builder

RUN mkdir -p /go/src
COPY ./ /go/src/
WORKDIR /go/src/
RUN CGO_ENABLED=0 \
make go-build

# Stage to build the driver image
FROM $BASEIMAGE AS final

COPY --from=builder /go/src/csi-metadata-retriever /
LABEL vendor="Dell Inc." \
name="csi-metadata-retriever" \
summary="CSI Metadata Retriever sidecar" \
description="CSI Metadata Retriever sidecar for metadata retrievel via kubeapi" \
version="1.6.0" \
adarsh-dell marked this conversation as resolved.
Show resolved Hide resolved
license="Apache-2.0"

COPY licenses /licenses
COPY "csi-metadata-retriever" .
ENTRYPOINT ["/csi-metadata-retriever"]
49 changes: 8 additions & 41 deletions docker.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
#
# Copyright © 2022 - 2023 Dell Inc. or its subsidiaries. All Rights Reserved.
# Copyright © 2022 - 2024 Dell Inc. or its subsidiaries. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,57 +16,24 @@

# for variables override
-include vars.mk

# Includes the following generated file to get semantic version information
ifdef NOTES
RELNOTE="$(NOTES)"
else
RELNOTE=
endif

ifndef DOCKER_REGISTRY
DOCKER_REGISTRY=dellemc
endif

ifndef DOCKER_IMAGE_NAME
DOCKER_IMAGE_NAME=csi-metadata-retriever
endif

# figure out if podman or docker should be used (use podman if found)
ifneq (, $(shell which podman 2>/dev/null))
BUILDER=podman
else
BUILDER=docker
endif

ifndef MAJOR
MAJOR=1
endif

ifndef MINOR
MINOR=6
endif

ifndef PATCH
PATCH=0
endif
include overrides.mk

docker: download-csm-common
$(eval include csm-common.mk)
echo "MAJOR $(MAJOR) MINOR $(MINOR) PATCH $(PATCH) RELNOTE $(RELNOTE)"
echo "Building: $(REGISTRY)/$(IMAGENAME):v$(MAJOR).$(MINOR).$(PATCH) RELNOTE $(RELNOTE)"
echo "$(DOCKER_FILE)"
$(BUILDER) build -f $(DOCKER_FILE) -t "$(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):v$(MAJOR).$(MINOR).$(PATCH)$(RELNOTE)" --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) .
$(BUILDER) build -f $(DOCKER_FILE) -t "$(REGISTRY)/$(IMAGENAME):v$(MAJOR).$(MINOR).$(PATCH)$(RELNOTE)" --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) --build-arg GOVERSION=$(GOVERSION) .

docker-no-cache: download-csm-common
$(eval include csm-common.mk)
echo "MAJOR $(MAJOR) MINOR $(MINOR) PATCH $(PATCH) RELNOTE $(RELNOTE)"
echo "Building: $(REGISTRY)/$(IMAGENAME):$(MAJOR).$(MINOR).$(PATCH) RELNOTE $(RELNOTE)"
echo "$(DOCKER_FILE) --no-cache"
$(BUILDER) build --no-cache --pull -f $(DOCKER_FILE) -t "$(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):v$(MAJOR).$(MINOR).$(PATCH)$(RELNOTE)" --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) .
$(BUILDER) build --no-cache --pull -f $(DOCKER_FILE) -t "$(REGISTRY)/$(IMAGENAME):v$(MAJOR).$(MINOR).$(PATCH)$(RELNOTE)" --build-arg BASEIMAGE=$(DEFAULT_BASEIMAGE) --build-arg GOVERSION=$(GOVERSION) .


push:
echo "MAJOR $(MAJOR) MINOR $(MINOR) PATCH $(PATCH) RELNOTE $(RELNOTE)"
$(BUILDER) push "$(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):v$(MAJOR).$(MINOR).$(PATCH)$(RELNOTE)"
echo "Pushing MAJOR $(MAJOR) MINOR $(MINOR) PATCH $(PATCH) RELNOTE $(RELNOTE)"
$(BUILDER) push "$(REGISTRY)/$(IMAGENAME):v$(MAJOR).$(MINOR).$(PATCH)$(RELNOTE)"

download-csm-common:
curl -O -L https://raw.githubusercontent.com/dell/csm/main/config/csm-common.mk
77 changes: 77 additions & 0 deletions overrides.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright © 2024 Dell Inc. or its subsidiaries. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License

# overrides file
# this file, included from the Makefile, will overlay default values with environment variables
#

# DEFAULT values


# DEFAULT values
DEFAULT_GOVERSION="1.21"
DEFAULT_REGISTRY="dellemc"
DEFAULT_IMAGENAME="csi-metadata-retriever"


# set the GOVERSION if needed
ifeq ($(GOVERSION),)
export GOVERSION="$(DEFAULT_GOVERSION)"
endif

# set the REGISTRY if needed
ifeq ($(REGISTRY),)
export REGISTRY="$(DEFAULT_REGISTRY)"
endif

# set the IMAGENAME if needed
ifeq ($(IMAGENAME),)
export IMAGENAME="$(DEFAULT_IMAGENAME)"
endif


# figure out if podman or docker should be used (use podman if found)
ifneq (, $(shell which podman 2>/dev/null))
export BUILDER=podman
else
export BUILDER=docker
endif

ifdef NOTES
RELNOTE="$(NOTES)"
else
RELNOTE=
endif

ifndef MAJOR
MAJOR=1
endif
ifndef MINOR
MINOR=6
endif
ifndef PATCH
PATCH=0
endif

# target to print some help regarding these overrides and how to use them
overrides-help:
@echo
@echo "The following environment variables can be set to control the build"
@echo
@echo "GOVERSION - The version of Go to build with, default is: $(DEFAULT_GOVERSION)"
@echo " Current setting is: $(GOVERSION)"
@echo "REGISTRY - The registry to push images to, default is: $(DEFAULT_REGISTRY)"
@echo " Current setting is: $(REGISTRY)"
@echo "IMAGENAME - The image name to be built, defaut is: $(DEFAULT_IMAGENAME)"
@echo " Current setting is: $(IMAGENAME)"
@echo

Loading