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
+ # # --------------------------------------
30
+ # # Testing
31
+ # # --------------------------------------
32
+
33
+ .PHONY : test
34
+ test :
35
+ go test ./...
36
+
37
+ # # --------------------------------------
38
+ # # Binaries
39
+ # # --------------------------------------
18
40
19
41
bin :
20
42
mkdir -p bin
21
43
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
+
22
68
proto/agent/agent.pb.go : proto/agent/agent.proto
23
69
protoc -I proto proto/agent/agent.proto --go_out=plugins=grpc:proto
24
70
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
29
75
cat hack/go-license-header.txt proto/proxy.pb.go > proto/proxy.licensed.go
30
76
mv proto/proxy.licensed.go proto/proxy.pb.go
31
77
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
+ # # --------------------------------------
52
81
53
82
easy-rsa.tar.gz :
54
83
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:
64
93
curl --retry 10 -L -o cfssljson https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
65
94
chmod +x cfssljson
66
95
96
+ .PHONY : certs
67
97
certs : easy-rsa-master cfssl cfssljson
68
98
# set up easy-rsa
69
99
cp -rf easy-rsa-master/easyrsa3 easy-rsa-master/master
@@ -93,17 +123,93 @@ certs: easy-rsa-master cfssl cfssljson
93
123
cp -r easy-rsa-master/agent/pki/issued certs/agent
94
124
cp easy-rsa-master/agent/pki/ca.crt certs/agent/issued
95
125
96
- gen : proto/agent/agent.pb.go proto/proxy.pb.go
126
+ # # --------------------------------------
127
+ # # Docker
128
+ # # --------------------------------------
97
129
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
99
135
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
101
144
@[ " ${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
+ # # --------------------------------------
104
161
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
105
214
clean :
106
215
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