|
1 | | -# ============================================================================= |
2 | | -# VARIABLES |
3 | | -# ============================================================================= |
4 | | - |
5 | | -# AWS Account IDs |
6 | | -PROD_AWS_ACCOUNT := 298118738376 |
7 | | -DEV_AWS_ACCOUNT := 427040638965 |
8 | | - |
9 | | -# Tools & Shell Commands (immediate expansion) |
10 | | -SHELL := /bin/bash |
11 | | -GIT_HASH := $(shell git rev-parse --short HEAD) |
12 | | -CURRENT_AWS_ACCT := $(shell aws sts get-caller-identity --query Account --output text) |
13 | | -CURL := curl -f |
14 | | - |
15 | | -# Directories |
16 | | -API_SRC_DIR := src/api |
17 | | -TERRAFORM_PROD_DIR := terraform/envs/prod |
18 | | -TERRAFORM_QA_DIR := terraform/envs/qa |
19 | | -DIST_LAMBDA_DIR := dist/lambda |
20 | | -DIST_SQS_CONSUMER_DIR := dist/sqsConsumer |
21 | | - |
22 | | -# Build Parameters |
23 | | -NODE_BUILDER_IMAGE := public.ecr.aws/sam/build-nodejs22.x:latest |
24 | | -NPM_INSTALL_PARAMS := --omit=dev --target_arch=arm64 --target_platform=linux --target_libc=glibc |
25 | | - |
26 | | -# Platforms for Terraform provider locking |
27 | | -TF_LOCK_PLATFORMS := -platform=windows_amd64 -platform=darwin_amd64 -platform=darwin_arm64 -platform=linux_amd64 -platform=linux_arm64 |
28 | | - |
29 | | -# ============================================================================= |
30 | | -# PHONY TARGETS & DEFAULT GOAL |
31 | | -# ============================================================================= |
32 | | - |
33 | | -.PHONY: help all clean build build_swagger local deploy_prod deploy_dev init_terraform \ |
34 | | - install test_all test_unit test_live_integration test_e2e test_post_deploy \ |
35 | | - check_account_prod check_account_dev dev_health_check prod_health_check \ |
36 | | - lock_terraform validate_terraform |
37 | | - |
38 | | -# Set the default goal to 'help' |
39 | | -.DEFAULT_GOAL := help |
40 | | - |
41 | | -# ============================================================================= |
42 | | -# HELPER DEFINITION |
43 | | -# ============================================================================= |
44 | | - |
45 | | -# Define a reusable function for building Node.js packages in Docker. |
46 | | -# Argument 1: The directory to process (e.g., dist/lambda) |
47 | | -define build-lambda-package |
48 | | - @echo "--- Building Node.js package in $(1) ---" |
49 | | - docker run --rm -v "$(shell pwd)/$(1)":/var/task $(NODE_BUILDER_IMAGE) \ |
50 | | - sh -c "npm install $(NPM_INSTALL_PARAMS) && \ |
51 | | - rm -rf node_modules/aws-crt/dist/bin/{darwin*,linux-x64*,linux-arm64-musl} && \ |
52 | | - rm -rf node_modules/argon2/prebuilds/{darwin*,freebsd*,linux-arm,linux-x64*,win32-x64*} && \ |
53 | | - rm -rf node_modules/argon2/prebuilds/linux-arm64/argon2.armv8.musl.node" |
54 | | -endef |
55 | | - |
56 | | -# ============================================================================= |
57 | | -# CORE TARGETS |
58 | | -# ============================================================================= |
59 | | - |
60 | | -help: ## ✨ Show this help message |
61 | | - @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_0-9-]+:.*?## / {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) |
62 | | - |
63 | | -all: install build test_all ## 🚀 Install, build, and run all tests |
64 | | - |
65 | | -install: ## 📦 Install all project dependencies using Yarn |
66 | | - yarn -D |
| 1 | +prod_aws_account = 298118738376 |
| 2 | +dev_aws_account = 427040638965 |
| 3 | +current_aws_account := $(shell aws sts get-caller-identity --query Account --output text) |
| 4 | + |
| 5 | +src_directory_root = src/ |
| 6 | +dist_ui_directory_root = dist_ui/ |
| 7 | +integration_test_directory_root = tests/live_integration/ |
| 8 | +npm_install_params = --omit=dev --target_arch=arm64 --target_platform=linux --target_libc=glibc --cpu arm64 --os linux --arch=arm64 |
| 9 | +GIT_HASH := $(shell git rev-parse --short HEAD) |
| 10 | + |
| 11 | +.PHONY: clean |
| 12 | + |
| 13 | +check_account_prod: |
| 14 | +ifneq ($(current_aws_account),$(prod_aws_account)) |
| 15 | + $(error Error: running in account $(current_aws_account), expected account ID $(prod_aws_account)) |
| 16 | +endif |
| 17 | + |
| 18 | +check_account_dev: |
| 19 | +ifneq ($(current_aws_account),$(dev_aws_account)) |
| 20 | + $(error Error: running in account $(current_aws_account), expected account ID $(dev_aws_account)) |
| 21 | +endif |
| 22 | + |
67 | 23 |
|
68 | | -clean: ## 🧹 Remove all build artifacts and node_modules |
69 | | - rm -rf .aws-sam node_modules/ src/api/node_modules/ src/ui/node_modules/ \ |
70 | | - dist/ dist_ui/ dist_devel/ coverage/ |
| 24 | +clean: |
| 25 | + rm -rf .aws-sam |
| 26 | + rm -rf node_modules/ |
| 27 | + rm -rf src/api/node_modules/ |
| 28 | + rm -rf src/ui/node_modules/ |
| 29 | + rm -rf dist/ |
| 30 | + rm -rf dist_ui/ |
| 31 | + rm -rf dist_devel/ |
| 32 | + rm -rf coverage/ |
71 | 33 |
|
72 | | -build_swagger: ## 📝 Generate Swagger/OpenAPI specification |
73 | | - @(cd $(API_SRC_DIR); npx tsx --experimental-loader=./mockLoader.mjs createSwagger.ts) |
| 34 | +build_swagger: |
| 35 | + cd src/api && npx tsx --experimental-loader=./mockLoader.mjs createSwagger.ts && cd ../.. |
74 | 36 |
|
75 | | -build: install build_swagger ## 🛠️ Build the entire application |
76 | | - @echo "--- Building project source ---" |
| 37 | +build: src/ |
| 38 | + yarn -D |
77 | 39 | yarn build |
78 | | - cp -r $(API_SRC_DIR)/resources/ dist/api/resources |
| 40 | + make build_swagger |
| 41 | + cp -r src/api/resources/ dist/api/resources |
79 | 42 | rm -rf dist/lambda/sqs |
80 | | - $(call build-lambda-package,$(DIST_LAMBDA_DIR)) |
81 | | - $(call build-lambda-package,$(DIST_SQS_CONSUMER_DIR)) |
82 | | - |
83 | | -local: install ## 🏃 Run the development server locally |
| 43 | + docker run --rm -v "$(shell pwd)/dist/lambda":/var/task public.ecr.aws/sam/build-nodejs22.x:latest \ |
| 44 | + sh -c "npm install $(npm_install_params) && \ |
| 45 | + rm -rf node_modules/aws-crt/dist/bin/{darwin*,linux-x64*,linux-arm64-musl} && \ |
| 46 | + rm -rf node_modules/argon2/prebuilds/{darwin*,freebsd*,linux-arm,linux-x64*,win32-x64*} && \ |
| 47 | + rm -rf node_modules/argon2/prebuilds/linux-arm64/argon2.armv8.musl.node" |
| 48 | + |
| 49 | + docker run --rm -v "$(shell pwd)/dist/sqsConsumer":/var/task public.ecr.aws/sam/build-nodejs22.x:latest \ |
| 50 | + sh -c "npm install $(npm_install_params) && \ |
| 51 | + rm -rf node_modules/aws-crt/dist/bin/{darwin*,linux-x64*,linux-arm64-musl} && \ |
| 52 | + rm -rf node_modules/argon2/prebuilds/{darwin*,freebsd*,linux-arm,linux-x64*,win32-x64*} && \ |
| 53 | + rm -rf node_modules/argon2/prebuilds/linux-arm64/argon2.armv8.musl.node" |
| 54 | + |
| 55 | +local: |
84 | 56 | VITE_BUILD_HASH=$(GIT_HASH) yarn run dev |
85 | 57 |
|
86 | | -# ============================================================================= |
87 | | -# DEPLOYMENT & TERRAFORM |
88 | | -# ============================================================================= |
89 | | - |
90 | | -deploy_prod: check_account_prod ## 🚀 Deploy to PRODUCTION environment |
91 | | - @echo "--- Deploying Terraform to Production ---" |
92 | | - terraform -chdir=$(TERRAFORM_PROD_DIR) apply -auto-approve |
93 | | - |
94 | | -deploy_dev: check_account_dev ## 🚀 Deploy to DEVELOPMENT (QA) environment |
95 | | - @echo "--- Deploying Terraform to Development (QA) ---" |
96 | | - terraform -chdir=$(TERRAFORM_QA_DIR) apply -auto-approve |
97 | | - |
98 | | -init_terraform: ## Terraform: Initialize all environments |
99 | | - @echo "--- Initializing Terraform for Production ---" |
100 | | - terraform -chdir=$(TERRAFORM_PROD_DIR) init |
101 | | - @echo "--- Initializing Terraform for Development (QA) ---" |
102 | | - terraform -chdir=$(TERRAFORM_QA_DIR) init |
103 | | - |
104 | | -validate_terraform: ## Terraform: Format and validate all environments |
105 | | - @echo "--- Validating Production Terraform ---" |
106 | | - terraform -chdir=$(TERRAFORM_PROD_DIR) fmt -check |
107 | | - terraform -chdir=$(TERRAFORM_PROD_DIR) validate |
108 | | - @echo "--- Validating Development (QA) Terraform ---" |
109 | | - terraform -chdir=$(TERRAFORM_QA_DIR) fmt -check |
110 | | - terraform -chdir=$(TERRAFORM_QA_DIR) validate |
111 | | - |
112 | | -lock_terraform: ## Terraform: Update provider dependency locks for all platforms |
113 | | - @echo "--- Locking Terraform providers for Production ---" |
114 | | - terraform -chdir=$(TERRAFORM_PROD_DIR) providers lock $(TF_LOCK_PLATFORMS) |
115 | | - @echo "--- Locking Terraform providers for Development (QA) ---" |
116 | | - terraform -chdir=$(TERRAFORM_QA_DIR) providers lock $(TF_LOCK_PLATFORMS) |
117 | | - |
118 | | -# ============================================================================= |
119 | | -# TESTING & QA |
120 | | -# ============================================================================= |
121 | | - |
122 | | -test_all: test_unit test_e2e ## ✅ Run all unit and e2e tests |
123 | | - |
124 | | -test_unit: install ## ✅ Run linters, formatters, and unit tests |
| 58 | +deploy_prod: check_account_prod |
| 59 | + @echo "Deploying Terraform..." |
| 60 | + terraform -chdir=terraform/envs/prod init -lockfile=readonly |
| 61 | + terraform -chdir=terraform/envs/prod apply -auto-approve |
| 62 | + |
| 63 | +deploy_dev: check_account_dev |
| 64 | + @echo "Deploying Terraform..." |
| 65 | + terraform -chdir=terraform/envs/qa init -lockfile=readonly |
| 66 | + terraform -chdir=terraform/envs/qa apply -auto-approve |
| 67 | + |
| 68 | +init_terraform: |
| 69 | + terraform -chdir=terraform/envs/qa init |
| 70 | + terraform -chdir=terraform/envs/prod init |
| 71 | + |
| 72 | +install: |
| 73 | + yarn -D |
| 74 | + |
| 75 | +test_live_integration: install |
| 76 | + yarn test:live |
| 77 | + |
| 78 | +test_unit: install |
125 | 79 | yarn lint |
| 80 | + terraform -chdir=terraform/envs/qa init -reconfigure -backend=false -upgrade |
| 81 | + terraform -chdir=terraform/envs/qa fmt -check |
| 82 | + terraform -chdir=terraform/envs/qa validate |
| 83 | + terraform -chdir=terraform/envs/prod init -reconfigure -backend=false |
| 84 | + terraform -chdir=terraform/envs/prod fmt -check |
| 85 | + terraform -chdir=terraform/envs/prod validate |
126 | 86 | yarn prettier |
127 | | - $(MAKE) validate_terraform |
128 | 87 | yarn test:unit |
129 | 88 |
|
130 | | -test_live_integration: install ## ✅ Run post-deployment integration tests |
131 | | - yarn test:live |
132 | | - |
133 | | -test_e2e: install ## ✅ Run Playwright end-to-end tests |
| 89 | +test_e2e: install |
134 | 90 | yarn playwright install |
135 | 91 | yarn test:e2e |
136 | 92 |
|
137 | | -test_post_deploy: test_live_integration test_e2e ## ✅ Run all post-deployment tests |
138 | | - |
139 | | -# ============================================================================= |
140 | | -# HEALTH CHECKS & GUARDS |
141 | | -# ============================================================================= |
| 93 | +test_post_deploy: test_live_integration test_e2e |
142 | 94 |
|
143 | | -check_account_prod: ## 🔒 Verify execution in the PRODUCTION AWS account |
144 | | -ifneq ($(CURRENT_AWS_ACCT),$(PROD_AWS_ACCOUNT)) |
145 | | - $(error ERROR: Not in PROD account. Expected $(PROD_AWS_ACCOUNT), but in $(CURRENT_AWS_ACCT)) |
146 | | -endif |
147 | | - |
148 | | -check_account_dev: ## 🔒 Verify execution in the DEVELOPMENT AWS account |
149 | | -ifneq ($(CURRENT_AWS_ACCT),$(DEV_AWS_ACCOUNT)) |
150 | | - $(error ERROR: Not in DEV account. Expected $(DEV_AWS_ACCOUNT), but in $(CURRENT_AWS_ACCT)) |
151 | | -endif |
| 95 | +dev_health_check: |
| 96 | + curl -f https://core.aws.qa.acmuiuc.org/api/v1/healthz && curl -f https://core.aws.qa.acmuiuc.org/ |
152 | 97 |
|
153 | | -dev_health_check: ## ❤️ Check health of the DEVELOPMENT environment |
154 | | - @echo "--- Pinging Development (QA) Environment ---" |
155 | | - $(CURL) https://core.aws.qa.acmuiuc.org/api/v1/healthz |
156 | | - $(CURL) https://core.aws.qa.acmuiuc.org/ |
| 98 | +prod_health_check: |
| 99 | + curl -f https://core.acm.illinois.edu/api/v1/healthz && curl -f https://core.acm.illinois.edu |
157 | 100 |
|
158 | | -prod_health_check: ## ❤️ Check health of the PRODUCTION environment |
159 | | - @echo "--- Pinging Production Environment ---" |
160 | | - $(CURL) https://core.acm.illinois.edu/api/v1/healthz |
161 | | - $(CURL) https://core.acm.illinois.edu |
| 101 | +lock_terraform: |
| 102 | + terraform -chdir=terraform/envs/qa providers lock -platform=windows_amd64 -platform=darwin_amd64 -platform=darwin_arm64 -platform=linux_amd64 -platform=linux_arm64 |
| 103 | + terraform -chdir=terraform/envs/prod providers lock -platform=windows_amd64 -platform=darwin_amd64 -platform=darwin_arm64 -platform=linux_amd64 -platform=linux_arm64 |
0 commit comments