-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
70 lines (50 loc) · 2.27 KB
/
Copy pathMakefile
File metadata and controls
70 lines (50 loc) · 2.27 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
# ---------------------------------------------------------------------------
# TFPlanBuilder — Developer Commands
# ---------------------------------------------------------------------------
.PHONY: help build run stop plan apply destroy fmt lint clean
PROJECT_NAME ?= tfplanbuilder
AWS_REGION ?= us-east-1
ENVIRONMENT ?= dev
IMAGE_TAG ?= local
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
# --- Application ---
build: ## Build the Docker image locally
docker build -t $(PROJECT_NAME):$(IMAGE_TAG) ./app
run: build ## Run the app locally on port 8080
docker run --rm -p 8080:8080 --name $(PROJECT_NAME) $(PROJECT_NAME):$(IMAGE_TAG)
stop: ## Stop the local container
docker stop $(PROJECT_NAME) 2>/dev/null || true
# --- Infrastructure ---
init: ## Initialize Terraform
cd infra && terraform init
plan: ## Run terraform plan
cd infra && terraform plan -var="environment=$(ENVIRONMENT)"
apply: ## Apply terraform changes
cd infra && terraform apply -var="environment=$(ENVIRONMENT)"
destroy: ## Destroy all infrastructure (asks for confirmation)
cd infra && terraform destroy -var="environment=$(ENVIRONMENT)"
# --- Quality ---
fmt: ## Format all Terraform and config files
terraform fmt -recursive infra/
@echo "Formatted."
lint: ## Validate Terraform configuration
cd infra && terraform validate
# --- CI Helpers ---
ecr-login: ## Login to ECR (requires AWS CLI configured)
aws ecr get-login-password --region $(AWS_REGION) | \
docker login --username AWS --password-stdin \
$$(aws sts get-caller-identity --query Account --output text).dkr.ecr.$(AWS_REGION).amazonaws.com
push: build ecr-login ## Build and push image to ECR
$(eval ACCOUNT_ID := $(shell aws sts get-caller-identity --query Account --output text))
$(eval REPO := $(ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(PROJECT_NAME)-app)
docker tag $(PROJECT_NAME):$(IMAGE_TAG) $(REPO):$(IMAGE_TAG)
docker tag $(PROJECT_NAME):$(IMAGE_TAG) $(REPO):latest
docker push $(REPO):$(IMAGE_TAG)
docker push $(REPO):latest
# --- Cleanup ---
clean: ## Remove local Docker images and Terraform cache
docker rmi $(PROJECT_NAME):$(IMAGE_TAG) 2>/dev/null || true
rm -rf infra/.terraform
@echo "Cleaned."