Skip to content

Commit 27b29d6

Browse files
authored
Merge pull request #613 from jingxu97/sep/multios
Enable multi-arch build in Makefile
2 parents e1d76d7 + 9f5b4af commit 27b29d6

File tree

6 files changed

+56
-28
lines changed

6 files changed

+56
-28
lines changed

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,30 @@ build-container: require-GCE_PD_CSI_STAGING_IMAGE
4040

4141
build-and-push-windows-container-ltsc2019: require-GCE_PD_CSI_STAGING_IMAGE init-buildx
4242
$(DOCKER) buildx build --file=Dockerfile.Windows --platform=windows \
43-
-t $(STAGINGIMAGE):$(STAGINGVERSION) --build-arg BASE_IMAGE=servercore \
43+
-t $(STAGINGIMAGE)-ltsc2019:$(STAGINGVERSION) --build-arg BASE_IMAGE=servercore \
4444
--build-arg BASE_IMAGE_TAG=ltsc2019 \
4545
--build-arg STAGINGVERSION=$(STAGINGVERSION) --push .
4646

4747
build-and-push-windows-container-1909: require-GCE_PD_CSI_STAGING_IMAGE init-buildx
4848
$(DOCKER) buildx build --file=Dockerfile.Windows --platform=windows \
49-
-t $(STAGINGIMAGE):$(STAGINGVERSION) --build-arg BASE_IMAGE=servercore \
49+
-t $(STAGINGIMAGE)-1909:$(STAGINGVERSION) --build-arg BASE_IMAGE=servercore \
5050
--build-arg BASE_IMAGE_TAG=1909 \
5151
--build-arg STAGINGVERSION=$(STAGINGVERSION) --push .
5252

53+
build-and-push-multi-arch: build-and-push-container-linux build-and-push-windows-container-ltsc2019 build-and-push-windows-container-1909
54+
$(DOCKER) manifest create --amend $(STAGINGIMAGE):$(STAGINGVERSION) ${STAGINGIMAGE}-linux:${STAGINGVERSION} ${STAGINGIMAGE}-1909:${STAGINGVERSION} ${STAGINGIMAGE}-ltsc2019:${STAGINGVERSION}
55+
STAGINGIMAGE=${STAGINGIMAGE} STAGINGVERSION=${STAGINGVERSION} ./manifest_osversion.sh
56+
$(DOCKER) manifest push -p $(STAGINGIMAGE):$(STAGINGVERSION)
57+
5358
push-container: build-container
5459
gcloud docker -- push $(STAGINGIMAGE):$(STAGINGVERSION)
5560

61+
build-and-push-container-linux: require-GCE_PD_CSI_STAGING_IMAGE init-buildx
62+
$(DOCKER) buildx build --platform=linux \
63+
-t $(STAGINGIMAGE)-linux:$(STAGINGVERSION) \
64+
--build-arg TAG=$(STAGINGVERSION) --push .
65+
66+
5667
test-sanity: gce-pd-driver
5768
go test -mod=vendor --v -timeout 30s sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/sanity -run ^TestSanity$
5869

deploy/kubernetes/base/node_windows/node.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ spec:
4242
- name: gce-pd-driver
4343
# Don't change base image without changing pdImagePlaceholder in
4444
# test/k8s-integration/main.go
45-
image: gke.gcr.io/gcp-compute-persistent-disk-csi-driver-win
45+
image: gke.gcr.io/gcp-compute-persistent-disk-csi-driver
4646
args:
4747
- "--v=5"
4848
- "--endpoint=unix:/csi/csi.sock"

deploy/kubernetes/images/alpha/image.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: ImageTagTransformer
33
metadata:
44
name: imagetag-gcepd-driver-alpha-win
55
imageTag:
6-
name: gke.gcr.io/gcp-compute-persistent-disk-csi-driver-win
6+
name: gke.gcr.io/gcp-compute-persistent-disk-csi-driver
77
newName: gcr.io/gke-release-staging/gcp-compute-persistent-disk-csi-driver
88
newTag: "v1.0.1-gke.9"
99
---

manifest_osversion.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# The following is a workaround for issue https://github.com/moby/moby/issues/41417
4+
# to manually inserver os.version information into docker manifest file
5+
# TODO: once docker manifest annotation for os.versions is availabler for the installed docker here,
6+
# replace the following with annotation approach. https://github.com/docker/cli/pull/2578
7+
8+
export DOCKER_CLI_EXPERIMENTAL=enabled
9+
_WINDOWS_VERSIONS="1909 ltsc2019"
10+
BASE="mcr.microsoft.com/windows/servercore"
11+
12+
IFS=', ' read -r -a osversions <<< "$_WINDOWS_VERSIONS"
13+
MANIFEST_TAG=${STAGINGIMAGE}:${STAGINGVERSION}
14+
15+
# translate from image tag to docker manifest foler format
16+
# e.g., gcr.io_k8s-staging-csi_gce-pd-windows-v2
17+
manifest_folder=$(echo "${MANIFEST_TAG}" | sed "s|/|_|g" | sed "s/:/-/")
18+
echo ${manifest_folder}
19+
echo ${#osversions[@]}
20+
21+
for ((i=0;i<${#osversions[@]};++i)); do
22+
BASEIMAGE="${BASE}:${osversions[i]}"
23+
echo $BASEIIMAGE
24+
25+
full_version=$(docker manifest inspect ${BASEIMAGE} | grep "os.version" | head -n 1 | awk '{print $2}') || true
26+
echo $full_version
27+
28+
IMAGETAG=${STAGINGIMAGE}-${osversions[i]}:${STAGINGVERSION}
29+
image_folder=$(echo "${IMAGETAG}" | sed "s|/|_|g" | sed "s/:/-/")
30+
echo ${manifest_folder}
31+
32+
sed -i -r "s/(\"os\"\:\"windows\")/\0,\"os.version\":$full_version/" \
33+
"${HOME}/.docker/manifests/${manifest_folder}/${image_folder}"
34+
35+
done

test/k8s-integration/driver.go

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,6 @@ func installDriver(platform, goPath, pkgDir, stagingImage, stagingVersion, deplo
4242
if err != nil {
4343
return fmt.Errorf("failed to edit kustomize: %s, err: %v", out, err)
4444
}
45-
if platform == "windows" {
46-
out, err = exec.Command(
47-
filepath.Join(pkgDir, "bin", "kustomize"),
48-
"edit",
49-
"set",
50-
"image",
51-
fmt.Sprintf("%s-win=%s-win:%s", pdImagePlaceholder, stagingImage, stagingVersion)).CombinedOutput()
52-
if err != nil {
53-
return fmt.Errorf("failed to edit kustomize: %s, err: %v", out, err)
54-
}
55-
}
5645
}
5746

5847
var deployEnv []string
@@ -131,22 +120,15 @@ func pushImage(pkgDir, stagingImage, stagingVersion, platform string) error {
131120
}
132121
var cmd *exec.Cmd
133122

134-
cmd = exec.Command("make", "-C", pkgDir, "push-container",
123+
// build multi-arch image which can work for both Linux and Windows
124+
cmd = exec.Command("make", "-C", pkgDir, "build-and-push-multi-arch",
135125
fmt.Sprintf("GCE_PD_CSI_STAGING_VERSION=%s", stagingVersion),
136126
fmt.Sprintf("GCE_PD_CSI_STAGING_IMAGE=%s", stagingImage))
137-
err = runCommand("Pushing GCP Container for Linux", cmd)
127+
err = runCommand("Building and Pushing GCP Container for Windows", cmd)
138128
if err != nil {
139-
return fmt.Errorf("failed to run make command for linux: err: %v", err)
140-
}
141-
if platform == "windows" {
142-
cmd = exec.Command("make", "-C", pkgDir, "build-and-push-windows-container-ltsc2019",
143-
fmt.Sprintf("GCE_PD_CSI_STAGING_VERSION=%s", stagingVersion),
144-
fmt.Sprintf("GCE_PD_CSI_STAGING_IMAGE=%s-win", stagingImage))
145-
err = runCommand("Building and Pushing GCP Container for Windows", cmd)
146-
if err != nil {
147-
return fmt.Errorf("failed to run make command for windows: err: %v", err)
148-
}
129+
return fmt.Errorf("failed to run make command for windows: err: %v", err)
149130
}
131+
150132
return nil
151133
}
152134

test/k8s-integration/prepull.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ spec:
3838
resources:
3939
requests:
4040
cpu: 1m
41-
command: ['cmd.exe', '/c', 'ping -n 1800 127.0.0.1 >NUL']
41+
command: ['cmd.exe', '/c', 'ping -n 1800 127.0.0.1 >NUL']

0 commit comments

Comments
 (0)