Skip to content

Commit 2259285

Browse files
authored
Merge pull request #770 from mattcary/buildarg
Move ARG decls to top of Dockerfile
2 parents 2a97336 + d009d11 commit 2259285

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
ARG BUILDPLATFORM
16+
1517
FROM --platform=$BUILDPLATFORM golang:1.13.15 as builder
1618

1719
ARG STAGINGVERSION
18-
ARG BUILDPLATFORM
1920
ARG TARGETPLATFORM
2021

2122
WORKDIR /go/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver
2223
ADD . .
23-
# RUN mkdir -p bin \
24-
# && GOARCH=$(echo $TARGETPLATFORM | cut -f2 -d '/') go build -mod=vendor -ldflags "-X main.version=${STAGINGVERSION}" -o bin/gce-pd-csi-driver ./cmd/gce-pd-csi-driver/
25-
RUN GOARCH=$(echo $TARGETPLATFORM | cut -f2 -d '/') GCE_PD_CSI_STAGING_VERSION=${STAGINGVERSION} make gce-pd-driver
24+
RUN GOARCH=$(echo $TARGETPLATFORM | cut -f2 -d '/') GCE_PD_CSI_STAGING_VERSION=$STAGINGVERSION make gce-pd-driver
2625

2726
# MAD HACKS: Build a version first so we can take the scsi_id bin and put it somewhere else in our real build
2827
FROM k8s.gcr.io/build-image/debian-base:buster-v1.6.0 as mad-hack

Makefile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,20 @@ WINDOWS_IMAGE_TAGS=ltsc2019 1909 2004 20H2
3333
WINDOWS_BASE_IMAGES=$(BASE_IMAGE_LTSC2019) $(BASE_IMAGE_1909) $(BASE_IMAGE_2004) $(BASE_IMAGE_20H2)
3434

3535
all: gce-pd-driver gce-pd-driver-windows
36-
gce-pd-driver:
36+
gce-pd-driver: require-GCE_PD_CSI_STAGING_VERSION
3737
mkdir -p bin
3838
go build -mod=vendor -gcflags=$(GCFLAGS) -ldflags "-X main.version=$(STAGINGVERSION)" -o bin/${DRIVERBINARY} ./cmd/gce-pd-csi-driver/
3939

40-
gce-pd-driver-windows:
40+
gce-pd-driver-windows: require-GCE_PD_CSI_STAGING_VERSION
4141
mkdir -p bin
4242
GOOS=windows go build -mod=vendor -ldflags -X=main.version=$(STAGINGVERSION) -o bin/${DRIVERWINDOWSBINARY} ./cmd/gce-pd-csi-driver/
4343

44-
build-container: require-GCE_PD_CSI_STAGING_IMAGE init-buildx
45-
$(DOCKER) buildx build --platform=linux \
44+
build-container: require-GCE_PD_CSI_STAGING_IMAGE require-GCE_PD_CSI_STAGING_VERSION init-buildx
45+
$(DOCKER) buildx build --platform=linux --progress=plain \
4646
-t $(STAGINGIMAGE):$(STAGINGVERSION) \
47-
--build-arg STAGINGVERSION=$(STAGINGVERSION) --push .
47+
--build-arg BUILDPLATFORM=linux \
48+
--build-arg STAGINGVERSION=$(STAGINGVERSION) \
49+
--push .
4850

4951
build-and-push-windows-container-ltsc2019: require-GCE_PD_CSI_STAGING_IMAGE init-buildx
5052
$(DOCKER) buildx build --file=Dockerfile.Windows --platform=windows \
@@ -108,6 +110,11 @@ ifndef GCE_PD_CSI_STAGING_IMAGE
108110
$(error "Must set environment variable GCE_PD_CSI_STAGING_IMAGE to staging image repository")
109111
endif
110112

113+
require-GCE_PD_CSI_STAGING_VERSION:
114+
ifndef GCE_PD_CSI_STAGING_VERSION
115+
$(error "Must set environment variable GCE_PD_CSI_STAGING_VERSION to build a runnable driver")
116+
endif
117+
111118
init-buildx:
112119
# Ensure we use a builder that can leverage it (the default on linux will not)
113120
-$(DOCKER) buildx rm multiarch-multiplatform-builder

0 commit comments

Comments
 (0)