Skip to content

Commit d229d20

Browse files
committed
cloudbuild: enable stargz-snapshotter
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent 92f7f27 commit d229d20

File tree

4 files changed

+117
-96
lines changed

4 files changed

+117
-96
lines changed

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ RUN set -eux && \
5454
ARG PROTOC_GEN_GO_VERSION
5555
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache \
5656
set -eux && \
57-
GOBIN="${OUTDIR}/usr/local/bin" go install -v -tags='osusergo,netgo,static,static_build' -buildmode=pie -ldflags='-s -w -d -linkmode external "-extldflags=-static-pie"' -installsuffix='netgo' \
57+
GOBIN="${OUTDIR}/usr/local/bin" go install -v -tags='osusergo,netgo,static,static_build' -buildmode=pie -ldflags='-s -w -d -linkmode external -buildid= "-extldflags=-static-pie"' -installsuffix='netgo' \
5858
google.golang.org/protobuf/cmd/protoc-gen-go@${PROTOC_GEN_GO_VERSION}
5959
ARG PROTOC_GEN_GO_GRPC_VERSION
6060
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache \
6161
set -eux && \
62-
GOBIN="${OUTDIR}/usr/local/bin" go install -v -tags='osusergo,netgo,static,static_build' -buildmode=pie -ldflags='-s -w -d -linkmode external "-extldflags=-static-pie"' -installsuffix='netgo' \
62+
GOBIN="${OUTDIR}/usr/local/bin" go install -v -tags='osusergo,netgo,static,static_build' -buildmode=pie -ldflags='-s -w -d -linkmode external -buildid= "-extldflags=-static-pie"' -installsuffix='netgo' \
6363
google.golang.org/grpc/cmd/protoc-gen-go-grpc@${PROTOC_GEN_GO_GRPC_VERSION}
6464

6565
FROM gcr.io/distroless/base:nonroot AS golang

cloudbuild.yaml

+102-94
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,155 @@
11
steps:
2-
- id: docker_buildx
2+
- id: buildkit
33
name: docker:20.10
4+
env:
5+
- "DOCKER_BUILDKIT=1"
6+
entrypoint: "docker"
47
args:
8+
- image
59
- build
6-
- --target=docker
710
- --build-arg=DOCKER_VERSION=${_DOCKER_VERSION}
8-
- --build-arg=BUILDX_VERSION=${_BUILDX_VERSION}
9-
- --tag=docker-buildx:cloudbuild
10-
- --file=hack/dockerfiles/buildx.dockerfile
11-
- hack/dockerfiles
12-
env:
13-
- "DOCKER_BUILDKIT=1"
11+
- --build-arg=BUILDKIT_VERSION=${_BUILDKIT_VERSION}
12+
- -t
13+
- buildkit:cloudbuild
14+
- --target=buildkit
15+
- --file=./hack/dockerfiles/buildkit.dockerfile
16+
- ./hack/dockerfiles
1417
waitFor:
1518
- "-"
1619

17-
- id: bootstrap_buildx
18-
name: docker-buildx:cloudbuild
20+
- id: bootstrap_buildkitd
21+
name: buildkit:cloudbuild
22+
entrypoint: "docker"
1923
args:
20-
- buildx
21-
- create
22-
- --bootstrap
23-
- --name=cloudbuild
24-
- --driver=docker-container
25-
- --driver-opt=image=moby/buildkit:nightly
26-
- --driver-opt=network=cloudbuild
27-
- --use
24+
- container
25+
- run
26+
- --detach
27+
- --privileged
28+
- --name=buildkitd
29+
- --network=cloudbuild
30+
- moby/buildkit:${_BUILDKIT_VERSION}
2831
waitFor:
29-
- "docker_buildx"
32+
- "buildkit"
3033

3134
- id: protoc-builder
32-
name: docker-buildx:cloudbuild
35+
name: buildkit:cloudbuild
36+
entrypoint: "buildctl"
3337
args:
34-
- buildx
38+
- --addr=docker-container://buildkitd
3539
- build
36-
- --target=protoc-builder
37-
- --build-arg=BUILDKIT_INLINE_CACHE=1
38-
- --build-arg=PROTOC_VERSION=${_PROTOC_VERSION}
39-
- --build-arg=GOLANG_VERSION=${_GOLANG_VERSION}
40-
- --build-arg=ALPINE_VERSION=${_ALPINE_VERSION}
41-
- --cache-from=type=registry,ref=gcr.io/$PROJECT_ID/protoc/protoc-builder:cloudbuild_cache
42-
- --output=type=image,name=gcr.io/$PROJECT_ID/protoc/protoc-builder:cloudbuild_cache,push=true
43-
- .
40+
- --frontend=dockerfile.v0
41+
- --local=context=/workspace
42+
- --local=dockerfile=/workspace
43+
- --opt=target=protoc-builder
44+
- --opt=build-arg:PROTOC_VERSION=${_PROTOC_VERSION}
45+
- --opt=build-arg:GOLANG_VERSION=${_GOLANG_VERSION}
46+
- --opt=build-arg:ALPINE_VERSION=${_ALPINE_VERSION}
47+
- --export-cache=type=inline
48+
- --import-cache=type=registry,ref=gcr.io/$PROJECT_ID/protoc/protoc-builder:cloudbuild_cache
4449
waitFor:
45-
- "bootstrap_buildx"
50+
- "bootstrap_buildkitd"
4651

4752
- id: protoc
48-
name: docker-buildx:cloudbuild
53+
name: buildkit:cloudbuild
54+
entrypoint: "buildctl"
4955
args:
50-
- buildx
56+
- --addr=docker-container://buildkitd
5157
- build
52-
- --target=protoc
53-
- --build-arg=PROTOC_VERSION=${_PROTOC_VERSION}
54-
- --build-arg=GOLANG_VERSION=${_GOLANG_VERSION}
55-
- --build-arg=ALPINE_VERSION=${_ALPINE_VERSION}
56-
- --tag=gcr.io/$PROJECT_ID/protoc/protoc:${_PROTOC_VERSION}
57-
- --load
58-
- .
58+
- --frontend=dockerfile.v0
59+
- --local=context=/workspace
60+
- --local=dockerfile=/workspace
61+
- --opt=target=protoc
62+
- --opt=build-arg:PROTOC_VERSION=${_PROTOC_VERSION}
63+
- --opt=build-arg:GOLANG_VERSION=${_GOLANG_VERSION}
64+
- --opt=build-arg:ALPINE_VERSION=${_ALPINE_VERSION}
65+
- --output=type=image,name=gcr.io/$PROJECT_ID/protoc/protoc:${_PROTOC_VERSION},push=true,oci-mediatypes=true,compression=estargz
66+
- --import-cache=type=registry,ref=gcr.io/$PROJECT_ID/protoc/protoc-builder:cloudbuild_cache
5967
waitFor:
6068
- "protoc-builder"
6169

6270
- id: protoc-debug
63-
name: docker-buildx:cloudbuild
71+
name: buildkit:cloudbuild
72+
entrypoint: "buildctl"
6473
args:
65-
- buildx
74+
- --addr=docker-container://buildkitd
6675
- build
67-
- --target=protoc-debug
68-
- --build-arg=PROTOC_VERSION=${_PROTOC_VERSION}
69-
- --build-arg=GOLANG_VERSION=${_GOLANG_VERSION}
70-
- --build-arg=ALPINE_VERSION=${_ALPINE_VERSION}
71-
- --tag=gcr.io/$PROJECT_ID/protoc/protoc:${_PROTOC_VERSION}-debug
72-
- --load
73-
- .
76+
- --frontend=dockerfile.v0
77+
- --local=context=/workspace
78+
- --local=dockerfile=/workspace
79+
- --opt=target=protoc-debug
80+
- --opt=build-arg:PROTOC_VERSION=${_PROTOC_VERSION}
81+
- --opt=build-arg:GOLANG_VERSION=${_GOLANG_VERSION}
82+
- --opt=build-arg:ALPINE_VERSION=${_ALPINE_VERSION}
83+
- --output=type=image,name=gcr.io/$PROJECT_ID/protoc/protoc:${_PROTOC_VERSION}-debug,push=true,oci-mediatypes=true,compression=estargz
84+
- --import-cache=type=registry,ref=gcr.io/$PROJECT_ID/protoc/protoc-builder:cloudbuild_cache
7485
waitFor:
7586
- "protoc-builder"
7687

7788
- id: golang-builder
78-
name: docker-buildx:cloudbuild
89+
name: buildkit:cloudbuild
90+
entrypoint: "buildctl"
7991
args:
80-
- buildx
92+
- --addr=docker-container://buildkitd
8193
- build
82-
- --target=golang-builder
83-
- --build-arg=BUILDKIT_INLINE_CACHE=1
84-
- --build-arg=PROTOC_VERSION=${_PROTOC_VERSION}
85-
- --build-arg=GOLANG_VERSION=${_GOLANG_VERSION}
86-
- --build-arg=ALPINE_VERSION=${_ALPINE_VERSION}
87-
- --build-arg=PROTOC_GEN_GO_VERSION=${_PROTOC_GEN_GO_VERSION}
88-
- --build-arg=PROTOC_GEN_GO_GRPC_VERSION=${_PROTOC_GEN_GO_GRPC_VERSION}
89-
- --cache-from=type=registry,ref=gcr.io/$PROJECT_ID/protoc/golang-builder:cloudbuild_cache
90-
- --output=type=image,name=gcr.io/$PROJECT_ID/protoc/golang-builder:cloudbuild_cache,push=true
91-
- .
92-
waitFor:
93-
- "protoc"
94-
- "protoc-debug"
94+
- --frontend=dockerfile.v0
95+
- --local=context=/workspace
96+
- --local=dockerfile=/workspace
97+
- --opt=target=golang-builder
98+
- --opt=build-arg:PROTOC_VERSION=${_PROTOC_VERSION}
99+
- --opt=build-arg:GOLANG_VERSION=${_GOLANG_VERSION}
100+
- --opt=build-arg:ALPINE_VERSION=${_ALPINE_VERSION}
101+
- --opt=build-arg:PROTOC_GEN_GO_VERSION=${_PROTOC_GEN_GO_VERSION}
102+
- --opt=build-arg:PROTOC_GEN_GO_GRPC_VERSION=${_PROTOC_GEN_GO_GRPC_VERSION}
103+
- --export-cache=type=inline
104+
- --import-cache=type=registry,ref=gcr.io/$PROJECT_ID/protoc/protoc-builder:cloudbuild_cache
95105

96106
- id: golang
97-
name: docker-buildx:cloudbuild
107+
name: buildkit:cloudbuild
108+
entrypoint: "buildctl"
98109
args:
99-
- buildx
110+
- --addr=docker-container://buildkitd
100111
- build
101-
- --target=golang
102-
- --build-arg=PROTOC_VERSION=${_PROTOC_VERSION}
103-
- --build-arg=GOLANG_VERSION=${_GOLANG_VERSION}
104-
- --build-arg=ALPINE_VERSION=${_ALPINE_VERSION}
105-
- --build-arg=PROTOC_GEN_GO_VERSION=${_PROTOC_GEN_GO_VERSION}
106-
- --build-arg=PROTOC_GEN_GO_GRPC_VERSION=${_PROTOC_GEN_GO_GRPC_VERSION}
107-
- --tag=gcr.io/$PROJECT_ID/protoc/golang:${_PROTOC_VERSION}-${_GOLANG_VERSION}
108-
- --load
109-
- .
112+
- --frontend=dockerfile.v0
113+
- --local=context=/workspace
114+
- --local=dockerfile=/workspace
115+
- --opt=target=golang
116+
- --opt=build-arg:PROTOC_VERSION=${_PROTOC_VERSION}
117+
- --opt=build-arg:GOLANG_VERSION=${_GOLANG_VERSION}
118+
- --opt=build-arg:ALPINE_VERSION=${_ALPINE_VERSION}
119+
- --output=type=image,name=gcr.io/$PROJECT_ID/protoc/golang:${_PROTOC_VERSION}-${_GOLANG_VERSION},push=true,oci-mediatypes=true,compression=estargz
120+
- --import-cache=type=registry,ref=gcr.io/$PROJECT_ID/protoc/cache/golang:${_PROTOC_VERSION}-${_GOLANG_VERSION}:cloudbuild_cache
110121
waitFor:
122+
- "protoc"
111123
- "golang-builder"
112124

113125
- id: golang-debug
114-
name: docker-buildx:cloudbuild
126+
name: buildkit:cloudbuild
127+
entrypoint: "buildctl"
115128
args:
116-
- buildx
129+
- --addr=docker-container://buildkitd
117130
- build
118-
- --target=golang-debug
119-
- --build-arg=PROTOC_VERSION=${_PROTOC_VERSION}
120-
- --build-arg=GOLANG_VERSION=${_GOLANG_VERSION}
121-
- --build-arg=ALPINE_VERSION=${_ALPINE_VERSION}
122-
- --build-arg=PROTOC_GEN_GO_VERSION=${_PROTOC_GEN_GO_VERSION}
123-
- --build-arg=PROTOC_GEN_GO_GRPC_VERSION=${_PROTOC_GEN_GO_GRPC_VERSION}
124-
- --tag=gcr.io/$PROJECT_ID/protoc/golang:${_PROTOC_VERSION}-${_GOLANG_VERSION}-debug
125-
- --load
126-
- .
131+
- --frontend=dockerfile.v0
132+
- --local=context=/workspace
133+
- --local=dockerfile=/workspace
134+
- --opt=target=golang-debug
135+
- --opt=build-arg:PROTOC_VERSION=${_PROTOC_VERSION}
136+
- --opt=build-arg:GOLANG_VERSION=${_GOLANG_VERSION}
137+
- --opt=build-arg:ALPINE_VERSION=${_ALPINE_VERSION}
138+
- --output=type=image,name=gcr.io/$PROJECT_ID/protoc/golang:${_PROTOC_VERSION}-${_GOLANG_VERSION}-debug,push=true,oci-mediatypes=true,compression=estargz
139+
- --import-cache=type=registry,ref=gcr.io/$PROJECT_ID/protoc/protoc-builder:cloudbuild_cache
127140
waitFor:
141+
- "protoc-debug"
128142
- "golang-builder"
129143

130144
substitutions:
131145
_DOCKER_VERSION: "20.10"
132-
_BUILDX_VERSION: "0.7.0-rc1" # https://github.com/docker/buildx/releases/tag/v0.7.0-rc1
133-
_PROTOC_VERSION: "3.19.0" # https://github.com/protocolbuffers/protobuf/releases/tag/v3.19.0
146+
_BUILDKIT_VERSION: "v0.10.0"
147+
_PROTOC_VERSION: "3.19.4" # https://github.com/protocolbuffers/protobuf/releases/tag/v3.19.0
134148
_GOLANG_VERSION: "1.17"
135-
_ALPINE_VERSION: "3.14"
149+
_ALPINE_VERSION: "3.15"
136150
_PROTOC_GEN_GO_VERSION: "v1.27.1" # https://github.com/protocolbuffers/protobuf-go/releases/tag/v1.27.1
137151
_PROTOC_GEN_GO_GRPC_VERSION: "9c668aeab869" # https://github.com/grpc/grpc-go/tree/9c668aeab869
138152

139-
# images:
140-
# - "gcr.io/$PROJECT_ID/protoc/protoc:${_PR_NUMBER:-${_PROTOC_VERSION}}"
141-
# - "gcr.io/$PROJECT_ID/protoc/protoc:${_PR_NUMBER:-${_PROTOC_VERSION}}-debug"
142-
# - "gcr.io/$PROJECT_ID/protoc/golang:${_PR_NUMBER:-${_PROTOC_VERSION}-${_GOLANG_VERSION}}"
143-
# - "gcr.io/$PROJECT_ID/protoc/golang:${_PR_NUMBER:-${_PROTOC_VERSION}-${_GOLANG_VERSION}}-debug"
144-
145153
tags:
146154
- "protoc.protoc"
147155
- "protoc.golang"

hack/dockerfiles/buildkit.dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# syntax=docker.io/docker/dockerfile:1.4.0-labs
2+
3+
ARG BUILDKIT_VERSION
4+
ARG DOCKER_VERSION
5+
6+
FROM --platform=$BUILDPLATFORM docker:${DOCKER_VERSION} AS docker
7+
8+
FROM --platform=$BUILDPLATFORM moby/buildkit:${BUILDKIT_VERSION} AS buildkit
9+
COPY --from=docker /usr/local/bin/docker /usr/local/bin/docker

hack/dockerfiles/buildx.dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
ARG DOCKER_VERSION
44
ARG BUILDX_VERSION
5+
ARG BUILDKIT_VERSION
56

67
FROM --platform=$BUILDPLATFORM docker/buildx-bin:${BUILDX_VERSION} AS buildx
78

9+
FROM --platform=$BUILDPLATFORM moby/buildkit:${BUILDKIT_VERSION} as buildkit
10+
811
FROM --platform=$BUILDPLATFORM docker:${DOCKER_VERSION} AS docker
912
COPY --from=buildx /buildx /usr/libexec/docker/cli-plugins/docker-buildx
13+
COPY --from=buildkit /usr/bin/buildctl /usr/bin/buildctl
1014
RUN docker buildx version

0 commit comments

Comments
 (0)