12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
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
+ DOCKER_CLI_EXPERIMENTAL ?= enabled
30
+
31
+ # # --------------------------------------
32
+ # # Testing
33
+ # # --------------------------------------
34
+
35
+ .PHONY : test
36
+ test :
37
+ go test ./...
38
+
39
+ # # --------------------------------------
40
+ # # Binaries
41
+ # # --------------------------------------
18
42
19
43
bin :
20
44
mkdir -p bin
21
45
46
+ .PHONY : build
47
+ build : bin/proxy-agent bin/proxy-server bin/proxy-test-client
48
+
49
+ bin/proxy-agent : bin cmd/agent/main.go proto/agent/agent.pb.go
50
+ go build -o bin/proxy-agent cmd/agent/main.go
51
+
52
+ bin/proxy-test-client : bin cmd/client/main.go proto/proxy.pb.go
53
+ go build -o bin/proxy-test-client cmd/client/main.go
54
+
55
+ bin/proxy-server : bin cmd/proxy/main.go proto/agent/agent.pb.go proto/proxy.pb.go
56
+ go build -o bin/proxy-server cmd/proxy/main.go
57
+
58
+ # # --------------------------------------
59
+ # # Linting
60
+ # # --------------------------------------
61
+
62
+
63
+ # # --------------------------------------
64
+ # # Proto
65
+ # # --------------------------------------
66
+
67
+ .PHONY : gen
68
+ gen : proto/agent/agent.pb.go proto/proxy.pb.go
69
+
22
70
proto/agent/agent.pb.go : proto/agent/agent.proto
23
71
protoc -I proto proto/agent/agent.proto --go_out=plugins=grpc:proto
24
72
cat hack/go-license-header.txt proto/agent/agent.pb.go > proto/agent/agent.licensed.go
@@ -29,26 +77,9 @@ proto/proxy.pb.go: proto/proxy.proto
29
77
cat hack/go-license-header.txt proto/proxy.pb.go > proto/proxy.licensed.go
30
78
mv proto/proxy.licensed.go proto/proxy.pb.go
31
79
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
80
+ # # --------------------------------------
81
+ # # Certs
82
+ # # --------------------------------------
52
83
53
84
easy-rsa.tar.gz :
54
85
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 +95,7 @@ cfssljson:
64
95
curl --retry 10 -L -o cfssljson https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
65
96
chmod +x cfssljson
66
97
98
+ .PHONY : certs
67
99
certs : easy-rsa-master cfssl cfssljson
68
100
# set up easy-rsa
69
101
cp -rf easy-rsa-master/easyrsa3 easy-rsa-master/master
@@ -93,17 +125,93 @@ certs: easy-rsa-master cfssl cfssljson
93
125
cp -r easy-rsa-master/agent/pki/issued certs/agent
94
126
cp easy-rsa-master/agent/pki/ca.crt certs/agent/issued
95
127
96
- gen : proto/agent/agent.pb.go proto/proxy.pb.go
128
+ # # --------------------------------------
129
+ # # Docker
130
+ # # --------------------------------------
97
131
98
- build : bin/proxy-agent bin/proxy-server bin/proxy-test-client
132
+ .PHONY : docker-build
133
+ docker-build : docker-build/proxy-agent docker-build/proxy-server
134
+
135
+ .PHONY : docker-push
136
+ docker-push : docker-push/proxy-agent docker-push/proxy-server
99
137
100
- push-images : docker/proxy-agent docker/proxy-server
138
+ .PHONY : docker-build/proxy-agent
139
+ docker-build/proxy-agent : cmd/agent/main.go proto/agent/agent.pb.go
140
+ @[ " ${TAG} " ] || ( echo " TAG is not set" ; exit 1 )
141
+ echo " Building proxy-agent for ${ARCH} "
142
+ docker build . --build-arg ARCH=$(ARCH ) -f artifacts/images/agent-build.Dockerfile -t ${AGENT_FULL_IMAGE} -$(ARCH ) :${TAG}
143
+
144
+ .PHONY : docker-push/proxy-agent
145
+ docker-push/proxy-agent : docker-build/proxy-agent
101
146
@[ " ${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}
147
+ ${DOCKER_CMD} push ${AGENT_FULL_IMAGE} :${TAG}
148
+
149
+ .PHONY : docker-build/proxy-server
150
+ docker-build/proxy-server : cmd/proxy/main.go proto/agent/agent.pb.go proto/proxy.pb.go
151
+ @[ " ${TAG} " ] || ( echo " TAG is not set" ; exit 1 )
152
+ echo " Building proxy-server for ${ARCH} "
153
+ docker build . --build-arg ARCH=$(ARCH ) -f artifacts/images/server-build.Dockerfile -t ${SERVER_FULL_IMAGE} -$(ARCH ) :${TAG}
154
+
155
+ .PHONY : docker-push/proxy-server
156
+ docker-push/proxy-server : docker-build/proxy-server
157
+ @[ " ${DOCKER_CMD} " ] || ( echo " DOCKER_CMD is not set" ; exit 1 )
158
+ ${DOCKER_CMD} push ${SERVER_FULL_IMAGE} :${TAG}
159
+
160
+ # # --------------------------------------
161
+ # # Docker — All ARCH
162
+ # # --------------------------------------
104
163
164
+ .PHONY : docker-build-all
165
+ docker-build-all : $(addprefix docker-build/proxy-agent-,$(ALL_ARCH ) ) $(addprefix docker-build/proxy-server-,$(ALL_ARCH ) )
166
+
167
+ .PHONY : docker-push-all
168
+ docker-push-all : $(addprefix docker-push/proxy-agent-,$(ALL_ARCH ) ) $(addprefix docker-push/proxy-server-,$(ALL_ARCH ) )
169
+ $(MAKE ) docker-push-manifest/proxy-agent
170
+ $(MAKE ) docker-push-manifest/proxy-server
171
+
172
+ docker-build/proxy-agent-% :
173
+ $(MAKE ) ARCH=$* docker-build/proxy-agent
174
+
175
+ docker-push/proxy-agent-% :
176
+ $(MAKE ) ARCH=$* docker-push/proxy-agent
177
+
178
+ docker-build/proxy-server-% :
179
+ $(MAKE ) ARCH=$* docker-build/proxy-server
180
+
181
+ docker-push/proxy-server-% :
182
+ $(MAKE ) ARCH=$* docker-push/proxy-server
183
+
184
+ .PHONY : docker-push-manifest/proxy-agent
185
+ docker-push-manifest/proxy-agent : # # Push the fat manifest docker image.
186
+ # # Minimum docker version 18.06.0 is required for creating and pushing manifest images.
187
+ docker manifest create --amend $(AGENT_FULL_IMAGE ) :$(TAG ) $(shell echo $(ALL_ARCH ) | sed -e "s~[^ ]* ~$(AGENT_FULL_IMAGE ) \-&:$(TAG ) ~g")
188
+ @for arch in $(ALL_ARCH ) ; do docker manifest annotate --arch $$ {arch} ${AGENT_FULL_IMAGE} :${TAG} ${AGENT_FULL_IMAGE} -$$ {arch}:${TAG} ; done
189
+ docker manifest push --purge $(AGENT_FULL_IMAGE ) :$(TAG )
190
+
191
+ .PHONY : docker-push-manifest/proxy-server
192
+ docker-push-manifest/proxy-server : # # Push the fat manifest docker image.
193
+ # # Minimum docker version 18.06.0 is required for creating and pushing manifest images.
194
+ docker manifest create --amend $(SERVER_FULL_IMAGE ) :$(TAG ) $(shell echo $(ALL_ARCH ) | sed -e "s~[^ ]* ~$(SERVER_FULL_IMAGE ) \-&:$(TAG ) ~g")
195
+ @for arch in $(ALL_ARCH ) ; do docker manifest annotate --arch $$ {arch} ${SERVER_FULL_IMAGE} :${TAG} ${SERVER_FULL_IMAGE} -$$ {arch}:${TAG} ; done
196
+ docker manifest push --purge $(SERVER_FULL_IMAGE ) :$(TAG )
197
+
198
+ # # --------------------------------------
199
+ # # Release
200
+ # # --------------------------------------
201
+
202
+ .PHONY : release-staging
203
+ release-staging : # # Builds and push container images to the staging bucket.
204
+ REGISTRY=$(STAGING_REGISTRY ) $(MAKE ) docker-build-all docker-push-all release-alias-tag
205
+
206
+ .PHONY : release-alias-tag
207
+ release-alias-tag : # Adds the tag to the last build tag. BASE_REF comes from the cloudbuild.yaml
208
+ gcloud container images add-tag $(AGENT_FULL_IMAGE ) :$(TAG ) $(AGENT_FULL_IMAGE ) :$(BASE_REF )
209
+ gcloud container images add-tag $(SERVER_FULL_IMAGE ) :$(TAG ) $(SERVER_FULL_IMAGE ) :$(BASE_REF )
210
+
211
+ # # --------------------------------------
212
+ # # Cleanup / Verification
213
+ # # --------------------------------------
214
+
215
+ .PHONY : clean
105
216
clean :
106
217
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 ./...
0 commit comments