-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
110 lines (88 loc) · 3.83 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
run_env = ParameterKey=RunEnvironment,ParameterValue
set_application_prefix = ParameterKey=ApplicationPrefix,ParameterValue
set_application_name = ParameterKey=ApplicationFriendlyName,ParameterValue
prod_aws_account = 298118738376
dev_aws_account = 427040638965
current_aws_account := $(shell aws sts get-caller-identity --query Account --output text)
src_directory_root = src/
dist_ui_directory_root = dist_ui/
integration_test_directory_root = tests/live_integration/
# CHANGE ME (as needed)
application_key=infra-core-api
application_name="InfraCoreApi"
techlead="[email protected]"
region="us-east-1"
# DO NOT CHANGE
common_params = --no-confirm-changeset \
--no-fail-on-empty-changeset \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND \
--region $(region) \
--stack-name $(application_key) \
--tags "project=$(application_key)" "techlead=$(techlead)" \
--s3-prefix $(application_key) \
--resolve-s3
s3_bucket_prefix = "$(current_aws_account)-$(region)-$(application_key)"
ui_s3_bucket = "$(s3_bucket_prefix)-ui"
GIT_HASH := $(shell git rev-parse --short HEAD)
.PHONY: clean
check_account_prod:
ifneq ($(current_aws_account),$(prod_aws_account))
$(error Error: running in account $(current_aws_account), expected account ID $(prod_aws_account))
endif
check_account_dev:
ifneq ($(current_aws_account),$(dev_aws_account))
$(error Error: running in account $(current_aws_account), expected account ID $(dev_aws_account))
endif
clean:
rm -rf .aws-sam
rm -rf node_modules/
rm -rf src/api/node_modules/
rm -rf src/ui/node_modules/
rm -rf dist/
rm -rf dist_ui/
rm -rf dist_devel/
build: src/ cloudformation/ docs/
yarn -D
VITE_BUILD_HASH=$(GIT_HASH) yarn build
cp -r src/api/resources/ dist/api/resources
rm -rf dist/lambda/sqs
sam build --template-file cloudformation/main.yml
local:
VITE_BUILD_HASH=$(GIT_HASH) yarn run dev
deploy_prod: check_account_prod build
@echo "Deploying CloudFormation stack..."
sam deploy $(common_params) --parameter-overrides $(run_env)=prod $(set_application_prefix)=$(application_key) $(set_application_name)="$(application_name)" S3BucketPrefix="$(s3_bucket_prefix)"
@echo "Syncing S3 bucket..."
aws s3 sync $(dist_ui_directory_root) s3://$(ui_s3_bucket)/ --delete
make invalidate_cloudfront
deploy_dev: check_account_dev build
@echo "Deploying CloudFormation stack..."
sam deploy $(common_params) --parameter-overrides $(run_env)=dev $(set_application_prefix)=$(application_key) $(set_application_name)="$(application_name)" S3BucketPrefix="$(s3_bucket_prefix)"
@echo "Syncing S3 bucket..."
aws s3 sync $(dist_ui_directory_root) s3://$(ui_s3_bucket)/ --delete
make invalidate_cloudfront
invalidate_cloudfront:
@echo "Creating CloudFront invalidation..."
$(eval DISTRIBUTION_ID := $(shell aws cloudformation describe-stacks --stack-name $(application_key) --query "Stacks[0].Outputs[?OutputKey=='CloudfrontDistributionId'].OutputValue" --output text))
$(eval INVALIDATION_ID := $(shell aws cloudfront create-invalidation --distribution-id $(DISTRIBUTION_ID) --paths "/*" --query 'Invalidation.Id' --output text --no-cli-page))
@echo "Waiting on job $(INVALIDATION_ID)..."
aws cloudfront wait invalidation-completed --distribution-id $(DISTRIBUTION_ID) --id $(INVALIDATION_ID)
@echo "CloudFront invalidation completed!"
install:
yarn -D
pip install cfn-lint
test_live_integration: install
yarn test:live
test_unit: install
yarn typecheck
yarn lint
cfn-lint cloudformation/**/* --ignore-templates cloudformation/phony-swagger.yml -i W3660
yarn prettier
yarn test:unit
test_e2e: install
yarn playwright install
yarn test:e2e
dev_health_check:
curl -f https://core.aws.qa.acmuiuc.org/api/v1/healthz && curl -f https://core.aws.qa.acmuiuc.org/
prod_health_check:
curl -f https://core.acm.illinois.edu/api/v1/healthz && curl -f https://core.acm.illinois.edu