Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
68 lines (53 loc) · 2.44 KB
/
Copy pathMakefile
File metadata and controls
68 lines (53 loc) · 2.44 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
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := help
# Layers depend on each other's state: never run targets in parallel, even if MAKEFLAGS sets -j.
.NOTPARALLEL:
PROJECT ?= egp
REGION ?= eu-north-1
# Ephemeral layers in apply order; `down` destroys them in reverse.
LAYERS := 10-network 20-cluster 30-data
ACCOUNT_ID = $(shell aws sts get-caller-identity --query Account --output text)
STATE_BUCKET = $(PROJECT)-tfstate-$(ACCOUNT_ID)
TF = terraform -chdir=infra/live/$*
BACKEND_ARGS = -backend-config=../backend.hcl -backend-config="bucket=$(STATE_BUCKET)" \
-backend-config="kms_key_id=arn:aws:kms:$(REGION):$(ACCOUNT_ID):alias/$(PROJECT)-tfstate"
##@ Infrastructure
.PHONY: bootstrap
bootstrap: ## One-time: create the state bucket and KMS key (local state)
terraform -chdir=infra/bootstrap init -input=false
terraform -chdir=infra/bootstrap apply
init-%: ## terraform init a layer, e.g. make init-00-foundation
$(TF) init -input=false -reconfigure $(BACKEND_ARGS)
plan-%: init-% ## terraform plan a layer
$(TF) plan -input=false
apply-%: init-% ## terraform apply a layer
$(TF) apply -input=false $(if $(AUTO_APPROVE),-auto-approve)
destroy-%: init-% ## terraform destroy a layer
$(TF) destroy -input=false $(if $(AUTO_APPROVE),-auto-approve)
.PHONY: up
up: $(addprefix apply-,$(LAYERS)) ## Create the ephemeral environment (network -> cluster -> data)
.PHONY: down
down: ## Clean up controller-created AWS resources, then destroy data -> cluster -> network
PROJECT=$(PROJECT) REGION=$(REGION) ./scripts/platform-down.sh
.PHONY: allow-ip
allow-ip: ## Let this machine's public IP reach the UIs (KEEP=1 to add, EXTRA=cidr,... for more)
REGION=$(REGION) PROJECT=$(PROJECT) ./scripts/allow-ip.sh
##@ Application
.PHONY: test
test: ## Go vet + unit tests
cd apps && go vet ./... && go test -race ./...
.PHONY: local-up
local-up: ## Run api + worker with Postgres and ElasticMQ in Docker
docker compose -f local/compose.yaml up --build -d
@echo "api: http://localhost:8080 worker metrics: http://localhost:8081/metrics"
.PHONY: local-down
local-down:
docker compose -f local/compose.yaml down -v
##@ Quality
.PHONY: lint
lint: ## Run all pre-commit hooks on every file
pre-commit run --all-files
.PHONY: help
help:
@awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z0-9_%-]+:.*##/ {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2} /^##@/ {printf "\n\033[1m%s\033[0m\n", substr($$0, 5)}' $(MAKEFILE_LIST)