-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
150 lines (124 loc) · 4.63 KB
/
Copy pathmakefile
File metadata and controls
150 lines (124 loc) · 4.63 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
139
140
141
142
143
144
145
146
147
148
149
150
.PHONY: test coverage coverage-html clean-test build up down logs logs-cw tf-init tf-apply tf-destroy run-producer seed diag diag-sns diag-sqs diag-dlq diag-dynamo clean-queues clean-sqs clean-dlq
PRODUCER_MAIN = ./cmd/producer/main.go
COVER_IGNORE='mocks/|tests/|cmd/'
TF_DOCKER = docker run --rm -v "$(PWD):/app" -w /app/terraform/envs/local --network host hashicorp/terraform:latest
PY_DOCKER = docker run --rm -it -v "$(PWD):/app" -w /app --network host
test:
go test -v ./...
coverage:
go test -coverpkg=./... -coverprofile=coverage.tmp ./...
grep -v -E $(COVER_IGNORE) coverage.tmp > coverage.out || true
rm coverage.tmp
go tool cover -func=coverage.out
coverage-html: coverage
go tool cover -html=coverage.out
clean-test:
rm -f coverage.out coverage.tmp
build:
@echo "building..."
mkdir -p build
docker run --rm \
-v "$(PWD):/app" \
-w /app \
-e GOOS=linux \
-e GOARCH=amd64 \
-e CGO_ENABLED=0 \
golang:1.25 \
go build -tags lambda.norpc -o build/bootstrap cmd/lambda/main.go
cd build && zip function.zip bootstrap
up: build
@echo "Subindo a infraestrutura e aguardando LocalStack ficar pronto..."
docker compose up -d --wait
@echo "LocalStack está saudável! Iniciando o Terraform..."
$(MAKE) tf-apply
$(MAKE) seed
down:
$(MAKE) tf-destroy
-docker compose down -v
rm -rf build/
logs:
docker compose logs -f localstack
logs-cw:
@echo "Coletando outputs do Terraform..."
$(eval LAMBDA_NAME := $(shell $(TF_DOCKER) output -raw lambda_name))
@echo "Nome da função Lambda: $(LAMBDA_NAME)"
docker compose exec localstack awslocal logs filter-log-events \
--log-group-name /aws/lambda/$(LAMBDA_NAME) \
--query 'events[*].message' \
--output text
diag: diag-sns diag-sqs diag-dlq diag-dynamo
diag-sns:
@echo "=== SNS: subscriptions ==="
$(eval TOPIC_ARN := $(shell $(TF_DOCKER) output -raw event_topic_arn))
docker compose exec localstack awslocal sns list-subscriptions-by-topic \
--topic-arn $(TOPIC_ARN) \
--query 'Subscriptions[*].{Protocol:Protocol,Endpoint:Endpoint,SubscriptionArn:SubscriptionArn}' \
--output table
diag-sqs:
@echo "=== SQS: mensagens na fila ==="
$(eval QUEUE_URL := $(shell $(TF_DOCKER) output -raw queue_url))
docker compose exec localstack awslocal sqs get-queue-attributes \
--queue-url $(QUEUE_URL) \
--attribute-names ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible ApproximateNumberOfMessagesDelayed \
--query 'Attributes' \
--output table
diag-dlq:
@echo "=== DLQ: contagem e preview ==="
$(eval DLQ_URL := $(shell $(TF_DOCKER) output -raw dlq_url))
docker compose exec localstack awslocal sqs get-queue-attributes \
--queue-url $(DLQ_URL) \
--attribute-names ApproximateNumberOfMessages \
--query 'Attributes' \
--output table
@echo "--- mensagens na DLQ (peek, visibility=30s) ---"
docker compose exec localstack awslocal sqs receive-message \
--queue-url $(DLQ_URL) \
--max-number-of-messages 5 \
--message-attribute-names All \
--visibility-timeout 30 \
--query 'Messages[*].{Id:MessageId,Attributes:MessageAttributes,Body:Body}' \
--output json
clean-queues: clean-sqs clean-dlq
@echo "Filas limpas!"
clean-sqs:
@echo "Limpando SQS event-queue..."
$(eval QUEUE_URL := $(shell $(TF_DOCKER) output -raw queue_url))
docker compose exec localstack awslocal sqs purge-queue --queue-url $(QUEUE_URL)
@echo "✓ SQS event-queue purgada"
clean-dlq:
@echo "Limpando SQS event-dlq..."
$(eval DLQ_URL := $(shell $(TF_DOCKER) output -raw dlq_url))
docker compose exec localstack awslocal sqs purge-queue --queue-url $(DLQ_URL)
@echo "✓ SQS event-dlq purgada"
tf-init:
@echo "Inicializando Terraform via Docker..."
$(TF_DOCKER) init
tf-apply: tf-init
@echo "Aplicando infraestrutura..."
$(TF_DOCKER) apply -auto-approve
tf-destroy:
@echo "Destruindo infraestrutura..."
$(TF_DOCKER) destroy -auto-approve
run-producer:
@echo "Coletando outputs do Terraform..."
$(eval TOPIC_ARN := $(shell $(TF_DOCKER) output -raw event_topic_arn))
@echo "ARN do tópico: $(TOPIC_ARN)"
AWS_REGION=us-east-1 \
AWS_ACCESS_KEY_ID=test \
AWS_SECRET_ACCESS_KEY=test \
AWS_ENDPOINT_URL="http://localhost:4566" \
TOPIC_ARN=${TOPIC_ARN} \
go run $(PRODUCER_MAIN)
seed:
@echo "Coletando outputs do Terraform..."
$(eval SCHEMAS_TABLE := $(shell $(TF_DOCKER) output -raw schemas_table_name))
@echo "Tabela de schemas encontrada: $(SCHEMAS_TABLE)"
@echo "Inserindo schemas iniciais via Docker..."
$(PY_DOCKER) \
-e SCHEMAS_TABLE_NAME=$(SCHEMAS_TABLE) \
-e AWS_ENDPOINT_URL=http://localhost:4566 \
-e AWS_ACCESS_KEY_ID=test \
-e AWS_SECRET_ACCESS_KEY=test \
-e AWS_DEFAULT_REGION=us-east-1 \
python:3.11-slim \
bash -c "pip install boto3 -q && python scripts/seed.py"