forked from bottlerocket-os/bottlerocket-test-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
179 lines (152 loc) · 7.26 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
TOP := $(dir $(firstword $(MAKEFILE_LIST)))
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
BOTTLEROCKET_SDK_VERSION = v0.26.0
BOTTLEROCKET_SDK_ARCH = $(TESTSYS_BUILD_HOST_UNAME_ARCH)
BOTTLEROCKET_TOOLS_VERSION ?= v0.1.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)
IMAGES = controller sonobuoy-test-agent ec2-resource-agent eks-resource-agent ecs-resource-agent \
migration-test-agent vsphere-vm-resource-agent ecs-test-agent
# Store targets for tagging images
TAG_IMAGES = $(addprefix tag-, $(IMAGES))
# Store targets to push images
PUSH_IMAGES = $(addprefix push-, $(IMAGES))
.PHONY: build sdk-openssl example-test-agent example-resource-agent \
images fetch integ-test show-variables cargo-deny tools $(IMAGES) \
tag-images $(TAG_IMAGES) push-images $(PUSH_IMAGES) print-image-names
export DOCKER_BUILDKIT=1
export CARGO_HOME = $(TOP)/.cargo
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
# Builds, Lints and Tests the Rust workspace
build: fetch
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
# 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 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
eks-resource-agent ec2-resource-agent ecs-resource-agent vsphere-vm-resource-agent sonobuoy-test-agent migration-test-agent ecs-test-agent: 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: 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 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)
# This defines the TAG_IMAGE variable, extracting the image name from the target name
$(TAG_IMAGES): TAG_IMAGE = $(@:tag-%=%)
$(TAG_IMAGES): check-publish-version
docker tag $(TAG_IMAGE) $(if $(PUBLISH_IMAGES_REGISTRY), $(PUBLISH_IMAGES_REGISTRY)/)$(TAG_IMAGE):$(PUBLISH_IMAGES_VERSION)
# Define a target to tag all images
publish-images: $(PUSH_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
docker push $(if $(PUBLISH_IMAGES_REGISTRY), $(PUBLISH_IMAGES_REGISTRY)/)$(TAG_IMAGE):$(PUBLISH_IMAGES_VERSION)
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