-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (122 loc) · 5.19 KB
/
Makefile
File metadata and controls
138 lines (122 loc) · 5.19 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
.PHONY: run-local run-prod deploy-local deploy-lab deploy-prod clean clean-all clean-nuclear del-local del-lab del-prod build-lambdas build-lambdas-powershell build-create build-lookup
# Build Lambda functions (requires zip command)
build-create:
@mkdir -p src/create/bin
@cd src/create && go mod tidy && \
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o bin/bootstrap main.go && \
rm -f bin/*.zip && \
cd bin && zip -j function.zip bootstrap
build-lookup:
@mkdir -p src/redirect/bin
@cd src/redirect && go mod tidy && \
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o bin/bootstrap main.go && \
rm -f bin/*.zip && \
cd bin && zip -j function.zip bootstrap
build-lambdas: build-create build-lookup
# Build Lambda functions (PowerShell alternative for Windows)
build-lambdas-powershell:
@mkdir -p src/create/bin src/redirect/bin
@cd src/create && go mod tidy && \
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o bin/bootstrap main.go
@cd src/redirect && go mod tidy && \
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o bin/bootstrap main.go
@powershell -Command "Compress-Archive -Path src/create/bin/bootstrap -DestinationPath src/create/bin/function.zip -Force"
@powershell -Command "Compress-Archive -Path src/redirect/bin/bootstrap -DestinationPath src/redirect/bin/function.zip -Force"
clean:
@cd terraform && rm -rf .terraform .terraform.lock.hcl
# Complete cleanup - remove all build artifacts and terraform cache (preserves workspace state for proper cleanup)
clean-all:
@echo "Cleaning build artifacts and terraform cache..."
@rm -f src/create/bin/*.zip src/redirect/bin/*.zip
@cd terraform && rm -rf .terraform .terraform.lock.hcl
@docker-compose down 2>/dev/null || true
# Nuclear cleanup - WARNING: removes ALL terraform state (use only if you're sure no resources need cleanup)
clean-nuclear:
@echo "WARNING: This will remove ALL terraform state files!"
@echo "Make sure all cloud resources are cleaned up first with del-local, del-dev, del-prod"
@read -p "Are you sure? [y/N]: " confirm && [ "$$confirm" = "y" ] || exit 1
@rm -f src/create/bin/*.zip src/redirect/bin/*.zip
@cd terraform && rm -rf .terraform .terraform.lock.hcl terraform.tfstate* terraform.tfstate.d/
@docker-compose down 2>/dev/null || true
# Deploy to LocalStack (requires Lambda functions to be built first)
deploy-local: clean
@docker-compose up -d
@cd terraform && \
terraform init \
-backend-config=envs/local/backend.conf \
-reconfigure && \
terraform workspace select local 2>/dev/null || \
terraform workspace new local
@cd terraform && \
terraform apply \
-var-file=terraform.tfvars.local \
-auto-approve
# Deploy to AWS Learner Lab (requires Lambda functions to be built first)
deploy-lab: clean
@echo "Deploying to AWS Learner Lab..."
@echo "Make sure you have AWS CLI configured with Learner Lab credentials"
@cd terraform && \
terraform init -reconfigure && \
terraform workspace select lab 2>/dev/null || \
terraform workspace new lab
@cd terraform && \
terraform apply \
-var-file=terraform.tfvars.lab \
-auto-approve
# Deploy to AWS production (requires Lambda functions to be built first)
deploy-prod: clean
@echo "Deploying to AWS Production..."
@echo "WARNING: This requires terraform.tfvars.prod to be configured with certificate_arn for custom domain"
@echo "Make sure you have production AWS credentials configured"
@cd terraform && \
terraform init -reconfigure && \
terraform workspace select prod 2>/dev/null || \
terraform workspace new prod
@cd terraform && \
terraform apply \
-var-file=terraform.tfvars.prod
# Backward compatibility with helpful messages
run-local:
@echo "Note: run-local now requires building Lambda functions first"
@echo "Run one of:"
@echo " make build-lambdas (if you have zip command)"
@echo " make build-lambdas-powershell (Windows/PowerShell users)"
@echo "Then run:"
@echo " make deploy-local"
run-prod:
@echo "Note: run-prod now requires building Lambda functions first"
@echo "Run one of:"
@echo " make build-lambdas (if you have zip command)"
@echo " make build-lambdas-powershell (Windows/PowerShell users)"
@echo "Then run:"
@echo " make deploy-prod"
del-local:
@cd terraform && terraform init \
-backend-config=envs/local/backend.conf \
-reconfigure && \
terraform workspace select local && \
terraform destroy \
-var-file=terraform.tfvars.local \
-auto-approve && \
terraform workspace select default && \
terraform workspace delete local
@docker-compose down
del-lab:
@cd terraform && terraform init -reconfigure && \
terraform workspace select lab && \
terraform destroy \
-var-file=terraform.tfvars.lab \
-auto-approve && \
terraform workspace select default && \
terraform workspace delete lab
# Alias for backward compatibility - delete Learner Lab deployment
del-dev: del-lab
del-prod:
@echo "Deleting AWS Production deployment..."
@cd terraform && terraform init -reconfigure && \
terraform workspace select prod && \
terraform destroy \
-var-file=terraform.tfvars.prod \
-auto-approve && \
terraform workspace select default && \
terraform workspace delete prod