forked from bottlerocket-os/bottlerocket-test-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
240 lines (205 loc) · 9.84 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
# Set our default to print out help if user has not provided a target
.DEFAULT_GOAL := help
# Determine our root directory path for later use
TOP := $(dir $(firstword $(MAKEFILE_LIST)))
# Variables we update as newer versions are released
BOTTLEROCKET_SDK_VERSION = v0.37.0
BOTTLEROCKET_SDK_ARCH = $(TESTSYS_BUILD_HOST_UNAME_ARCH)
BOTTLEROCKET_TOOLS_VERSION ?= v0.8.0
BUILDER_IMAGE = public.ecr.aws/bottlerocket/bottlerocket-sdk-$(BOTTLEROCKET_SDK_ARCH):$(BOTTLEROCKET_SDK_VERSION)
TOOLS_IMAGE ?= public.ecr.aws/bottlerocket-test-system/bottlerocket-test-tools:$(BOTTLEROCKET_TOOLS_VERSION)
# Capture information about the build host
TESTSYS_BUILD_HOST_UNAME_ARCH=$(shell uname -m)
TESTSYS_BUILD_HOST_GOARCH ?= $(lastword $(subst :, ,$(filter $(TESTSYS_BUILD_HOST_UNAME_ARCH):%,x86_64:amd64 aarch64:arm64)))
TESTSYS_BUILD_HOST_PLATFORM=$(shell uname | tr '[:upper:]' '[:lower:]')
# On some hosts we get an x509 certificate error and need to set GOPROXY to "direct"
TESTSYS_BUILD_GOPROXY ?= direct
# The set of agent images. Add new agent artifacts here when added to the
# project
AGENT_IMAGES = sonobuoy-test-agent ec2-resource-agent eks-resource-agent ecs-resource-agent \
migration-test-agent vsphere-vm-resource-agent vsphere-k8s-cluster-resource-agent \
ecs-test-agent k8s-workload-agent ecs-workload-agent metal-k8s-cluster-resource-agent \
ec2-karpenter-resource-agent
# The set of container images. Add additional artifacts here when added
# to the project
IMAGES = controller $(AGENT_IMAGES)
# Store targets for tagging images
TAG_IMAGES = $(addprefix tag-, $(IMAGES))
# Store targets to push images
PUSH_IMAGES = $(addprefix push-, $(IMAGES))
.PHONY: build example-test-agent example-test-agent-cli example-resource-agent \
images fetch integ-test show-variables cargo-deny tools $(IMAGES) \
tag-images $(TAG_IMAGES) push-images $(PUSH_IMAGES) print-image-names \
help
# Store targets to create the ECR repos
CREATE_REPOS = $(addprefix create-repo-, $(IMAGES))
export DOCKER_BUILDKIT=1
export CARGO_HOME = $(TOP)/.cargo
help: ## display help
@awk 'BEGIN {FS = ":.* ## "; printf "\n\033[1;32mTargets:\033[36m\033[0m\n"} /^[a-zA-Z_-]+:.*? ## / { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
show-variables:
$(info TESTSYS_BUILD_HOST_UNAME_ARCH=$(TESTSYS_BUILD_HOST_UNAME_ARCH))
$(info TESTSYS_BUILD_HOST_GOARCH=$(TESTSYS_BUILD_HOST_GOARCH))
$(info TESTSYS_BUILD_HOST_PLATFORM=$(TESTSYS_BUILD_HOST_PLATFORM))
$(info TESTSYS_BUILD_GOPROXY=$(TESTSYS_BUILD_GOPROXY))
$(info BUILDER_IMAGE=$(BUILDER_IMAGE))
$(info TOOLS_IMAGE=$(TOOLS_IMAGE))
@echo > /dev/null
# Fetches crates from upstream
fetch:
cargo fetch --locked
images: fetch $(IMAGES)
# This target prints the image names. It may be useful to write loops over the names of the containers. For example, we
# might want to check to make sure a repository exists for each image (i.e. maybe a new container has been added to the
# list since we last pushed, so maybe we need to create a new repository).
#
# Example:
# declare -a arr=($(make print-image-names))
# for image_name in "${arr[@]}"
# do
# echo "do something with $image_name"
# done
print-image-names:
$(info $(IMAGES))
@echo > /dev/null
build: fetch ## build, lint, and test the Rust workspace
cargo fmt -- --check
cargo clippy --locked -- -D warnings
cargo build --locked
cargo test --locked
cargo test --features integ --no-run
# We've seen cases where this can fail with a version conflict, so we need to make sure it's working
cargo install --path ./cli --force --locked
# Build the container image for the example test-agent program
example-test-agent: show-variables fetch
docker build $(DOCKER_BUILD_FLAGS) \
--build-arg ARCH="$(TESTSYS_BUILD_HOST_UNAME_ARCH)" \
--build-arg BUILDER_IMAGE="$(BUILDER_IMAGE)" \
--tag "example-test-agent" \
--network none \
-f agent/test-agent/examples/example_test_agent/Dockerfile .
# Build the container image for the example resource-agent program
example-resource-agent: show-variables fetch
docker build $(DOCKER_BUILD_FLAGS) \
--build-arg ARCH="$(TESTSYS_BUILD_HOST_UNAME_ARCH)" \
--build-arg BUILDER_IMAGE="$(BUILDER_IMAGE)" \
--tag "example-resource-agent" \
--network none \
-f agent/resource-agent/examples/example_resource_agent/Dockerfile .
# Build the container image for the example test-agent-cli program
example-test-agent-cli: show-variables fetch
docker build $(DOCKER_BUILD_FLAGS) \
--build-arg ARCH="$(TESTSYS_BUILD_HOST_UNAME_ARCH)" \
--build-arg BUILDER_IMAGE="$(BUILDER_IMAGE)" \
--tag "example-test-agent-cli" \
-f agent/test-agent-cli/examples/example_test_agent_cli/Dockerfile .
# Build the container image for the example duplicator resource-agent program
duplicator-resource-agent: show-variables fetch
docker build $(DOCKER_BUILD_FLAGS) \
--build-arg ARCH="$(TESTSYS_BUILD_HOST_UNAME_ARCH)" \
--build-arg BUILDER_IMAGE="$(BUILDER_IMAGE)" \
--tag "duplicator-resource-agent" \
--network none \
-f agent/resource-agent/examples/duplicator_resource_agent/Dockerfile .
# Build the container image for the testsys controller
controller: show-variables fetch
docker build $(DOCKER_BUILD_FLAGS) \
--build-arg ARCH="$(TESTSYS_BUILD_HOST_UNAME_ARCH)" \
--build-arg BUILDER_IMAGE="$(BUILDER_IMAGE)" \
--build-arg TOOLS_IMAGE="$(TOOLS_IMAGE)" \
--tag "controller" \
-f controller/Dockerfile .
# Build the 3rd-party tools that we use in our agent containers.
tools:
docker build $(DOCKER_BUILD_FLAGS) \
--build-arg ARCH="$(TESTSYS_BUILD_HOST_UNAME_ARCH)" \
--build-arg BUILDER_IMAGE="$(BUILDER_IMAGE)" \
--build-arg GOARCH="$(TESTSYS_BUILD_HOST_GOARCH)" \
--build-arg GOPROXY="$(TESTSYS_BUILD_GOPROXY)" \
--network=host \
-f ./tools/Dockerfile \
-t bottlerocket-test-tools \
-t $(TOOLS_IMAGE) \
--progress=plain \
./tools
# Build the container image for a testsys agent
$(AGENT_IMAGES): show-variables fetch
docker build $(DOCKER_BUILD_FLAGS) \
--build-arg ARCH="$(TESTSYS_BUILD_HOST_UNAME_ARCH)" \
--build-arg BUILDER_IMAGE="$(BUILDER_IMAGE)" \
--build-arg TOOLS_IMAGE="$(TOOLS_IMAGE)" \
--build-arg GOARCH="$(TESTSYS_BUILD_HOST_GOARCH)" \
--build-arg GOPROXY="$(TESTSYS_BUILD_GOPROXY)" \
--network=host \
--target $@ \
--tag $@ \
--progress=plain \
.
# TESTSYS_SELFTEST_SKIP_IMAGE_BUILDS - If this is set to a non-zero-length string, the container images will will be
# expected to already exist and will not be built.
# TESTSYS_SELFTEST_THREADS - The number of tests that cargo will run in parallel. This defaults to 1 since the
# integration tests run Kubernetes clusters in kind which can be resource-intensive
# for some machines.
integ-test: ## run integration tests
integ-test: export TESTSYS_SELFTEST_KIND_PATH := $(shell pwd)/bin/kind
integ-test: TESTSYS_SELFTEST_THREADS ?= 1
integ-test: $(if $(TESTSYS_SELFTEST_SKIP_IMAGE_BUILDS), ,controller example-test-agent duplicator-resource-agent)
$(shell pwd)/bin/download-kind.sh --platform $(TESTSYS_BUILD_HOST_PLATFORM) --goarch ${TESTSYS_BUILD_HOST_GOARCH}
docker tag example-test-agent example-test-agent:integ
docker tag controller controller:integ
docker tag example-test-agent-cli example-test-agent-cli:integ
docker tag duplicator-resource-agent duplicator-resource-agent:integ
cargo test --features integ -- --test-threads=$(TESTSYS_SELFTEST_THREADS)
cargo-deny:
# Install cargo-deny to CARGO_HOME which is set to be .cargo in this repository
cargo install --version 0.9.1 cargo-deny --locked
cargo fetch
cargo deny --all-features --no-default-features check --disable-fetch licenses sources
# Define a target to tag all images
tag-images: $(TAG_IMAGES) ## tag all images
# This defines the TAG_IMAGE variable, extracting the image name from the target name
$(TAG_IMAGES): TAG_IMAGE = $(@:tag-%=%)
$(TAG_IMAGES): check-publish-version check-single-publish-repository
ifeq ($(SINGLE_IMAGE_REPO), true)
docker tag $(TAG_IMAGE) $(if $(PUBLISH_IMAGES_REGISTRY), $(PUBLISH_IMAGES_REGISTRY)/)$(PUBLISH_IMAGES_REPO):$(TAG_IMAGE)-$(PUBLISH_IMAGES_VERSION)
else
docker tag $(TAG_IMAGE) $(if $(PUBLISH_IMAGES_REGISTRY), $(PUBLISH_IMAGES_REGISTRY)/)$(TAG_IMAGE):$(PUBLISH_IMAGES_VERSION)
endif
# Define a target to publish all images
publish-images: $(PUSH_IMAGES) ## publish all images
# This defines the TAG_IMAGE variable, extracting the image name from the target name
$(PUSH_IMAGES): TAG_IMAGE = $(@:push-%=%)
$(PUSH_IMAGES): check-publish-version check-publish-registry check-single-publish-repository
ifeq ($(SINGLE_IMAGE_REPO), true)
docker push $(if $(PUBLISH_IMAGES_REGISTRY), $(PUBLISH_IMAGES_REGISTRY)/)$(PUBLISH_IMAGES_REPO):$(TAG_IMAGE)-$(PUBLISH_IMAGES_VERSION)
else
docker push $(if $(PUBLISH_IMAGES_REGISTRY), $(PUBLISH_IMAGES_REGISTRY)/)$(TAG_IMAGE):$(PUBLISH_IMAGES_VERSION)
endif
check-publish-version:
ifndef PUBLISH_IMAGES_VERSION
$(error PUBLISH_IMAGES_VERSION is undefined)
endif
check-publish-registry:
ifndef PUBLISH_IMAGES_REGISTRY
$(error PUBLISH_IMAGES_REGISTRY is undefined)
endif
check-single-publish-repository:
ifdef PUBLISH_IMAGES_REPO
else ifeq ($(SINGLE_IMAGE_REPO), true)
$(error PUBLISH_IMAGES_REPO is undefined)
endif
mdlint:
docker run --rm -v "$$(pwd)":/workdir ghcr.io/igorshubovych/markdownlint-cli:latest "**/*.md"
# Define a target to create the ECR repos, if they don't exist for the configured credentials
create-repos: $(CREATE_REPOS)
$(CREATE_REPOS): REPO = $(@:create-repo-%=%)
$(CREATE_REPOS):
@if ! 2>&1 1>/dev/null aws ecr describe-repositories --repository-names $(REPO); then \
echo "Creating repository $(REPO)"; \
if ! 2>&1 1>/dev/null aws ecr create-repository --repository-name=$(REPO); then \
echo "Failed to create repository $(REPO)"; exit 1; \
fi; \
echo "Created repository $(REPO)"; \
else \
echo "Repository $(REPO) already exists"; \
fi