forked from openshift/assisted-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
303 lines (233 loc) · 13 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
299
300
301
302
303
NAMESPACE := $(or ${NAMESPACE},assisted-installer)
PWD = $(shell pwd)
UID = $(shell id -u)
BUILD_FOLDER = $(PWD)/build/$(NAMESPACE)
ROOT_DIR = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
TARGET := $(or ${TARGET},minikube)
PROFILE := $(or $(PROFILE),minikube)
KUBECTL=kubectl -n $(NAMESPACE)
ifeq ($(TARGET), minikube)
define get_service
minikube -p $(PROFILE) service --url $(1) -n $(NAMESPACE) | sed 's/http:\/\///g'
endef # get_service
else
define get_service
kubectl get service $(1) -n $(NAMESPACE) | grep $(1) | awk '{print $$4 ":" $$5}' | \
awk '{split($$0,a,":"); print a[1] ":" a[2]}'
endef # get_service
endif # TARGET
SERVICE := $(or ${SERVICE},quay.io/ocpmetal/assisted-service:latest)
SERVICE_ONPREM := $(or ${SERVICE_ONPREM},quay.io/ocpmetal/assisted-service-onprem:latest)
ISO_CREATION := $(or ${ISO_CREATION},quay.io/ocpmetal/assisted-iso-create:latest)
DUMMY_IGNITION := $(or ${DUMMY_IGNITION},minikube-local-registry/ignition-dummy-generator:minikube-test)
GIT_REVISION := $(shell git rev-parse HEAD)
APPLY_NAMESPACE := $(or ${APPLY_NAMESPACE},True)
ROUTE53_SECRET := ${ROUTE53_SECRET}
OCM_CLIENT_ID := ${OCM_CLIENT_ID}
OCM_CLIENT_SECRET := ${OCM_CLIENT_SECRET}
ENABLE_AUTH := $(or ${ENABLE_AUTH},False)
DELETE_PVC := $(or ${DELETE_PVC},False)
ISO_CREATION_DOCKER_DAEMON_PULL_STRING := $(or ${ISO_CREATION_DOCKER_DAEMON_PULL_STRING},docker-daemon:${ISO_CREATION})
ASSISTED_SERVICE_DOCKER_DAEMON_PULL_STRING := $(or ${ASSISTED_SERVICE_DOCKER_DAEMON_PULL_STRING},docker-daemon:${SERVICE})
# We decided to have an option to change replicas count only while running in minikube
# That line is checking if we run on minikube
# check if SERVICE_REPLICAS_COUNT was set and if yes change default value to required one
REPLICAS_COUNT = $(shell if ! [ "${TARGET}" = "minikube" ];then echo 3; else echo $(or ${SERVICE_REPLICAS_COUNT},3);fi)
ifdef INSTALLATION_TIMEOUT
INSTALLATION_TIMEOUT_FLAG = --installation-timeout $(INSTALLATION_TIMEOUT)
endif
# define focus flag for test so users can run individual tests or suites
ifdef FOCUS
GINKGO_FOCUS_FLAG = -ginkgo.focus=${FOCUS}
endif
all: build
_pre_commit_hooks:
@-cp ${ROOT_DIR}/tools/check-commit-message.sh ${ROOT_DIR}/.git/hooks/commit-msg
${ROOT_DIR}/tools/check-commits.sh
lint: _pre_commit_hooks
golangci-lint run -v
$(BUILD_FOLDER):
mkdir -p $(BUILD_FOLDER)
format:
goimports -w -l cmd/ internal/ subsystem/ pkg/ assisted-iso-create/ dummy-ignition/
gofmt -w -l cmd/ internal/ subsystem/ pkg/ assisted-iso-create/ dummy-ignition/
############
# Generate #
############
generate:
go generate $(shell go list ./... | grep -v 'assisted-service/models\|assisted-service/client\|assisted-service/restapi')
generate-from-swagger: generate-go-client generate-go-server
generate-go-server:
rm -rf restapi
docker run -u $(UID):$(UID) -v $(PWD):$(PWD):rw,Z -v /etc/passwd:/etc/passwd -w $(PWD) \
quay.io/goswagger/swagger:v0.25.0 generate server --template=stratoscale -f swagger.yaml \
--template-dir=/templates/contrib
generate-go-client:
rm -rf client models
docker run -u $(UID):$(UID) -v $(PWD):$(PWD):rw,Z -v /etc/passwd:/etc/passwd -w $(PWD) \
quay.io/goswagger/swagger:v0.25.0 generate client --template=stratoscale -f swagger.yaml \
--template-dir=/templates/contrib
generate-python-client: $(BUILD_FOLDER)
rm -rf $(BUILD_FOLDER)/assisted-service-client*
docker run --rm -u ${UID} --entrypoint /bin/sh \
-v $(BUILD_FOLDER):/local:Z \
-v $(ROOT_DIR)/swagger.yaml:/swagger.yaml:ro,Z \
-v $(ROOT_DIR)/tools/generate_python_client.sh:/script.sh:ro,Z \
-e SWAGGER_FILE=/swagger.yaml -e OUTPUT=/local/assisted-service-client/ \
swaggerapi/swagger-codegen-cli:2.4.15 /script.sh
cd $(BUILD_FOLDER)/assisted-service-client/ && python3 setup.py sdist --dist-dir $(BUILD_FOLDER)
generate-keys: $(BUILD_FOLDER)
cd tools && go run auth_keys_generator.go -keys-dir=$(BUILD_FOLDER)
##################
# Build & Update #
##################
.PHONY: build
build: lint unit-test build-minimal build-iso-generator
build-minimal: $(BUILD_FOLDER)
CGO_ENABLED=0 go build -o $(BUILD_FOLDER)/assisted-service cmd/main.go
build-iso-generator: $(BUILD_FOLDER)
CGO_ENABLED=0 go build -o $(BUILD_FOLDER)/assisted-iso-create assisted-iso-create/main.go
build-dummy-ignition: $(BUILD_FOLDER)
CGO_ENABLED=0 go build -o $(BUILD_FOLDER)/dummy-ignition dummy-ignition/main.go
build-onprem-dependencies:
skipper make build-image build-assisted-iso-generator-image
build-onprem: build-onprem-dependencies
podman pull $(ISO_CREATION_DOCKER_DAEMON_PULL_STRING)
podman pull $(ASSISTED_SERVICE_DOCKER_DAEMON_PULL_STRING)
GIT_REVISION=${GIT_REVISION} podman build --network=host --build-arg GIT_REVISION \
-f Dockerfile.assisted-service-onprem . -t $(SERVICE_ONPREM)
build-image: build
GIT_REVISION=${GIT_REVISION} docker build --network=host --build-arg GIT_REVISION \
-f Dockerfile.assisted-service . -t $(SERVICE)
build-assisted-iso-generator-image: lint unit-test build-minimal build-minimal-assisted-iso-generator-image
build-minimal-assisted-iso-generator-image: build-iso-generator
GIT_REVISION=${GIT_REVISION} docker build --network=host --build-arg GIT_REVISION --build-arg NAMESPACE=$(NAMESPACE) \
-f Dockerfile.assisted-iso-create . -t $(ISO_CREATION)
build-dummy-ignition-image: build-dummy-ignition
docker build --network=host --build-arg NAMESPACE=$(NAMESPACE) -f Dockerfile.ignition-dummy . -t ${DUMMY_IGNITION}
update: build-image
docker push $(SERVICE)
update-minimal: build-minimal
GIT_REVISION=${GIT_REVISION} docker build --network=host --build-arg GIT_REVISION \
-f Dockerfile.assisted-service . -t $(SERVICE)
update-minikube: build build-dummy-ignition
eval $$(SHELL=$${SHELL:-/bin/sh} minikube -p $(PROFILE) docker-env) && \
GIT_REVISION=${GIT_REVISION} docker build --network=host --build-arg GIT_REVISION \
-f Dockerfile.assisted-service . -t $(SERVICE) && docker build --network=host -f Dockerfile.ignition-dummy . -t ${DUMMY_IGNITION} \
&& docker build --network=host --build-arg GIT_REVISION -f Dockerfile.assisted-iso-create . -t $(ISO_CREATION)
define publish_image
docker tag ${1} ${2}
docker push ${2}
endef # publish_image
publish:
$(call publish_image,${SERVICE},quay.io/ocpmetal/assisted-service:latest)
$(call publish_image,${SERVICE},quay.io/ocpmetal/assisted-service:${GIT_REVISION})
$(call publish_image,${ISO_CREATION},quay.io/ocpmetal/assisted-iso-create:latest)
$(call publish_image,${ISO_CREATION},quay.io/ocpmetal/assisted-iso-create:${GIT_REVISION})
##########
# Deploy #
##########
ifdef DEPLOY_TAG
DEPLOY_TAG_OPTION = --deploy-tag "$(DEPLOY_TAG)"
else ifdef DEPLOY_MANIFEST_PATH
DEPLOY_TAG_OPTION = --deploy-manifest-path "$(DEPLOY_MANIFEST_PATH)"
else ifdef DEPLOY_MANIFEST_TAG
DEPLOY_TAG_OPTION = --deploy-manifest-tag "$(DEPLOY_MANIFEST_TAG)"
endif
deploy-all: $(BUILD_FOLDER) deploy-namespace deploy-postgres deploy-s3 deploy-ocm-secret deploy-route53 deploy-service
echo "Deployment done"
deploy-ui: deploy-namespace
python3 ./tools/deploy_ui.py --target "$(TARGET)" --domain "$(INGRESS_DOMAIN)" --namespace "$(NAMESPACE)" --profile "$(PROFILE)" $(DEPLOY_TAG_OPTION)
deploy-namespace: $(BUILD_FOLDER)
python3 ./tools/deploy_namespace.py --deploy-namespace $(APPLY_NAMESPACE) --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)"
deploy-s3-secret:
python3 ./tools/deploy_scality_configmap.py --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)"
deploy-s3: deploy-namespace
python3 ./tools/deploy_s3.py --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)"
sleep 5; # wait for service to get an address
make deploy-s3-secret
deploy-route53: deploy-namespace
python3 ./tools/deploy_route53.py --secret "$(ROUTE53_SECRET)" --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)"
deploy-ocm-secret: deploy-namespace
python3 ./tools/deploy_sso_secret.py --secret "$(OCM_CLIENT_SECRET)" --id "$(OCM_CLIENT_ID)" --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)"
deploy-inventory-service-file: deploy-namespace
python3 ./tools/deploy_inventory_service.py --target "$(TARGET)" --domain "$(INGRESS_DOMAIN)" --namespace "$(NAMESPACE)" --profile "$(PROFILE)"
sleep 5; # wait for service to get an address
deploy-service-requirements: deploy-namespace deploy-inventory-service-file
python3 ./tools/deploy_assisted_installer_configmap.py --target "$(TARGET)" --domain "$(INGRESS_DOMAIN)" \
--base-dns-domains "$(BASE_DNS_DOMAINS)" --namespace "$(NAMESPACE)" --profile "$(PROFILE)" \
$(INSTALLATION_TIMEOUT_FLAG) $(DEPLOY_TAG_OPTION) --enable-auth "$(ENABLE_AUTH)" $(TEST_FLAGS)
deploy-service: deploy-namespace deploy-service-requirements deploy-role
python3 ./tools/deploy_assisted_installer.py $(DEPLOY_TAG_OPTION) --namespace "$(NAMESPACE)" \
--profile "$(PROFILE)" $(TEST_FLAGS) --target "$(TARGET)" --replicas-count $(REPLICAS_COUNT)
python3 ./tools/wait_for_assisted_service.py --target $(TARGET) --namespace "$(NAMESPACE)" \
--profile "$(PROFILE)" --domain "$(INGRESS_DOMAIN)"
deploy-role: deploy-namespace
python3 ./tools/deploy_role.py --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)"
deploy-postgres: deploy-namespace
python3 ./tools/deploy_postgres.py --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)"
jenkins-deploy-for-subsystem: generate-keys build-dummy-ignition-image
export TEST_FLAGS=--subsystem-test && export ENABLE_AUTH="True" && export DUMMY_IGNITION=${DUMMY_IGNITION} && $(MAKE) deploy-wiremock deploy-all
deploy-test: generate-keys
export SERVICE=minikube-local-registry/assisted-service:minikube-test && export TEST_FLAGS=--subsystem-test && export ENABLE_AUTH="True" \
&& export DUMMY_IGNITION=${DUMMY_IGNITION} && ISO_CREATION=minikube-local-registry/assisted-iso-create:minikube-test \
$(MAKE) update-minikube deploy-wiremock deploy-all
deploy-onprem:
podman pod create --name assisted-installer -p 5432,8000,8090,8080
podman run -dt --pod assisted-installer --env-file onprem-environment --name db quay.io/ocpmetal/postgresql-12-centos7
podman run -dt --pod assisted-installer --env-file onprem-environment --user assisted-installer --restart always --name installer $(SERVICE_ONPREM)
podman run -dt --pod assisted-installer --env-file onprem-environment --pull always -v $(PWD)/deploy/ui/nginx.conf:/opt/bitnami/nginx/conf/server_blocks/nginx.conf:z --name ui quay.io/ocpmetal/ocp-metal-ui:latest
########
# Test #
########
subsystem-run: test subsystem-clean
test:
INVENTORY=$(shell $(call get_service,assisted-service) | sed 's/http:\/\///g') \
DB_HOST=$(shell $(call get_service,postgres) | sed 's/http:\/\///g' | cut -d ":" -f 1) \
DB_PORT=$(shell $(call get_service,postgres) | sed 's/http:\/\///g' | cut -d ":" -f 2) \
OCM_HOST=$(shell $(call get_service,wiremock) | sed 's/http:\/\///g') \
TEST_TOKEN="$(shell cat $(BUILD_FOLDER)/auth-tokenString)" \
TEST_TOKEN_ADMIN="$(shell cat $(BUILD_FOLDER)/auth-tokenAdminString)" \
TEST_TOKEN_UNALLOWED="$(shell cat $(BUILD_FOLDER)/auth-tokenUnallowedString)" \
ENABLE_AUTH="true" \
go test -v ./subsystem/... -count=1 $(GINKGO_FOCUS_FLAG) -ginkgo.v -timeout 30m
deploy-wiremock: deploy-namespace
python3 ./tools/deploy_wiremock.py --target $(TARGET) --namespace "$(NAMESPACE)" --profile "$(PROFILE)"
deploy-olm: deploy-namespace
python3 ./tools/deploy_olm.py --target $(TARGET) --profile $(PROFILE)
deploy-prometheus: $(BUILD_FOLDER) deploy-namespace
python3 ./tools/deploy_prometheus.py --target $(TARGET) --namespace "$(NAMESPACE)" --profile "$(PROFILE)"
deploy-grafana: $(BUILD_FOLDER)
python3 ./tools/deploy_grafana.py --target $(TARGET) --namespace "$(NAMESPACE)" --profile "$(PROFILE)"
deploy-monitoring: deploy-olm deploy-prometheus deploy-grafana
unit-test:
docker kill postgres || true
sleep 3
docker run -d --rm --name postgres -e POSTGRES_PASSWORD=admin -e POSTGRES_USER=admin -p 127.0.0.1:5432:5432 postgres:12.3-alpine -c 'max_connections=10000'
until PGPASSWORD=admin pg_isready -U admin --dbname postgres --host 127.0.0.1 --port 5432; do sleep 1; done
SKIP_UT_DB=1 go test -v $(or ${TEST}, ${TEST}, $(shell go list ./... | grep -v subsystem)) $(GINKGO_FOCUS_FLAG) -cover || (docker kill postgres && /bin/false)
docker kill postgres
test-onprem:
INVENTORY=127.0.0.1:8090 \
INVENTORY=127.0.0.1:8090 \
DB_HOST=127.0.0.1 \
DB_PORT=5432 \
go test -v ./subsystem/... -count=1 $(GINKGO_FOCUS_FLAG) -ginkgo.v -timeout 30m
#########
# Clean #
#########
clear-all: clean subsystem-clean clear-deployment
clean:
-rm -rf $(BUILD_FOLDER)
subsystem-clean:
-$(KUBECTL) get pod -o name | grep dummyimage | xargs -r $(KUBECTL) delete 1> /dev/null || true
-$(KUBECTL) get pod -o name | grep createimage | xargs -r $(KUBECTL) delete 1> /dev/null || true
-$(KUBECTL) get pod -o name | grep ignition-generator | xargs -r $(KUBECTL) delete 1> /dev/null || true
clear-deployment:
-python3 ./tools/clear_deployment.py --delete-namespace $(APPLY_NAMESPACE) --delete-pvc $(DELETE_PVC) --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)" || true
clean-onprem:
podman pod rm -f -i assisted-installer
delete-minikube-profile:
minikube delete -p $(PROFILE)
delete-all-minikube-profiles:
minikube delete --all