Skip to content

Commit 96e724f

Browse files
committed
add multisarch and cloudbuild
Signed-off-by: Patrik Cyvoct <[email protected]>
1 parent 3b44a3d commit 96e724f

File tree

4 files changed

+158
-33
lines changed

4 files changed

+158
-33
lines changed

Makefile

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

15-
.PHONY: gen clean certs build docker/proxy-server docker/proxy-agent push-images test
16-
proto/agent/agent.pb.go: proto/agent/agent.proto
17-
protoc -I proto proto/agent/agent.proto --go_out=plugins=grpc:proto
15+
ARCH ?= amd64
16+
ALL_ARCH = amd64 arm arm64 ppc64le s390x
17+
18+
REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
19+
STAGING_REGISTRY := gcr.io/k8s-staging-kas-network-proxy
20+
21+
SERVER_IMAGE_NAME ?= proxy-server
22+
AGENT_IMAGE_NAME ?= proxy-agent
23+
24+
SERVER_FULL_IMAGE ?= $(REGISTRY)/$(SERVER_IMAGE_NAME)
25+
AGENT_FULL_IMAGE ?= $(REGISTRY)/$(AGENT_IMAGE_NAME)
26+
27+
TAG ?= $(shell git rev-parse HEAD)
28+
29+
## --------------------------------------
30+
## Testing
31+
## --------------------------------------
32+
33+
.PHONY: test
34+
test:
35+
go test ./...
36+
37+
## --------------------------------------
38+
## Binaries
39+
## --------------------------------------
1840

1941
bin:
2042
mkdir -p bin
2143

44+
.PHONY: build
45+
build: bin/proxy-agent bin/proxy-server bin/proxy-test-client
46+
47+
bin/proxy-agent: bin cmd/agent/main.go proto/agent/agent.pb.go
48+
go build -o bin/proxy-agent cmd/agent/main.go
49+
50+
bin/proxy-test-client: bin cmd/client/main.go proto/proxy.pb.go
51+
go build -o bin/proxy-test-client cmd/client/main.go
52+
53+
bin/proxy-server: bin cmd/proxy/main.go proto/agent/agent.pb.go proto/proxy.pb.go
54+
go build -o bin/proxy-server cmd/proxy/main.go
55+
56+
## --------------------------------------
57+
## Linting
58+
## --------------------------------------
59+
60+
61+
## --------------------------------------
62+
## Proto
63+
## --------------------------------------
64+
65+
.PHONY: gen
66+
gen: proto/agent/agent.pb.go proto/proxy.pb.go
67+
2268
proto/agent/agent.pb.go: proto/agent/agent.proto
2369
protoc -I proto proto/agent/agent.proto --go_out=plugins=grpc:proto
2470
cat hack/go-license-header.txt proto/agent/agent.pb.go > proto/agent/agent.licensed.go
@@ -29,26 +75,9 @@ proto/proxy.pb.go: proto/proxy.proto
2975
cat hack/go-license-header.txt proto/proxy.pb.go > proto/proxy.licensed.go
3076
mv proto/proxy.licensed.go proto/proxy.pb.go
3177

32-
bin/proxy-agent: bin cmd/agent/main.go proto/agent/agent.pb.go
33-
go build -o bin/proxy-agent cmd/agent/main.go
34-
35-
docker/proxy-agent: cmd/agent/main.go proto/agent/agent.pb.go
36-
@[ "${REGISTRY}" ] || ( echo "REGISTRY is not set"; exit 1 )
37-
@[ "${VERSION}" ] || ( echo "VERSION is not set"; exit 1 )
38-
@[ "${PROJECT_ID}" ] || ( echo "PROJECT_ID is not set"; exit 1 )
39-
docker build . -f artifacts/images/agent-build.Dockerfile -t ${REGISTRY}/${PROJECT_ID}/proxy-agent:${VERSION}
40-
41-
bin/proxy-server: bin cmd/proxy/main.go proto/agent/agent.pb.go proto/proxy.pb.go
42-
go build -o bin/proxy-server cmd/proxy/main.go
43-
44-
docker/proxy-server: cmd/proxy/main.go proto/agent/agent.pb.go proto/proxy.pb.go
45-
@[ "${REGISTRY}" ] || ( echo "REGISTRY is not set"; exit 1 )
46-
@[ "${VERSION}" ] || ( echo "VERSION is not set"; exit 1 )
47-
@[ "${PROJECT_ID}" ] || ( echo "PROJECT_ID is not set"; exit 1 )
48-
docker build . -f artifacts/images/server-build.Dockerfile -t ${REGISTRY}/${PROJECT_ID}/proxy-server:${VERSION}
49-
50-
bin/proxy-test-client: bin cmd/client/main.go proto/proxy.pb.go
51-
go build -o bin/proxy-test-client cmd/client/main.go
78+
## --------------------------------------
79+
## Certs
80+
## --------------------------------------
5281

5382
easy-rsa.tar.gz:
5483
curl -L -O --connect-timeout 20 --retry 6 --retry-delay 2 https://storage.googleapis.com/kubernetes-release/easy-rsa/easy-rsa.tar.gz
@@ -64,6 +93,7 @@ cfssljson:
6493
curl --retry 10 -L -o cfssljson https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
6594
chmod +x cfssljson
6695

96+
.PHONY: certs
6797
certs: easy-rsa-master cfssl cfssljson
6898
# set up easy-rsa
6999
cp -rf easy-rsa-master/easyrsa3 easy-rsa-master/master
@@ -93,17 +123,93 @@ certs: easy-rsa-master cfssl cfssljson
93123
cp -r easy-rsa-master/agent/pki/issued certs/agent
94124
cp easy-rsa-master/agent/pki/ca.crt certs/agent/issued
95125

96-
gen: proto/agent/agent.pb.go proto/proxy.pb.go
126+
## --------------------------------------
127+
## Docker
128+
## --------------------------------------
97129

98-
build: bin/proxy-agent bin/proxy-server bin/proxy-test-client
130+
.PHONY: docker-build
131+
docker-build: docker-build/proxy-agent docker-build/proxy-server
132+
133+
.PHONY: docker-push
134+
docker-push: docker-push/proxy-agent docker-push/proxy-server
99135

100-
push-images: docker/proxy-agent docker/proxy-server
136+
.PHONY: docker-build/proxy-agent
137+
docker-build/proxy-agent: cmd/agent/main.go proto/agent/agent.pb.go
138+
@[ "${TAG}" ] || ( echo "TAG is not set"; exit 1 )
139+
echo "Building proxy-agent for ${ARCH}"
140+
docker build . --build-arg ARCH=$(ARCH) -f artifacts/images/agent-build.Dockerfile -t ${AGENT_FULL_IMAGE}-$(ARCH):${TAG}
141+
142+
.PHONY: docker-push/proxy-agent
143+
docker-push/proxy-agent: docker-build/proxy-agent
101144
@[ "${DOCKER_CMD}" ] || ( echo "DOCKER_CMD is not set"; exit 1 )
102-
${DOCKER_CMD} push ${REGISTRY}/${PROJECT_ID}/proxy-agent:${VERSION}
103-
${DOCKER_CMD} push ${REGISTRY}/${PROJECT_ID}/proxy-server:${VERSION}
145+
${DOCKER_CMD} push ${AGENT_FULL_IMAGE}:${TAG}
146+
147+
.PHONY: docker-build/proxy-server
148+
docker-build/proxy-server: cmd/proxy/main.go proto/agent/agent.pb.go proto/proxy.pb.go
149+
@[ "${TAG}" ] || ( echo "TAG is not set"; exit 1 )
150+
echo "Building proxy-server for ${ARCH}"
151+
docker build . --build-arg ARCH=$(ARCH) -f artifacts/images/server-build.Dockerfile -t ${SERVER_FULL_IMAGE}-$(ARCH):${TAG}
152+
153+
.PHONY: docker-push/proxy-server
154+
docker-push/proxy-server: docker-build/proxy-server
155+
@[ "${DOCKER_CMD}" ] || ( echo "DOCKER_CMD is not set"; exit 1 )
156+
${DOCKER_CMD} push ${SERVER_FULL_IMAGE}:${TAG}
157+
158+
## --------------------------------------
159+
## Docker — All ARCH
160+
## --------------------------------------
104161

162+
.PHONY: docker-build-all
163+
docker-build-all: $(addprefix docker-build/proxy-agent-,$(ALL_ARCH)) $(addprefix docker-build/proxy-server-,$(ALL_ARCH))
164+
165+
.PHONY: docker-push-all
166+
docker-push-all: $(addprefix docker-push/proxy-agent-,$(ALL_ARCH)) $(addprefix docker-push/proxy-server-,$(ALL_ARCH))
167+
$(MAKE) docker-push-manifest/proxy-agent
168+
$(MAKE) docker-push-manifest/proxy-server
169+
170+
docker-build/proxy-agent-%:
171+
$(MAKE) ARCH=$* docker-build/proxy-agent
172+
173+
docker-push/proxy-agent-%:
174+
$(MAKE) ARCH=$* docker-push/proxy-agent
175+
176+
docker-build/proxy-server-%:
177+
$(MAKE) ARCH=$* docker-build/proxy-server
178+
179+
docker-push/proxy-server-%:
180+
$(MAKE) ARCH=$* docker-push/proxy-server
181+
182+
.PHONY: docker-push-manifest/proxy-agent
183+
docker-push-manifest/proxy-agent: ## Push the fat manifest docker image.
184+
## Minimum docker version 18.06.0 is required for creating and pushing manifest images.
185+
docker manifest create --amend $(AGENT_FULL_IMAGE):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(AGENT_FULL_IMAGE)\-&:$(TAG)~g")
186+
@for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${AGENT_FULL_IMAGE}:${TAG} ${AGENT_FULL_IMAGE}-$${arch}:${TAG}; done
187+
docker manifest push --purge $(AGENT_FULL_IMAGE):$(TAG)
188+
189+
.PHONY: docker-push-manifest/proxy-server
190+
docker-push-manifest/proxy-server: ## Push the fat manifest docker image.
191+
## Minimum docker version 18.06.0 is required for creating and pushing manifest images.
192+
docker manifest create --amend $(SERVER_FULL_IMAGE):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(SERVER_FULL_IMAGE)\-&:$(TAG)~g")
193+
@for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${SERVER_FULL_IMAGE}:${TAG} ${SERVER_FULL_IMAGE}-$${arch}:${TAG}; done
194+
docker manifest push --purge $(SERVER_FULL_IMAGE):$(TAG)
195+
196+
## --------------------------------------
197+
## Release
198+
## --------------------------------------
199+
200+
.PHONY: release-staging
201+
release-staging: ## Builds and push container images to the staging bucket.
202+
REGISTRY=$(STAGING_REGISTRY) $(MAKE) docker-build-all docker-push-all release-alias-tag
203+
204+
.PHONY: release-alias-tag
205+
release-alias-tag: # Adds the tag to the last build tag. BASE_REF comes from the cloudbuild.yaml
206+
gcloud container images add-tag $(AGENT_FULL_IMAGE):$(TAG) $(AGENT_FULL_IMAGE):$(BASE_REF)
207+
gcloud container images add-tag $(SERVER_FULL_IMAGE):$(TAG) $(SERVER_FULL_IMAGE):$(BASE_REF)
208+
209+
## --------------------------------------
210+
## Cleanup / Verification
211+
## --------------------------------------
212+
213+
.PHONY: clean
105214
clean:
106215
rm -rf proto/agent/agent.pb.go proto/proxy.pb.go easy-rsa.tar.gz easy-rsa-master cfssl cfssljson certs bin
107-
108-
test:
109-
go test ./...

artifacts/images/agent-build.Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ COPY proto/ proto/
99
COPY vendor/ vendor/
1010

1111
# Build
12-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o proxy-agent sigs.k8s.io/apiserver-network-proxy/cmd/agent
12+
ARG ARCH
13+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -a -ldflags '-extldflags "-static"' -o proxy-agent sigs.k8s.io/apiserver-network-proxy/cmd/agent
1314

1415
# Copy the loader into a thin image
1516
FROM scratch

artifacts/images/server-build.Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ COPY proto/ proto/
99
COPY vendor/ vendor/
1010

1111
# Build
12-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o proxy-server sigs.k8s.io/apiserver-network-proxy/cmd/proxy
12+
ARG ARCH
13+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -a -ldflags '-extldflags "-static"' -o proxy-server sigs.k8s.io/apiserver-network-proxy/cmd/proxy
1314

1415
# Copy the loader into a thin image
1516
FROM scratch

cloudbuild.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
timeout: 1200s
2+
options:
3+
substitution_option: ALLOW_LOOSE
4+
steps:
5+
- name: 'gcr.io/k8s-testimages/gcb-docker-gcloud:v20190906-745fed4'
6+
entrypoint: make
7+
env:
8+
- DOCKER_CLI_EXPERIMENTAL=enabled
9+
- TAG=$_GIT_TAG
10+
- BASE_REF=$_PULL_BASE_REF
11+
args:
12+
- release-staging
13+
substitutions:
14+
# _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and
15+
# can be used as a substitution
16+
_GIT_TAG: '12345'
17+
_PULL_BASE_REF: 'dev'

0 commit comments

Comments
 (0)