Files
miti99bot/Makefile
T
tiennm99 f3b9891a54 refactor: rename module to miti99bot, canonicalize AWS deploy path
Rename:
- Go module github.com/tiennm99/miti99bot-go → github.com/tiennm99/miti99bot
- CloudFormation stack miti99bot-aws-port → miti99bot
- Drop "port", "Cloud Run", "GCP", "cutover", "Phase NN" framing from
  active code and docs — project reads as canonical AWS-Lambda from now on.

AWS deploy guide + flow fix:
- New docs/deploy-aws-free-tier-guide.md — Ubuntu 24.04 ARM64 onboarding
  with project-local venv (pip awscli + sam-cli), SSM secrets via read -s,
  idempotent OIDC provider + role creation, $1 budget alarm.
- Drop sam build from the pipeline — provided.al2023 + makefile builder
  expects a Makefile in CodeUri (build/lambda/, the output dir), so the
  step always fails. sam deploy --template-file template.yaml now reads
  the raw template and zips build/lambda/ directly.
- Rollback section rewritten — use continue-update-rollback /
  cancel-update-stack / git-SHA redeploy. Drop the broken
  --use-previous-template recipe.
- DynamoDB free-tier row corrected (on-demand is 2.5M read / 1M write
  request units, not 25 RCU/WCU).

Updated:
- README.md fully rewritten (drops port/legacy framing, lists modules,
  points new users at the free-tier guide).
- aws/README.md retitled "AWS account setup", phase numbers stripped.
- Makefile / .github/workflows/deploy.yml — sam deploy flow.
- samconfig.toml — stack_name = "miti99bot".
- Go comments — Cloud Run → Lambda, Cloud Scheduler → EventBridge
  Scheduler, Cloud Logging → CloudWatch Logs.
- Struct field GCPProject → FirestoreProject (env GOOGLE_CLOUD_PROJECT
  unchanged).

Plus advisory reports under plans/reports/ from the code-reviewer +
researcher passes that informed the fixes.

Verified: go vet ./..., go build ./..., go test ./... all green.
2026-05-13 22:05:38 +07:00

101 lines
4.1 KiB
Makefile

.PHONY: help test test-emulator test-dynamodb firestore-emulator dynamodb-local dynamodb-local-stop vet build build-lambda run sam-validate sam-build sam-deploy logs clean
# Lambda target architecture. Match Globals.Architectures in template.yaml.
LAMBDA_GOOS ?= linux
LAMBDA_GOARCH ?= arm64
LAMBDA_OUT := build/lambda/bootstrap
help: ## Show this help
@grep -hE '^[a-zA-Z0-9_-]+:.*?## ' $(MAKEFILE_LIST) | awk 'BEGIN {FS=":.*?## "}; {printf " \033[36m%-22s\033[0m %s\n", $$1, $$2}'
# ---- Test ------------------------------------------------------------------
# Default: run unit tests that don't require any emulator.
test: ## Unit tests (no emulator required)
go test -race -count=1 ./...
# Start a local Firestore emulator (separate terminal). Requires gcloud SDK
# with the cloud-firestore-emulator component installed:
# gcloud components install cloud-firestore-emulator
firestore-emulator: ## Start Firestore emulator on :8085 (foreground)
gcloud emulators firestore start --host-port=localhost:8085
# Run all tests including Firestore-emulator-gated ones. Expects the emulator
# to already be running (use `make firestore-emulator` in another shell).
test-emulator: ## Run tests with Firestore emulator (must be running)
FIRESTORE_EMULATOR_HOST=localhost:8085 \
GOOGLE_CLOUD_PROJECT=miti99bot-test \
go test -race -count=1 ./...
# Run DynamoDB integration tests against DynamoDB Local.
# Override DDB_PORT if 8001 is taken on your host.
DDB_PORT ?= 8001
test-dynamodb: dynamodb-local ## Run DynamoDB tests against DynamoDB Local
DYNAMODB_LOCAL_URL=http://localhost:$(DDB_PORT) LOG_LEVEL=error \
go test -race -count=1 ./internal/storage/...
# ---- Lint / Vet -----------------------------------------------------------
vet: ## go vet
go vet ./...
# ---- Build ----------------------------------------------------------------
build: ## Build the local server binary (host arch)
CGO_ENABLED=0 go build -ldflags="-s -w" -o ./bin/server ./cmd/server
build-lambda: ## Cross-compile bootstrap for Lambda (linux/arm64)
@mkdir -p $(dir $(LAMBDA_OUT))
CGO_ENABLED=0 GOOS=$(LAMBDA_GOOS) GOARCH=$(LAMBDA_GOARCH) \
go build -tags lambda.norpc -ldflags="-s -w" \
-o $(LAMBDA_OUT) ./cmd/server
@chmod +x $(LAMBDA_OUT)
@ls -lh $(LAMBDA_OUT) | awk '{print "lambda binary:", $$5}'
# ---- Run ------------------------------------------------------------------
# Local dev run with an in-memory KV (no Firestore / DynamoDB needed).
run: ## Run locally (in-memory KV)
go run ./cmd/server
# ---- DynamoDB Local for tests ---------------------------------------------
dynamodb-local: ## Start DynamoDB Local container on :$(DDB_PORT) (idempotent)
@if ! docker ps --format '{{.Names}}' | grep -q '^miti99bot-ddb$$'; then \
docker run -d --rm --name miti99bot-ddb -p $(DDB_PORT):8000 \
amazon/dynamodb-local -jar DynamoDBLocal.jar -inMemory -sharedDb; \
echo "DynamoDB Local started on :$(DDB_PORT)"; \
sleep 1; \
else \
echo "DynamoDB Local already running"; \
fi
dynamodb-local-stop: ## Stop DynamoDB Local
-docker stop miti99bot-ddb
# ---- SAM (require AWS CLI + SAM CLI installed locally) -------------------
sam-validate: ## Validate template.yaml without contacting AWS
sam validate --lint
sam-build: build-lambda ## Produce the Lambda artifact (alias for build-lambda; sam deploy uses raw template directly)
@echo "Artifact ready at build/lambda/bootstrap; sam deploy --template-file template.yaml will zip it."
sam-deploy: build-lambda ## Deploy via SAM (uses samconfig.toml). Set ALERT_EMAIL=… optionally.
@if [ -n "$$ALERT_EMAIL" ]; then \
sam deploy --template-file template.yaml \
--no-confirm-changeset --no-fail-on-empty-changeset \
--parameter-overrides "AlertEmail=$$ALERT_EMAIL"; \
else \
sam deploy --template-file template.yaml \
--no-confirm-changeset --no-fail-on-empty-changeset; \
fi
logs: ## Tail Lambda logs (last 5m). Override with SINCE=10m.
@sam logs --tail --stack-name miti99bot --start-time $${SINCE:-5m}ago
# ---- Clean ----------------------------------------------------------------
clean: ## Remove local build artifacts
rm -rf build/ bin/ .aws-sam/ cov.out