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

Multistage go build for docker image building #61

Merged
merged 6 commits into from
Jan 23, 2024
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
25 changes: 20 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
ARG BASEIMAGE
ARG GOVERSION

FROM $BASEIMAGE AS final
COPY ./bin/vg-snapshotter .

FROM golang:${GOVERSION} as builder
RUN mkdir -p /go/src
COPY ./ /go/src/
WORKDIR /go/src/
RUN CGO_ENABLED=0 \
make build

# Final Stage
FROM $BASEIMAGE AS final

# Copy the binary from the builder stage

COPY --from=builder /go/src/bin/vg-snapshotter .

# Set entry point
ENTRYPOINT ["/vg-snapshotter"]

# Metadata labels
LABEL vendor="Dell Inc." \
name="dellcsi-vg-snapshotter" \
summary="CSI VG Snapshotter for Dell EMC Powerflex" \
summary="CSI VG Snapshotter for Dell EMC PowerFlex/PowerStore" \
description="Dell Storage VolumeGroup Snapshot Controller for CSI" \
version="1.4.0" \
license="Apache-2.0"

license="Apache-2.0"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ else
GOBIN=$(shell go env GOBIN)
endif

all: build
all: help

##@ General

Expand Down
2 changes: 1 addition & 1 deletion docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ endif
docker:
@echo "Base Images is set to: $(BASEIMAGE)"
@echo "Building: $(REGISTRY)/$(IMAGENAME):$(IMAGETAG)"
$(BUILDER) build -t "$(REGISTRY)/$(IMAGENAME):$(IMAGETAG)" --target $(BUILDSTAGE) --build-arg BASEIMAGE=$(BASEIMAGE) .
$(BUILDER) build -t "$(REGISTRY)/$(IMAGENAME):$(IMAGETAG)" --target $(BUILDSTAGE) --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg GOVERSION=$(GOVERSION) .

push:
@echo "Pushing: $(REGISTRY)/$(IMAGENAME):$(IMAGETAG)"
Expand Down
8 changes: 8 additions & 0 deletions overrides.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ DEFAULT_REGISTRY="dellemc"
DEFAULT_IMAGENAME="csi-volumegroup-snapshotter"
DEFAULT_BUILDSTAGE="final"
DEFAULT_IMAGETAG="1.4.0"
DEFAULT_GOVERSION="1.21"

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

# set the GOVERSION if needed
ifeq ($(GOVERSION),)
export GOVERSION="$(DEFAULT_GOVERSION)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KshitijaKakde Could you kindly expand the overrides-help segment intended for the help page display? As we're introducing a new argument, it is advisable to incorporate it into the current list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

endif

# set the IMAGENAME if needed
ifeq ($(IMAGENAME),)
export IMAGENAME="$(DEFAULT_IMAGENAME)"
Expand Down Expand Up @@ -48,5 +54,7 @@ overrides-help:
@echo "BUILDSTAGE - The Dockerfile build stage to execute, default is: $(DEFAULT_BUILDSTAGE)"
@echo " Stages can be found by looking at the Dockerfile"
@echo " Current setting is: $(BUILDSTAGE)"
@echo "GOVERSION - The version of Go to build with, default is: $(DEFAULT_GOVERSION)"
@echo " Current setting is: $(GOVERSION)""
@echo

Loading