Skip to content

Commit fe391d3

Browse files
Add cloudbuild configuration to build the image (#124)
1 parent 4930806 commit fe391d3

File tree

3 files changed

+81
-35
lines changed

3 files changed

+81
-35
lines changed

Dockerfile

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
#FROM golang:1.15-buster AS builder
2-
#WORKDIR /go/src/sigs.k8s.io/ibm-powervs-block-csi-driver
3-
#COPY . .
4-
#RUN make
1+
# Copyright 2022 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
514

6-
FROM --platform=linux/ppc64le k8s.gcr.io/build-image/debian-base:v2.1.3 AS debian-base
7-
RUN clean-install ca-certificates e2fsprogs mount udev util-linux xfsprogs
8-
RUN clean-install bash multipath-tools sg3-utils
9-
# COPY --from=builder /go/src/sigs.k8s.io/ibm-powervs-block-csi-driver/bin/ibm-powervs-block-csi-driver /bin/ibm-powervs-block-csi-driver
10-
COPY ./bin/ibm-powervs-block-csi-driver /bin/ibm-powervs-block-csi-driver
15+
FROM golang:1.17 AS builder
16+
WORKDIR /go/src/sigs.k8s.io/ibm-powervs-block-csi-driver
17+
ADD . .
18+
ARG TARGETPLATFORM
19+
RUN ARCH=$(echo $TARGETPLATFORM | cut -f2 -d '/') make driver
20+
21+
FROM k8s.gcr.io/build-image/debian-base:v2.1.3 AS debian-base
22+
RUN clean-install ca-certificates e2fsprogs mount udev util-linux xfsprogs bash multipath-tools sg3-utils
23+
COPY --from=builder /go/src/sigs.k8s.io/ibm-powervs-block-csi-driver /ibm-powervs-block-csi-driver
24+
ENTRYPOINT ["/ibm-powervs-block-csi-driver"]
1125

12-
ENTRYPOINT ["/bin/ibm-powervs-block-csi-driver"]
1326

14-
FROM --platform=linux/ppc64le registry.access.redhat.com/ubi8/ubi:8.5 AS rhel-base
27+
FROM registry.access.redhat.com/ubi8/ubi:8.5 AS rhel-base
1528
RUN yum --disableplugin=subscription-manager -y install httpd php \
1629
&& yum --disableplugin=subscription-manager clean all
1730
RUN clean-install ca-certificates e2fsprogs mount udev util-linux xfsprogs
18-
# COPY --from=builder /go/src/sigs.k8s.io/ibm-powervs-block-csi-driver/bin/ibm-powervs-block-csi-driver /bin/ibm-powervs-block-csi-driver
19-
COPY ./bin/ibm-powervs-block-csi-driver /bin/ibm-powervs-block-csi-driver
20-
21-
ENTRYPOINT ["/bin/ibm-powervs-block-csi-driver"]
31+
COPY --from=builder /go/src/sigs.k8s.io/ibm-powervs-block-csi-driver /ibm-powervs-block-csi-driver
32+
ENTRYPOINT ["/ibm-powervs-block-csi-driver"]

Makefile

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,60 @@
1313
# limitations under the License.
1414

1515
PKG=sigs.k8s.io/ibm-powervs-block-csi-driver
16-
IMAGE?=quay.io/powercloud/ibm-powervs-block-csi-driver
17-
VERSION=v0.0.1
18-
GIT_COMMIT?=$(shell git rev-parse HEAD)
16+
GIT_COMMIT?=$(shell git rev-parse --short HEAD)
1917
BUILD_DATE?=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
20-
LDFLAGS?="-X ${PKG}/pkg/driver.driverVersion=${VERSION} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE} -s -w"
18+
REGISTRY?=gcr.io/k8s-staging-cloud-provider-ibm
19+
IMAGE?=ibm-powervs-block-csi-driver
20+
TAG?=$(GIT_COMMIT)
21+
LDFLAGS?="-X ${PKG}/pkg/driver.driverVersion=${TAG} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE} -s -w"
2122

2223
GO111MODULE=on
2324
GOPROXY=direct
2425
GOPATH=$(shell go env GOPATH)
2526
GOOS=$(shell go env GOOS)
2627
GOBIN=$(shell pwd)/bin
2728

28-
PLATFORM=linux/ppc64le
29-
30-
3129
.EXPORT_ALL_VARIABLES:
3230

3331
bin:
3432
@mkdir -p $@
3533

36-
.PHONY: bin/ibm-powervs-block-csi-driver
37-
bin/ibm-powervs-block-csi-driver: | bin
38-
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le go build -ldflags ${LDFLAGS} -o bin/ibm-powervs-block-csi-driver ./cmd/
34+
.PHONY: driver
35+
bin/ibm-powervs-block-csi-driver:
36+
driver: | bin
37+
CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -ldflags ${LDFLAGS} -o bin/ibm-powervs-block-csi-driver ./cmd/
3938

4039
.PHONY: test
4140
test:
4241
go test -v -race ./cmd/... ./pkg/...
4342

44-
.PHONY: image-release
45-
image-release:
46-
docker buildx build -t $(IMAGE):$(VERSION) . --target debian-base
47-
4843
.PHONY: image
4944
image:
50-
docker build -t $(IMAGE):$(VERSION) . --target debian-base
51-
52-
.PHONY: push-release
53-
push-release:
54-
docker push $(IMAGE):$(VERSION)
45+
docker build -t $(REGISTRY)/$(IMAGE):$(TAG) . --target debian-base
5546

5647
.PHONY: push
5748
push:
58-
docker push $(IMAGE):$(VERSION)
49+
docker push $(REGISTRY)/$(IMAGE):$(TAG)
50+
51+
build-image-and-push-linux-amd64: init-buildx
52+
{ \
53+
set -e ; \
54+
docker buildx build \
55+
--build-arg TARGETPLATFORM=linux/amd64 \
56+
-t $(REGISTRY)/$(IMAGE):$(TAG)_linux_amd64 --push . --target debian-base; \
57+
}
58+
59+
build-image-and-push-linux-ppc64le: init-buildx
60+
{ \
61+
set -e ; \
62+
docker buildx build \
63+
--build-arg TARGETPLATFORM=linux/ppc64le \
64+
-t $(REGISTRY)/$(IMAGE):$(TAG)_linux_ppc64le --push . --target debian-base; \
65+
}
66+
67+
build-and-push-multi-arch: build-image-and-push-linux-amd64 build-image-and-push-linux-ppc64le
68+
docker manifest create --amend $(REGISTRY)/$(IMAGE):$(TAG) $(REGISTRY)/$(IMAGE):$(TAG)_linux_amd64 $(REGISTRY)/$(IMAGE):$(TAG)_linux_ppc64le
69+
docker manifest push -p $(REGISTRY)/$(IMAGE):$(TAG)
5970

6071
.PHONY: clean
6172
clean:
@@ -83,3 +94,9 @@ verify: verify-vendor
8394
verify-vendor:
8495
@ echo; echo "### $@:"
8596
@ ./hack/verify-vendor.sh
97+
98+
init-buildx:
99+
# Ensure we use a builder that can leverage it (the default on linux will not)
100+
-docker buildx rm multiarch-multiplatform-builder
101+
docker buildx create --use --name=multiarch-multiplatform-builder
102+
docker run --rm --privileged multiarch/qemu-user-static --reset --credential yes --persistent yes

cloudbuild.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# A configuration file for multi-arch image building with the Google cloud build service.
2+
#
3+
# See https://github.com/kubernetes/test-infra/blob/master/config/jobs/image-pushing/README.md
4+
# for more details on image pushing process in Kubernetes.
5+
6+
# This must be specified in seconds. If omitted, defaults to 600s (10 mins).
7+
timeout: 1200s
8+
options:
9+
substitution_option: ALLOW_LOOSE
10+
steps:
11+
- name: 'gcr.io/k8s-testimages/gcb-docker-gcloud:v20210722-085d930'
12+
entrypoint: make
13+
env:
14+
- PULL_BASE_REF=${_PULL_BASE_REF}
15+
- TAG=${_GIT_TAG}
16+
- HOME=/root
17+
args:
18+
- build-and-push-multi-arch

0 commit comments

Comments
 (0)