-
Notifications
You must be signed in to change notification settings - Fork 52
/
Makefile
298 lines (253 loc) · 9.5 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#
# Copyright 2020 Alexander Vollschwitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
.DEFAULT_GOAL := help
SHELL = /bin/bash
REPO = dregsy
DREGSY_VERSION = $(shell git describe --always --tag --dirty)
SKOPEO_VERSION = v1.14.1 # https://github.com/containers/skopeo/releases
ROOT = $(shell pwd)
BUILD_OUTPUT =_build
BINARIES = $(BUILD_OUTPUT)/bin
ISOLATED_PKG = $(BUILD_OUTPUT)/pkg
ISOLATED_CACHE = $(BUILD_OUTPUT)/cache
GO_IMAGE = docker.io/golang:1.21.6
# use digests of plain golang:{x:y:z} image
GO_IMAGE_DIGEST_amd64 = 5c7c2c9f1a930f937a539ff66587b6947890079470921d62ef1a6ed24395b4b3 # linux/amd64
GO_IMAGE_DIGEST_arm64 = ea3f343e515dd6d4c39e82757c186040f2838ea91e935670433b0849f0813ab5 # linux/arm64/v8
GO_IMAGE_DIGEST_arm = fb3420044a05d239f768b02fde6c987729379b631f44f27c917880fe3d632c7b # linux/arm/v7
GO_IMAGE_DIGEST_386 = 7fd31c31aab449c1cc9a6a4cd498ab20a018de2f64b7ed151bcef3305270dee5 # linux/386
GOOS = $(shell uname -s | tr A-Z a-z)
GOARCH = $(shell ./hack/devenvutil get_architecture)
## makerc
# You need to set the following parameters in configuration file ${DIM}.makerc${NRM}, with every line
# containing a parameter in the form ${ITL}key = value${NRM}:
#
# ${ITL}DREGSY_TEST_DOCKERHOST${NRM} how the ${ITL}Docker${NRM} daemon is set up for testing, i.e. how
# it can be reached from within the test container, which
# uses host networking; defaults to ${DIM}tcp://127.0.0.1:2375${NRM}
#
# ${ITL}DREGSY_TEST_ECR_REGISTRY${NRM} the ECR instance to use
# ${ITL}DREGSY_TEST_ECR_REPO${NRM} the repo to use within the ECR instance;
# defaults to ${DIM}dregsy/test${NRM}
#
# ${ITL}DREGSY_TEST_ECR_PUB_REGISTRY${NRM} the public ECR instance to use
# ${ITL}DREGSY_TEST_ECR_PUB_REPO${NRM} the repo to use within the public ECR instance
#
# ${ITL}AWS_ACCESS_KEY_ID${NRM} credentials for AWS account in which ECR instance for
# ${ITL}AWS_SECRET_ACCESS_KEY${NRM} testing is located; the user associated with these
# credentials needs to have sufficient IAM permissions for
# creating an ECR instance, pulling & pushing from/to it,
# and deleting it
#
# If any of the above settings without a default is missing, ECR tests are skipped!
#
# ${ITL}DREGSY_TEST_GCR_HOST${NRM} the GCR host to use; defaults to ${DIM}eu.gcr.io${NRM}
# ${ITL}DREGSY_TEST_GCR_PROJECT${NRM} the GCP project ID to use with GCR tests
# ${ITL}DREGSY_TEST_GCR_IMAGE${NRM} the image to use; defaults to ${DIM}dregsy/test${NRM}
#
# ${ITL}DREGSY_TEST_GAR_HOST${NRM} the GAR host to use; defaults to ${DIM}europe-west3-docker.pkg.dev${NRM}
# ${ITL}DREGSY_TEST_GAR_PROJECT${NRM} the GCP project ID to use with GAR tests
# ${ITL}DREGSY_TEST_GAR_IMAGE${NRM} the image to use; defaults to ${DIM}dregsy/test${NRM}
#
# ${ITL}GCP_CREDENTIALS${NRM} full path to credentials file for GCP service account
# with which to test GCR/GAR
#
# If any of the above settings without a default is missing, GCR and/or GAR tests are skipped!
#
-include .makerc
## env
# You can set the following environment variables when calling make:
#
# ${ITL}VERBOSE=y${NRM} get detailed output
#
# ${ITL}ISOLATED=y${NRM} when using this with a build or test target, the build/test will be isolated
# in the sense that local caches such as ${DIM}\${GOPATH}/pkg${NRM} and ${DIM}~/.cache${NRM} will
# not be mounted into the container. Instead, according folders underneath
# the configured build folder are used. These folders are removed when
# running ${DIM}make clean${NRM}. That way you can force a clean build/test, where all
# dependencies are retrieved & built inside the container.
#
# ${ITL}CROSS=y${NRM} set this to build binaries for various platforms & architectures
#
# ${ITL}TEST_ALPINE=n${NRM} when using this with the test target, tests will not be performed
# ${ITL}TEST_UBUNTU=n${NRM} for the respective image (${ITL}Alpine${NRM} or ${ITL}Ubuntu${NRM} based)
#
# ${ITL}TEST_OPTS="..."${NRM} any options you would like to pass to the test run, e.g. to select a
# particular test, ${DIM}TEST_OPTS="-run TestE2ESkopeo"${NRM}
#
VERBOSE ?=
ifeq ($(VERBOSE),y)
$(warning ***** starting Makefile for goal(s) "$(MAKECMDGOALS)")
$(warning ***** $(shell date))
MAKEFLAGS += --trace
TEST_OPTS += -v
else
MAKEFLAGS += -s
endif
ifeq ($(MAKECMDGOALS),release)
ISOLATED = y
endif
ISOLATED ?=
ifeq ($(ISOLATED),y)
CACHE_VOLS = -v $(ROOT)/$(ISOLATED_PKG):/go/pkg -v $(ROOT)/$(ISOLATED_CACHE):/.cache
else
CACHE_VOLS = -v $(GOPATH)/pkg:/go/pkg -v $(HOME)/.cache:/.cache
endif
ifeq ($(GCP_CREDENTIALS),)
GCP_CREDS =
else
GCP_CREDS = -v $(GCP_CREDENTIALS):/var/run/secrets/gcp-creds.json -e GOOGLE_APPLICATION_CREDENTIALS=/var/run/secrets/gcp-creds.json
endif
TEST_ALPINE ?= y
TEST_UBUNTU ?= y
TEST_CLEANUP = "127.0.0.1:5000/*/*/*/*" "*/*/*/busybox*" \
"*/cloudrun/container/hello" "registry.hub.docker.com/library/busybox" \
"*/jenkins/jnlp-slave" "*/*/*/hello"
export
#
#
.PHONY: help
help:
# show this help
#
$(call utils, synopsis) | more
.PHONY: release
release: clean rmi dregsy imgdregsy imgtests tests registrydown
# clean, do an isolated build, create container images, and test
#
.PHONY: publish
publish:
# tag & push all container images belonging to a complete release
#
docker tag xelalex/$(REPO):latest-alpine xelalex/$(REPO):$(DREGSY_VERSION)
docker tag xelalex/$(REPO):latest-alpine xelalex/$(REPO):$(DREGSY_VERSION)-alpine
docker tag xelalex/$(REPO):latest-ubuntu xelalex/$(REPO):$(DREGSY_VERSION)-ubuntu
docker push xelalex/$(REPO):latest
docker push xelalex/$(REPO):latest-alpine
docker push xelalex/$(REPO):$(DREGSY_VERSION)
docker push xelalex/$(REPO):$(DREGSY_VERSION)-alpine
docker push xelalex/$(REPO):latest-ubuntu
docker push xelalex/$(REPO):$(DREGSY_VERSION)-ubuntu
.PHONY: dregsy
dregsy: prep
# build the ${ITL}dregsy${NRM} binary
#
rm -f $(BINARIES)/dregsy
ifneq ($(CROSS),y)
$(call utils, build_binary dregsy $(GOOS) $(GOARCH) keep)
else
$(call utils, build_binary dregsy linux amd64 keep)
$(call utils, build_binary dregsy linux arm64)
$(call utils, build_binary dregsy linux arm)
$(call utils, build_binary dregsy linux 386)
endif
unzip -q $(BINARIES)/dregsy_*_linux_amd64.zip -d $(BINARIES) 2>/dev/null \
|| true
cd $(BINARIES); sha256sum dregsy_*.zip > checksums.txt
.PHONY: imgdregsy
imgdregsy:
# build the ${ITL}dregsy${NRM} container images (Alpine and Ubuntu based);
# assumes binary was built
#
echo -e "\nBuilding Alpine-based image...\n"
docker build -t xelalex/$(REPO):latest-alpine \
--build-arg binaries=$(BINARIES) \
--build-arg SKOPEO_VERSION=$(SKOPEO_VERSION) \
-f ./hack/dregsy.alpine.Dockerfile .
# for historical reasons, the `xelalex/dregsy` image is the Alpine image
docker tag xelalex/$(REPO):latest-alpine xelalex/$(REPO):latest
echo -e "\n\nBuilding Ubuntu-based image...\n"
docker build -t xelalex/$(REPO):latest-ubuntu \
--build-arg binaries=$(BINARIES) \
--build-arg SKOPEO_VERSION=$(SKOPEO_VERSION) \
-f ./hack/dregsy.ubuntu.Dockerfile .
echo -e "\nDone\n"
.PHONY: imgtests
imgtests:
# build the container images for running tests (Alpine and Ubuntu based);
# assumes ${ITL}dregsy-...${NRM} images were built
#
echo -e "\nBuilding Alpine-based test image...\n"
docker build -t xelalex/$(REPO)-tests-alpine \
-f ./hack/tests.alpine.Dockerfile .
echo -e "\n\nBuilding Ubuntu-based test image...\n"
docker build -t xelalex/$(REPO)-tests-ubuntu \
-f ./hack/tests.ubuntu.Dockerfile .
echo -e "\nDone\n"
.PHONY: rmi
rmi:
# remove the ${ITL}dregsy${NRM} and testing container images
#
docker rmi -f xelalex/$(REPO):latest
docker rmi -f xelalex/$(REPO):latest-alpine
docker rmi -f xelalex/$(REPO):latest-ubuntu
docker rmi -f xelalex/$(REPO)-tests-alpine
docker rmi -f xelalex/$(REPO)-tests-ubuntu
.PHONY: rmitest
rmitest:
# remove all test-related container images
#
$(call utils, remove_test_images $(TEST_CLEANUP))
.PHONY: tests
tests: prep
# run tests; assumes test images were built; local ${ITL}Docker${NRM} registry gets
# (re-)started on localhost:5000
#
ifeq (,$(wildcard .makerc))
$(warning ***** Missing .makerc! Some tests may be skipped or fail!)
endif
ifeq ($(TEST_ALPINE),y)
$(call utils, remove_test_images $(TEST_CLEANUP)) > /dev/null
docker image prune --force
$(call utils, registry_restart)
$(call utils, run_tests alpine)
endif
ifeq ($(TEST_UBUNTU),y)
$(call utils, remove_test_images $(TEST_CLEANUP)) > /dev/null
docker image prune --force
$(call utils, registry_restart)
$(call utils, run_tests ubuntu)
endif
.PHONY: registryup
registryup:
# start local ${ITL}Docker${NRM} registry for running tests
#
$(call utils, registry_up)
.PHONY: registrydown
registrydown:
# stop local ${ITL}Docker${NRM} registry
#
$(call utils, registry_down) || true
.PHONY: registryrestart
registryrestart:
# restart local ${ITL}Docker${NRM} registry
#
$(call utils, registry_restart)
.PHONY: clean
clean:
# remove all build artifacts, including isolation caches
#
[ ! -d $(BUILD_OUTPUT) ] || chmod -R u+w $(BUILD_OUTPUT)
rm -rf $(BUILD_OUTPUT)/*
.PHONY: prep
prep:
# prepare required directories
#
mkdir -p $(BUILD_OUTPUT) $(BINARIES) $(ISOLATED_PKG) $(ISOLATED_CACHE)
#
# helper functions
#
utils = ./hack/devenvutil $(1)