-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathMakefile
More file actions
380 lines (324 loc) · 15.2 KB
/
Makefile
File metadata and controls
380 lines (324 loc) · 15.2 KB
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
SHELL = /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
# Load environment variables from ods-core.env file
include ../ods-configuration/ods-core.env
export $(shell sed 's/=.*//' ../ods-configuration/ods-core.env)
# Load environment variables from ods-core.ods-api-service.env file
include ../ods-configuration/ods-core.ods-api-service.env
export $(shell sed 's/=.*//' ../ods-configuration/ods-core.ods-api-service.env)
INSECURE := false
INSECURE_FLAG :=
ifeq ($(INSECURE), $(filter $(INSECURE), true yes))
INSECURE_FLAG = --insecure
endif
# ODS API Service configuration files
ODS_CONFIGURATION_DIR := ../ods-configuration
ODS_CONFIGURATION_FULL_PATH := $(abspath $(ODS_CONFIGURATION_DIR))
ODS_API_SERVICE_DATABASE_REPO := $(ODS_API_SERVICE_DIR:-.../ods-api-service)
# REPOSITORIES
## Prepare Bitbucket repos (create project and repos).
prepare-bitbucket-repos:
cd ods-setup && ./bitbucket.sh $(INSECURE_FLAG)
.PHONY: prepare-bitbucket-repos
## Push local repos to Bitbucket.
push-local-repos:
cd scripts && ./push-local-repos.sh
.PHONY: push-local-repos
## Set ODS_IMAGE_TAG ref in Jenkins Shared Library repo on Bitbucket.
set-shared-library-ref:
cd scripts && ./set-shared-library-ref.sh
.PHONY: set-shared-library-ref
# CONFIG
## Update local sample config sample and run check against local actual config.
prepare-config:
cd ods-setup && ./config.sh
.PHONY: prepare-config
# ODS SETUP
## Setup central "ods" project.
install-ods-project:
cd ods-setup && ./setup-ods-project.sh --namespace $(ODS_NAMESPACE) --reveal-secrets
# AQUA SETUP
## Setup the needed configuration of Aqua for ODS base in Config Maps in the ODS namespace.
setup-aqua-configmap:
cd ods-setup && ./setup-aqua-configmap.sh --namespace $(ODS_NAMESPACE) --reveal-secrets
# JENKINS
## Install or update Jenkins resources.
install-jenkins: apply-jenkins-build start-jenkins-build apply-jenkins-deploy
.PHONY: install-jenkins
## Update OpenShift resources related to Jenkins images.
apply-jenkins-build:
cd jenkins/ocp-config/build && tailor apply --namespace $(ODS_NAMESPACE)
.PHONY: apply-jenkins-build
## Install a jenkins instance in the ods namespace (needed by the provisioning app)
apply-jenkins-deploy:
cd jenkins/ocp-config/deploy && tailor apply --namespace $(ODS_NAMESPACE) --selector template=ods-jenkins-template
.PHONY: apply-jenkins-deploy
## Start build of all Jenkins BuildConfig resources.
start-jenkins-build: start-jenkins-build-master start-jenkins-build-agent-base start-jenkins-build-webhook-proxy
.PHONY: jenkins-build
## Start build of BuildConfig "jenkins-master".
start-jenkins-build-master:
ocp-scripts/start-and-follow-build.sh --namespace $(ODS_NAMESPACE) --build-config jenkins-master
.PHONY: start-jenkins-build-master
## Start build of BuildConfig "jenkins-agent-base".
start-jenkins-build-agent-base:
ocp-scripts/start-and-follow-build.sh --namespace $(ODS_NAMESPACE) --build-config jenkins-agent-base
.PHONY: start-jenkins-build-agent-base
## Start build of BuildConfig "jenkins-webhook-proxy".
start-jenkins-build-webhook-proxy:
ocp-scripts/start-and-follow-build.sh --namespace $(ODS_NAMESPACE) --build-config jenkins-webhook-proxy
.PHONY: start-jenkins-build-webhook-proxy
# PROVISIONING APP
## Install the provisioning app.
install-provisioning-app: apply-provisioning-app-build start-provisioning-app-build apply-provisioning-app-deploy
.PHONY: install-provisioning-app
## Update OpenShift resources related to the Provisioning App image.
apply-provisioning-app-build:
cd ods-provisioning-app/ocp-config && tailor apply --namespace $(ODS_NAMESPACE) is,bc
.PHONY: apply-provisioning-app-build
## Start build of BuildConfig "ods-provisioning-app".
start-provisioning-app-build:
ocp-scripts/start-and-follow-build.sh --namespace $(ODS_NAMESPACE) --build-config ods-provisioning-app
.PHONY: start-provisioning-app-build
## Update OpenShift resources related to the Provisioning App service.
apply-provisioning-app-deploy:
cd ods-provisioning-app/ocp-config && tailor apply --namespace $(ODS_NAMESPACE) --exclude is,bc
.PHONY: apply-provisioning-app-deploy
# DOCUMENT GENERATION SERVICE IMAGE
## Install the documentation generation image.
install-doc-gen: apply-doc-gen-build start-doc-gen-build
.PHONY: install-doc-gen
## Update OpenShift resources related to the Document Generation image.
apply-doc-gen-build:
cd ods-document-generation-svc/ocp-config && tailor apply --namespace $(ODS_NAMESPACE)
.PHONY: apply-doc-gen-build
## Start build of BuildConfig "ods-doc-gen-svc".
start-doc-gen-build:
ocp-scripts/start-and-follow-build.sh --namespace $(ODS_NAMESPACE) --build-config ods-doc-gen-svc
.PHONY: start-doc-gen-build
# SONARQUBE
## Install or update SonarQube.
install-sonarqube: apply-sonarqube-chart start-sonarqube-build configure-sonarqube
.PHONY: install-sonarqube
## Apply OpenShift resources related to the SonarQube.
apply-sonarqube-chart:
cd sonarqube/chart && envsubst < values.yaml.template > values.yaml && helm upgrade --install --namespace $(ODS_NAMESPACE) sonarqube . && rm values.yaml
.PHONY: apply-sonarqube-build
## Start build of BuildConfig "sonarqube".
start-sonarqube-build:
ocp-scripts/start-and-follow-build.sh --namespace $(ODS_NAMESPACE) --build-config sonarqube && ocp-scripts/start-and-follow-build.sh --namespace $(ODS_NAMESPACE) --build-config sonarqube-postgresql
@echo "Visit $(SONARQUBE_URL)/setup to see if any update actions need to be taken."
.PHONY: start-sonarqube-build
## Configure SonarQube service.
configure-sonarqube:
cd sonarqube && ./configure.sh --sonarqube=$(SONARQUBE_URL) --database-config=true $(INSECURE_FLAG)
.PHONY: configure-sonarqube
# NEXUS
## Install or update Nexus.
install-nexus: apply-nexus-chart start-nexus-build
.PHONY: nexus
## Apply OpenShift resources related to the Nexus.
apply-nexus-chart:
cd nexus/chart && envsubst < values.yaml.template > values.yaml && helm upgrade --install --namespace $(ODS_NAMESPACE) nexus . && rm values.yaml
.PHONY: apply-nexus-chart
## Start build of BuildConfig "nexus".
start-nexus-build:
ocp-scripts/start-and-follow-build.sh --namespace $(ODS_NAMESPACE) --build-config nexus
.PHONY: start-nexus-build
## Configure Nexus service.
configure-nexus:
cd nexus && ./configure.sh --namespace $(ODS_NAMESPACE) --nexus=$(NEXUS_URL) --admin-password=$(NEXUS_ADMIN_PASSWORD) $(INSECURE_FLAG)
.PHONY: configure-nexus
### configure-nexus is not part of install-nexus because it is not idempotent yet.
# OPENTELEMETRY COLLECTOR
## Install or update Opentelemetry Collector.
install-opentelemetry-collector: apply-opentelemetry-collector-chart start-opentelemetry-collector-build
.PHONY: opentelemetry-collector
## Apply OpenShift resources related to the Opentelemetry Collector.
apply-opentelemetry-collector-chart:
cd opentelemetry-collector/chart && envsubst < values.yaml.template > values.yaml && helm upgrade --install --namespace $(ODS_NAMESPACE) opentelemetry-collector . && rm values.yaml
.PHONY: apply-opentelemetry-collector-chart
## Start build of BuildConfig "Opentelemetry Collector".
start-opentelemetry-collector-build:
ocp-scripts/start-and-follow-build.sh --namespace $(ODS_NAMESPACE) --build-config opentelemetry-collector
.PHONY: start-opentelemetry-collector-build
####################
# ODS API SERVICE
####################
## Install or update Ods API Service.
check-configuration-defined:
ifndef env
$(error "Environment variable 'env' is not defined. Please set it to the desired environment (e.g., dev, staging, prod) before running this target.")
endif
@if [ ! -d "../ods-api-service" ]; then \
echo "Error: ods-api-service directory not found at ../ods-api-service"; \
exit 1; \
fi
@if [ ! -d "$(ODS_CONFIGURATION_FULL_PATH)" ]; then \
echo "Error: ods-configuration directory not found at $(ODS_CONFIGURATION_FULL_PATH)"; \
exit 1; \
fi
@if [ ! -f "$(ODS_CONFIGURATION_FULL_PATH)/ods-core.values.yaml" ]; then \
echo "Error: File not found: $(ODS_CONFIGURATION_FULL_PATH)/ods-core.values.yaml"; \
exit 1; \
fi
@if [ ! -f "$(ODS_CONFIGURATION_FULL_PATH)/ods-core.secrets.enc.yaml" ]; then \
echo "Error: File not found: $(ODS_CONFIGURATION_FULL_PATH)/ods-core.secrets.enc.yaml"; \
exit 1; \
fi
@if [ ! -f "$(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/values.yaml" ]; then \
echo "Error: File not found: $(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/values.yaml"; \
exit 1; \
fi
@if [ ! -f "$(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/secrets.enc.yaml" ]; then \
echo "Error: File not found: $(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/secrets.enc.yaml"; \
exit 1; \
fi
@if [ ! -f "$(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/$(env)/values.$(env).yaml" ]; then \
echo "Error: File not found: $(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/$(env)/values.$(env).yaml"; \
exit 1; \
fi
@if [ ! -f "$(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/$(env)/secrets.$(env).enc.yaml" ]; then \
echo "Error: File not found: $(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/$(env)/secrets.$(env).enc.yaml"; \
exit 1; \
fi
@echo "All validation checks passed!"
.PHONY: check-configuration-defined
install-ods-api-service: \
check-configuration-defined \
start-ods-api-service-build \
start-ods-api-service-database-build \
apply-ods-api-service-database-chart \
configure-ods-api-service-database-backup \
ods-api-service-db-migration \
apply-ods-api-service-chart
.PHONY: ods-api-service
## Start build of BuildConfig "Ods API Service".
start-ods-api-service-build:
cd ods-api-service/build-config && oc process -f template-ods-api-service.yaml \
-p ODS_NAMESPACE=$(ODS_NAMESPACE) \
-p ODS_IMAGE_TAG=$(ODS_IMAGE_TAG) \
-p BITBUCKET_URL=$(BITBUCKET_URL) \
-p ODS_BITBUCKET_PROJECT=$(ODS_BITBUCKET_PROJECT) \
-p ODS_GIT_REF=$(ODS_GIT_REF) \
-p ODS_API_SERVICE_VERSION=$(ODS_API_SERVICE_VERSION) | oc apply --namespace $(ODS_NAMESPACE) -f -
ocp-scripts/start-and-follow-build.sh --namespace $(ODS_NAMESPACE) --build-config ods-api-service
.PHONY: start-ods-api-service-build
## Start build of BuildConfig "Ods API Service Database".
start-ods-api-service-database-build:
cd ods-api-service-database/build-config && oc process -f template-postgresql.yaml \
-p ODS_NAMESPACE=$(ODS_NAMESPACE) \
-p BITBUCKET_URL=$(BITBUCKET_URL) \
-p ODS_BITBUCKET_PROJECT=$(ODS_BITBUCKET_PROJECT) \
-p ODS_GIT_REF=$(ODS_GIT_REF) \
-p ODS_DATABASE_VERSION=$(ODS_DATABASE_VERSION) | oc apply --namespace $(ODS_NAMESPACE) -f -
ocp-scripts/start-and-follow-build.sh --namespace $(ODS_NAMESPACE) --build-config ods-api-service-postgresql
.PHONY: start-ods-api-service-database-build
## Apply OpenShift resources related to the Ods API Service.
apply-ods-api-service-chart: check-configuration-defined
cd ods-api-service/chart && \
helm secrets upgrade --install --namespace $(ODS_NAMESPACE) \
-f $(ODS_CONFIGURATION_FULL_PATH)/ods-core.values.yaml \
-f $(ODS_CONFIGURATION_FULL_PATH)/ods-core.secrets.enc.yaml \
-f $(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/values.yaml \
-f $(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/secrets.enc.yaml \
-f $(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/$(env)/values.$(env).yaml \
-f $(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/$(env)/secrets.$(env).enc.yaml \
--set projectId=$(ODS_NAMESPACE) \
--set appSelector=app=ods-api-service \
--set registry=$(DOCKER_REGISTRY) \
--set componentId=ods-api-service \
--set global.projectId=$(ODS_NAMESPACE) \
--set global.appSelector=app=ods-api-service \
--set global.registry=$(DOCKER_REGISTRY) \
--set global.componentId=ods-api-service \
--set imageNamespace=$(ODS_NAMESPACE) \
--set imageTag=$(ODS_API_SERVICE_VERSION) \
--set global.imageNamespace=$(ODS_NAMESPACE) \
--set global.imageTag=$(ODS_API_SERVICE_VERSION) \
--set ODS_OPENSHIFT_APP_DOMAIN=$(OPENSHIFT_APPS_BASEDOMAIN) \
ods-api-service .
.PHONY: apply-ods-api-service-chart
## Apply OpenShift resources related to the Ods API Service Database.
apply-ods-api-service-database-chart: check-configuration-defined
cd ods-api-service-database/chart && \
helm secrets upgrade --install --namespace $(ODS_NAMESPACE) \
-f $(ODS_CONFIGURATION_FULL_PATH)/ods-core.values.yaml \
-f $(ODS_CONFIGURATION_FULL_PATH)/ods-core.secrets.enc.yaml \
-f $(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/values.yaml \
-f $(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/secrets.enc.yaml \
-f $(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/$(env)/values.$(env).yaml \
-f $(ODS_CONFIGURATION_FULL_PATH)/ods-api-service/$(env)/secrets.$(env).enc.yaml \
--set projectId=$(ODS_NAMESPACE) \
--set appSelector=app=ods-api-service \
--set registry=$(DOCKER_REGISTRY) \
--set componentId=ods-api-service \
--set global.projectId=$(ODS_NAMESPACE) \
--set global.appSelector=app=ods-api-service \
--set global.registry=$(DOCKER_REGISTRY) \
--set global.componentId=ods-api-service \
--set imageNamespace=$(ODS_NAMESPACE) \
--set imageTag=$(ODS_DATABASE_VERSION) \
--set global.imageNamespace=$(ODS_NAMESPACE) \
--set global.imageTag=$(ODS_DATABASE_VERSION) \
--set ODS_OPENSHIFT_APP_DOMAIN=$(OPENSHIFT_APPS_BASEDOMAIN) \
ods-api-service-postgresql .
.PHONY: apply-ods-api-service-database-chart
## Run database migration for ODS API Service. This will port-forward the PostgreSQL service to localhost and run the migration command, then stop the port-forwarding.
ods-api-service-db-migration:
@cd ../ods-api-service && { \
make db-port-forward NAMESPACE=$(ODS_NAMESPACE) & \
PF_PID=$$!; \
export ODS_API_SERVICE_DB_HOST=localhost \
ODS_API_SERVICE_DB_PORT=5432 \
ODS_API_SERVICE_DB_NAME=$(ODS_API_SERVICE_DB_NAME) \
ODS_API_SERVICE_DB_USER=$(ODS_API_SERVICE_DB_USER) \
ODS_API_SERVICE_DB_PASSWORD=$(ODS_API_SERVICE_DB_PASSWORD); \
make db-migrate; \
MIGRATE_RC=$$?; \
echo "Database migration completed. Stopping port-forwarding..."; \
kill $$PF_PID 2>/dev/null || true; \
wait $$PF_PID 2>/dev/null || true; \
exit $$MIGRATE_RC; \
}
.PHONY: ods-api-service-db-migration
## Configure ODS API Service (sets up PostgreSQL superuser for backup operations).
configure-ods-api-service-database-backup:
cd ods-api-service-database && ./configure.sh --namespace $(ODS_NAMESPACE)
.PHONY: configure-ods-api-service-database-backup
# BACKUP
## Create a backup of the current state.
backup: backup-ocp-config
.PHONY: backup
## Create a backup of OpenShift resources in "ods" namespace.
backup-ocp-config:
tailor export --namespace $(ODS_NAMESPACE) > backup_ods.yml
.PHONY: backup-ocp-config
# PVC MIGRATION
## Migrate data from one PVC to another. Options: SOURCE_PVC, TARGET_PVC, THREADS (default: 5), CPU_REQUEST (default: 1), MEMORY (default: 2)
migrate-pvc-data:
./scripts/migrate_pvc_data.sh --source-pvc $(SOURCE_PVC) --target-pvc $(TARGET_PVC) --namespace $(ODS_NAMESPACE) --threads $(THREADS) --cpu $(CPU_REQUEST) --memory $(MEMORY)
.PHONY: migrate-pvc-data
### HELP
### Based on https://gist.github.com/prwhite/8168133#gistcomment-2278355.
help:
@echo ''
@echo 'Usage:'
@echo ' make <target>'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:|^# .*/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " %-35s %s\n", helpCommand, helpMessage; \
} else { \
printf "\n"; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
.PHONY: help