-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
243 lines (197 loc) · 13.5 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
package:
# This target should be executed by passing in an argument representing the version of the artifacts we are packaging
# For example: make package version=r1
docker build -t packaging -f Dockerfiles/Dockerfile.package .
docker run --rm \
-e BCDA_GPG_RPM_PASSPHRASE='${BCDA_GPG_RPM_PASSPHRASE}' \
-e GPG_RPM_USER='${GPG_RPM_USER}' \
-e GPG_RPM_EMAIL='${GPG_RPM_EMAIL}' \
-e GPG_PUB_KEY_FILE='${GPG_PUB_KEY_FILE}' \
-e GPG_SEC_KEY_FILE='${GPG_SEC_KEY_FILE}' \
-v ${PWD}:/go/src/github.com/CMSgov/bcda-app packaging $(version)
setup-tests:
# Clean up any existing data to ensure we spin up container in a known state.
docker compose -f docker-compose.test.yml rm -fsv tests
docker compose -f docker-compose.test.yml build tests
LINT_TIMEOUT ?= 3m
lint: setup-tests
docker compose -f docker-compose.test.yml run \
--rm tests golangci-lint run --exclude="(conf\.(Un)?[S,s]etEnv)" --exclude="github\.com\/stretchr\/testify\/suite\.Suite contains sync\.RWMutex" --timeout=$(LINT_TIMEOUT) --verbose
# TODO: Remove the exclusion of G301 as part of BCDA-8414
docker compose -f docker-compose.test.yml run --rm tests gosec -exclude=G301 ./... ./optout
smoke-test: setup-tests
test/smoke_test/smoke_test.sh $(env) $(maintenanceMode)
postman:
# This target should be executed by passing in an argument for the environment (dev/test/sbx)
# and if needed a token.
# Use env=local to bring up a local version of the app and test against it
# For example: make postman env=test token=<MY_TOKEN> maintenanceMode=<CURRENT_MAINTENANCE_MODE>
$(eval BLACKLIST_CLIENT_ID=$(shell docker compose exec -T api env | grep BLACKLIST_CLIENT_ID | cut -d'=' -f2))
$(eval BLACKLIST_CLIENT_SECRET=$(shell docker compose exec -T api env | grep BLACKLIST_CLIENT_SECRET | cut -d'=' -f2))
# Set up valid client credentials
$(eval ACO_CMS_ID = A9994)
$(eval CLIENT_TEMP := $(shell docker compose run --rm api sh -c 'bcda reset-client-credentials --cms-id $(ACO_CMS_ID)'|tail -n2))
$(eval CLIENT_ID:=$(shell echo $(CLIENT_TEMP) |awk '{print $$1}'))
$(eval CLIENT_SECRET:=$(shell echo $(CLIENT_TEMP) |awk '{print $$2}'))
# to test alrEnabled, include --global-var alrEnabled=true below
docker compose -f docker-compose.test.yml build postman_test
@docker compose -f docker-compose.test.yml run --rm postman_test test/postman_test/BCDA_Tests_Sequential.postman_collection.json \
-e test/postman_test/$(env).postman_environment.json --global-var "token=$(token)" --global-var clientId=$(CLIENT_ID) --global-var clientSecret=$(CLIENT_SECRET) \
--global-var blacklistedClientId=$(BLACKLIST_CLIENT_ID) --global-var blacklistedClientSecret=$(BLACKLIST_CLIENT_SECRET) \
--global-var v2Disabled=false \
--global-var maintenanceMode=$(maintenanceMode)
# make test-path TEST_PATH="bcdaworker/worker/*.go"
test-path: setup-tests
@docker compose -f docker-compose.test.yml run --rm tests go test -v $(TEST_PATH)
unit-test: unit-test-ssas unit-test-db unit-test-localstack load-fixtures-ssas setup-tests
@docker compose -f docker-compose.test.yml run --rm tests bash scripts/unit_test.sh
unit-test-ssas:
docker compose up -d ssas
unit-test-db:
# Target stands up the postgres instance needed for unit testing.
# Clean up any existing data to ensure we spin up container in a known state.
docker compose -f docker-compose.test.yml rm -fsv db-unit-test
docker compose -f docker-compose.test.yml up -d db-unit-test
# Wait for the database to be ready
docker run --rm --network bcda-app-net willwill/wait-for-it db-unit-test:5432 -t 120
# Perform migrations to ensure matching schemas
docker run --rm -v ${PWD}/db/migrations:/migrations --network bcda-app-net migrate/migrate -path=/migrations/bcda/ -database 'postgres://postgres:toor@db-unit-test:5432/bcda_test?sslmode=disable&x-migrations-table=schema_migrations_bcda' up
docker run --rm -v ${PWD}/db/migrations:/migrations --network bcda-app-net migrate/migrate -path=/migrations/bcda_queue/ -database 'postgres://postgres:toor@db-unit-test:5432/bcda_test?sslmode=disable&x-migrations-table=schema_migrations_bcda_queue' up
# Load ALR data into the unit-test-DB for local and github actions unit-test
# TODO: once we finalize on synthetic ALR data, we should take a snapshot of the unit-test-db
docker compose run \
-e DATABASE_URL=postgresql://postgres:toor@db-unit-test:5432/bcda_test?sslmode=disable \
-e QUEUE_DATABASE_URL=postgresql://postgres:toor@db-unit-test:5432/bcda_test?sslmode=disable \
api sh -c 'bcda generate-synthetic-alr-data --cms-id=A9994 --alr-template-file ./alr/gen/testdata/PY21ALRTemplatePrelimProspTable1.csv'
unit-test-localstack:
# Clean up any existing data to ensure we spin up container in a known state.
docker compose -f docker-compose.test.yml rm -fsv localstack
docker compose -f docker-compose.test.yml up -d localstack
unit-test-db-snapshot:
# Target takes a snapshot of the currently running postgres instance used for unit testing and updates the db/testing/docker-entrypoint-initdb.d/dump.pgdata file
docker compose -f docker-compose.test.yml exec db-unit-test sh -c 'PGPASSWORD=$$POSTGRES_PASSWORD pg_dump -U postgres --format custom --file=/docker-entrypoint-initdb.d/dump.pgdata --create $$POSTGRES_DB'
performance-test: setup-tests
docker compose -f docker-compose.test.yml run --rm -w /go/src/github.com/CMSgov/bcda-app/test/performance_test tests sh performance_test.sh
test:
$(MAKE) lint
$(MAKE) unit-test
$(MAKE) postman env=local maintenanceMode=""
$(MAKE) smoke-test env=local maintenanceMode=""
reset-db:
# Rebuild the databases to ensure that we're starting in a fresh state
docker compose -f docker-compose.yml rm -fsv db queue
docker compose up -d db queue
echo "Wait for databases to be ready..."
docker run --rm --network bcda-app-net willwill/wait-for-it db:5432 -t 100
docker run --rm --network bcda-app-net willwill/wait-for-it queue:5432 -t 100
# Initialize schemas
docker run --rm -v ${PWD}/db/migrations:/migrations --network bcda-app-net migrate/migrate -path=/migrations/bcda/ -database 'postgres://postgres:toor@db:5432/bcda?sslmode=disable&x-migrations-table=schema_migrations_bcda' up
docker run --rm -v ${PWD}/db/migrations:/migrations --network bcda-app-net migrate/migrate -path=/migrations/bcda_queue/ -database 'postgres://postgres:toor@queue:5432/bcda_queue?sslmode=disable&x-migrations-table=schema_migrations_bcda_queue' up
load-fixtures: reset-db
docker compose run db psql -v ON_ERROR_STOP=1 "postgres://postgres:toor@db:5432/bcda?sslmode=disable" -f /var/db/fixtures.sql
$(MAKE) load-synthetic-cclf-data
$(MAKE) load-synthetic-suppression-data
$(MAKE) load-fixtures-ssas
# Add ALR data for ACOs under test. Must have attribution already set.
$(eval ACO_CMS_IDS := A9994 A9996)
for acoId in $(ACO_CMS_IDS) ; do \
docker compose run api sh -c 'bcda generate-synthetic-alr-data --cms-id='$$acoId' --alr-template-file ./alr/gen/testdata/PY21ALRTemplatePrelimProspTable1.csv' ; \
done
# Ensure components are started as expected
docker compose up -d api worker ssas
docker run --rm --network bcda-app-net willwill/wait-for-it api:3000 -t 100
docker run --rm --network bcda-app-net willwill/wait-for-it ssas:3003 -t 100
# Additional fixtures for postman+ssas
docker compose run db psql -v ON_ERROR_STOP=1 "postgres://postgres:toor@db:5432/bcda?sslmode=disable" -f /var/db/postman_fixtures.sql
load-synthetic-cclf-data:
$(eval ACO_SIZES := dev dev-auth dev-cec dev-cec-auth dev-ng dev-ng-auth dev-ckcc dev-ckcc-auth dev-kcf dev-kcf-auth dev-dc dev-dc-auth small medium large extra-large)
# The "test" environment provides baseline CCLF ingestion for ACO
docker compose run --rm api sh -c "../scripts/bulk_import_synthetic_cclf_package.sh test ' ' $(ACO_SIZES)"
echo "Updating timestamp data on historical CCLF data for simulating ability to test /Group with _since"
docker compose run db psql -v ON_ERROR_STOP=1 "postgres://postgres:toor@db:5432/bcda?sslmode=disable" -c "update cclf_files set timestamp='2020-02-01';"
docker compose run --rm api sh -c "../scripts/bulk_import_synthetic_cclf_package.sh test-new-beneficiaries ' ' $(ACO_SIZES)"
docker compose run --rm api sh -c "../scripts/bulk_import_synthetic_cclf_package.sh test runout $(ACO_SIZES)"
# Improved Synthea BFD Data Ingestion
$(eval IMPROVED_SIZE := improved-dev improved-small improved-large)
docker compose run --rm api sh -c "../scripts/bulk_import_synthetic_cclf_package.sh improved ' ' $(IMPROVED_SIZE)"
docker compose run --rm api sh -c "../scripts/bulk_import_synthetic_cclf_package.sh improved-new ' ' $(IMPROVED_SIZE)"
docker compose run --rm api sh -c "../scripts/bulk_import_synthetic_cclf_package.sh improved runout $(IMPROVED_SIZE)"
load-synthetic-suppression-data:
docker compose run api sh -c 'bcda import-suppression-directory --directory=../shared_files/synthetic1800MedicareFiles'
# Update the suppression entries to guarantee there are qualified entries when searching for suppressed benes.
# See postgres#GetSuppressedMBIs for more information
docker compose exec -T db sh -c 'PGPASSWORD=$$POSTGRES_PASSWORD psql -v ON_ERROR_STOP=1 $$POSTGRES_DB postgres -c "UPDATE suppressions SET effective_date = now(), preference_indicator = '"'"'N'"'"' WHERE effective_date = (SELECT max(effective_date) FROM suppressions);"'
load-fixtures-ssas:
docker compose up -d db
docker run --rm --network bcda-app-net migrate/migrate:v4.15.0-beta.3 -source='github://CMSgov/bcda-ssas-app/db/migrations#main' -database 'postgres://postgres:toor@db:5432/bcda?sslmode=disable' up
docker compose run ssas --add-fixture-data
docker-build:
docker compose build --force-rm
docker compose -f docker-compose.test.yml build --force-rm
docker-bootstrap: docker-build load-fixtures
api-shell:
docker compose exec -T api bash
worker-shell:
docker compose exec -T worker bash
debug-api:
docker compose start db queue worker
@echo "Starting debugger. This may take a while..."
@-bash -c "trap 'docker compose stop' EXIT; \
docker compose -f docker-compose.yml -f docker-compose.debug.yml run --no-deps -T --rm -p 3000:3000 -v $(shell pwd):/go/src/github.com/CMSgov/bcda-app api dlv debug -- start-api"
debug-worker:
docker compose start db queue api
@echo "Starting debugger. This may take a while..."
@-bash -c "trap 'docker compose stop' EXIT; \
docker compose -f docker-compose.yml -f docker-compose.debug.yml run --no-deps -T --rm -v $(shell pwd):/go/src/github.com/CMSgov/bcda-app worker dlv debug"
bdt:
# Set up valid client credentials
$(eval ACO_CMS_ID = A9994)
$(eval CLIENT_TEMP := $(shell docker compose run --rm api sh -c 'bcda reset-client-credentials --cms-id $(ACO_CMS_ID)'|tail -n2))
$(eval CLIENT_ID:=$(shell echo $(CLIENT_TEMP) |awk '{print $$1}'))
$(eval CLIENT_SECRET:=$(shell echo $(CLIENT_TEMP) |awk '{print $$2}'))
$(eval BDT_BASE_URL = 'http://host.docker.internal:3000')
docker build --no-cache -t bdt -f Dockerfiles/Dockerfile.bdt .
@docker run --rm \
-e BASE_URL='${BDT_BASE_URL}' \
-e CLIENT_ID='${CLIENT_ID}' \
-e SECRET='${CLIENT_SECRET}' \
bdt
.PHONY: api-shell debug-api debug-worker docker-bootstrap docker-build lint load-fixtures load-fixtures-ssas load-synthetic-cclf-data load-synthetic-suppression-data package performance-test postman release smoke-test test unit-test worker-shell bdt unit-test-db unit-test-db-snapshot reset-db dbdocs
credentials:
$(eval ACO_CMS_ID = A9994)
# Use ACO_CMS_ID to generate a local set of credentials for the ACO.
# For example: ACO_CMS_ID=A9993 make credentials
@docker compose run --rm api sh -c 'bcda reset-client-credentials --cms-id $(ACO_CMS_ID)'|tail -n2
dbdocs:
docker run --rm -v $PWD:/work -w /work --network bcda-app-net ghcr.io/k1low/tbls doc --rm-dist "postgres://postgres:toor@db:5432/bcda?sslmode=disable" dbdocs/bcda
docker run --rm -v $PWD:/work -w /work --network bcda-app-net ghcr.io/k1low/tbls doc --force "postgres://postgres:toor@queue:5432/bcda_queue?sslmode=disable" dbdocs/bcda_queue
# ==== Lambda ====
package-opt-out: export GOOS=linux
package-opt-out: export GOARCH=amd64
package-opt-out:
cd bcda && go build -o bin/opt-out-import ./lambda/optout/main.go
package-cclf-import: export GOOS=linux
package-cclf-import: export GOARCH=amd64
package-cclf-import:
cd bcda && go build -o bin/cclf-import ./lambda/cclf/main.go
# Build and publish images to ECR
build-api:
$(eval ACCOUNT_ID =$(shell aws sts get-caller-identity --output text --query Account))
$(eval CURRENT_COMMIT=$(shell git log -n 1 --pretty=format:'%h'))
$(eval DOCKER_REGISTRY_URL=${ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/bcda-api)
docker build -t ${DOCKER_REGISTRY_URL}:latest -t '${DOCKER_REGISTRY_URL}:${CURRENT_COMMIT}' -f Dockerfiles/Dockerfile.bcda_prod .
publish-api:
$(eval ACCOUNT_ID =$(shell aws sts get-caller-identity --output text --query Account))
$(eval DOCKER_REGISTRY_URL=${ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/bcda-api)
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin '${DOCKER_REGISTRY_URL}'
docker image push '${DOCKER_REGISTRY_URL}' -a
build-worker:
$(eval ACCOUNT_ID =$(shell aws sts get-caller-identity --output text --query Account))
$(eval CURRENT_COMMIT=$(shell git log -n 1 --pretty=format:'%h'))
$(eval DOCKER_REGISTRY_URL=${ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/bcda-worker)
docker build -t ${DOCKER_REGISTRY_URL}:latest -t '${DOCKER_REGISTRY_URL}:${CURRENT_COMMIT}' -f Dockerfiles/Dockerfile.bcdaworker_prod .
publish-worker:
$(eval ACCOUNT_ID =$(shell aws sts get-caller-identity --output text --query Account))
$(eval DOCKER_REGISTRY_URL=${ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/bcda-worker)
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin '${DOCKER_REGISTRY_URL}'
docker image push '${DOCKER_REGISTRY_URL}' -a