-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
174 lines (149 loc) · 7.62 KB
/
Makefile
File metadata and controls
174 lines (149 loc) · 7.62 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
SHELL := /usr/bin/env bash
PATHFINDER_PREFIX := wksv3k
PROJECT_PREFIX := cas-
THIS_FILE := $(lastword $(MAKEFILE_LIST))
PROJECT_FOLDER := $(abspath $(realpath $(lastword $(MAKEFILE_LIST)))/../)
include .pipeline/*.mk
# We define the default values of the template variables here to make them available in the lint target.
POSTGRESQL_WORKERS="4"
MASTER_CPU_REQUEST="500m"
MASTER_CPU_LIMIT="2"
MASTER_MEMORY_REQUEST="4096Mi"
MASTER_MEMORY_LIMIT="8192Mi"
WORKER_CPU_REQUEST="250m"
WORKER_CPU_LIMIT="1"
WORKER_MEMORY_REQUEST="2048Mi"
WORKER_MEMORY_LIMIT="4096Mi"
OC_TEMPLATE_VARS += POSTGRESQL_WORKERS="$(POSTGRESQL_WORKERS)"
OC_TEMPLATE_VARS += MASTER_CPU_REQUEST=$(MASTER_CPU_REQUEST) MASTER_CPU_LIMIT=$(MASTER_CPU_LIMIT)
OC_TEMPLATE_VARS += MASTER_MEMORY_REQUEST=$(MASTER_MEMORY_REQUEST) MASTER_MEMORY_LIMIT=$(MASTER_MEMORY_LIMIT)
OC_TEMPLATE_VARS += WORKER_CPU_REQUEST=$(WORKER_CPU_REQUEST) WORKER_CPU_LIMIT=$(WORKER_CPU_LIMIT)
OC_TEMPLATE_VARS += WORKER_MEMORY_REQUEST=$(WORKER_MEMORY_REQUEST) WORKER_MEMORY_LIMIT=$(WORKER_MEMORY_LIMIT)
.PHONY: help
help: $(call make_help,help,Explains how to use this Makefile)
@@exit 0
.PHONY: targets
targets: $(call make_help,targets,Lists all targets in this Makefile)
$(call make_list_targets,$(THIS_FILE))
.PHONY: whoami
whoami: $(call make_help,whoami,Prints the name of the user currently authenticated via `oc`)
$(call oc_whoami)
.PHONY: project
project: whoami
project: $(call make_help,project,Switches to the desired $$OC_PROJECT namespace)
$(call oc_project)
.PHONY: lint
lint: $(call make_help,lint,Checks the configured yml template definitions against the remote schema using the tools namespace)
lint: OC_PROJECT=$(OC_TOOLS_PROJECT)
lint: whoami
$(call oc_lint)
.PHONY: configure
configure: $(call make_help,configure,Configures the tools project namespace for a build)
configure: OC_PROJECT=$(OC_TOOLS_PROJECT)
configure: whoami
$(call oc_configure)
.PHONY: build
build: $(call make_help,build,Builds the source into an image in the tools project namespace)
build: OC_PROJECT=$(OC_TOOLS_PROJECT)
build: whoami
$(call oc_build,$(PROJECT_PREFIX)postgres)
# The != operator assigns the ouput of a bash command to the variable, this allows us to override the
# default value depending on the value OC_PROJECT in the install target
.PHONY: install
install: POSTGRESQL_WORKERS != if [ "$(OC_PROJECT)" == "$(OC_PROD_PROJECT)" ]; then echo 8; else echo 4; fi;
install: MASTER_CPU_REQUEST != if [ "$(OC_PROJECT)" == "$(OC_PROD_PROJECT)" ]; then echo 1; else echo "500m"; fi;
install: WORKER_CPU_REQUEST != if [ "$(OC_PROJECT)" == "$(OC_PROD_PROJECT)" ]; then echo "500m"; else echo "250m"; fi;
install: POSTGRESQL_ADMIN_PASSWORD=$(shell openssl rand -base64 32 | tr -d /=+ | cut -c -16 | base64)
install: OC_TEMPLATE_VARS += POSTGRESQL_ADMIN_PASSWORD="$(POSTGRESQL_ADMIN_PASSWORD)"
install: whoami
$(call oc_run_job,${PROJECT_PREFIX}ciip-postgres-shelf-tfe-add-app)
$(call oc_create_secrets)
$(call oc_promote,$(PROJECT_PREFIX)postgres)
$(call oc_deploy)
$(call oc_wait_for_deploy_ready,$(PROJECT_PREFIX)ciip-postgres-master)
$(call oc_wait_for_deploy_ready,$(PROJECT_PREFIX)postgres-master)
@@echo "TODO: wait for statefulset to be ready"
@@echo "waiting for all $(PROJECT_PREFIX)postgres-workers to be connected to $(PROJECT_PREFIX)postgres-master..."; \
POD=$$($(OC) -n $(OC_PROJECT) get pods --selector deploymentconfig=$(PROJECT_PREFIX)postgres-master --field-selector status.phase=Running -o name | cut -d '/' -f 2 ); \
AVAILABLE_COUNT="-1"; \
while [ "$(POSTGRESQL_WORKERS)" != "$$AVAILABLE_COUNT" ]; do \
AVAILABLE_COUNT="$$($(OC) -n $(OC_PROJECT) exec $$POD -- psql -qtA -v "ON_ERROR_STOP=1" -c "select count(success) from run_command_on_workers('select true') where success = true;")"; \
echo "connected nodes: $$AVAILABLE_COUNT"; \
if [ "$(POSTGRESQL_WORKERS)" != "$$AVAILABLE_COUNT" ]; then \
sleep 5; \
fi; \
done; \
if [ "$(POSTGRESQL_WORKERS)" != "$$($(OC) -n $(OC_PROJECT) exec $$POD -- psql -qtA -v "ON_ERROR_STOP=1" -c "select count(isactive) from pg_dist_node where isactive = true;")" ]; then \
echo "list configured workers..."; \
$(OC) -n $(OC_PROJECT) exec $$POD -- psql -c "select * from pg_dist_node;"; \
echo "try connecting to all enabled workers..."; \
$(OC) -n $(OC_PROJECT) exec $$POD -- psql -c "select * from run_command_on_workers('select true');"; \
fi;
.PHONY: install_dev
install_dev: OC_PROJECT=$(OC_DEV_PROJECT)
install_dev: install
.PHONY: install_test
install_test: OC_PROJECT=$(OC_TEST_PROJECT)
install_test: install
.PHONY: install_prod
install_prod: OC_PROJECT=$(OC_PROD_PROJECT)
install_prod: install
.PHONY: mock_storageclass
mock_storageclass:
$(call oc_mock_storageclass,netapp-block-standard)
.PHONY: provision
provision:
$(call oc_new_project,$(OC_TOOLS_PROJECT))
$(call oc_new_project,$(OC_TEST_PROJECT))
$(call oc_new_project,$(OC_DEV_PROJECT))
$(call oc_new_project,$(OC_PROD_PROJECT))
OC_CIRCLECI_SECRET=$(shell $(OC) -n $(OC_PROJECT) describe sa $(PROJECT_PREFIX)circleci | awk '$$1 == "Mountable" { print $$3 }')
OC_CIRCLECI_TOKEN=$(shell $(OC) -n $(OC_PROJECT) get secret $(OC_CIRCLECI_SECRET) -o=template --template '{{base64decode .data.token}}')
OC_SHIPIT_SECRET=$(shell $(OC) -n $(OC_PROJECT) describe sa $(PROJECT_PREFIX)shipit | awk '$$1 == "Mountable" { print $$3 }')
OC_SHIPIT_TOKEN=$(shell $(OC) -n $(OC_PROJECT) get secret $(OC_SHIPIT_SECRET) -o=template --template '{{base64decode .data.token}}')
.PHONY: token
token: OC_PROJECT=$(OC_TOOLS_PROJECT)
token:
@@echo "\n$(OC_CIRCLECI_SECRET)"
@@echo "$(OC_CIRCLECI_TOKEN)\n"
@@echo "\n$(OC_SHIPIT_SECRET)"
@@echo "$(OC_SHIPIT_TOKEN)\n"
.PHONY: scan
scan:
curl https://ftp.postgresql.org/pub/source/v11.4/postgresql-11.4.tar.gz | tar xz
git clone -b 'v1.0.0' --single-branch https://github.com/theory/pgtap.git
git clone -b 'v8.2.2' --single-branch https://github.com/citusdata/citus.git
docker run -d --name sonarqube -p 9000:9000 sonarqube
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.0.0.1744-macosx.zip
unzip sonar-scanner-cli-4.0.0.1744-macosx.zip
./sonar-scanner-4.0.0.1744-macosx/bin/sonar-scanner \
-Dsonar.projectKey=cas-postgres \
-Dsonar.sources=. \
-Dsonar.projectVersion=`git rev-parse --abbrev-ref HEAD` \
-Dsonar.coverage.exclusions='**/*'
.PHONY: old_tags
old_tags:
oc get is/cas-postgres -o go-template='{{range .status.tags}}{{$$tag := .tag}}{{range .items}}{{.created}}{{"\t"}}{{$$tag}}{{"\n"}}{{end}}{{end}}' | sort -r | tail -n +8 | awk '{print $$2}'
ifeq ($(MAKECMDGOALS),$(filter $(MAKECMDGOALS),test_e2e test_unit))
include $(PROJECT_FOLDER)/.pipeline/test/bats.mk
endif
.PHONY: test_e2e_setup
test_e2e_setup: $(call make_help,test_e2e_setup,Set up the local cluster for e2e tests. Run prior to make install)
test_e2e_setup: OC_PROJECT=$(OC_DEV_PROJECT)
test_e2e_setup:
$(eval OC_TEMPLATE_VARS += TFC_TOKEN="$(shell echo -n "$(TFC_TOKEN)" | base64 -w 0)" TFC_WORKSPACE_ID="$(shell echo -n "$(TFC_WORKSPACE_ID)" | base64 -w 0)")
@@oc process --ignore-unknown-parameters -f test/e2e/terraform-cloud-workspace-secret.yml $(OC_TEMPLATE_VARS) |\
oc -n "$(OC_PROJECT)" create --validate -f- ;
@@oc process --ignore-unknown-parameters -f test/e2e/gcp-sa-secret.yml |\
oc -n "$(OC_PROJECT)" create --validate -f- ;
.PHONY: test_e2e
test_e2e: $(call make_help,test_e2e,Runs e2e tests with bats)
test_e2e: whoami
test_e2e: OC_PROJECT=$(OC_DEV_PROJECT)
test_e2e:
@@export OC="$(OC)" OC_PROJECT="$(OC_PROJECT)" PROJECT_PREFIX="$(PROJECT_PREFIX)"; \
bats $(PROJECT_FOLDER)/test/e2e/**/*.bats;
.PHONY: test_unit
test_unit: $(call make_help,test_unit,Runs unit tests with bats)
test_unit: # https://github.com/bats-core/bats-core
$(call bats_test,$(PROJECT_FOLDER)/test/unit)