Skip to content

Commit 6993bf7

Browse files
committed
add quick start script
1 parent 81e0134 commit 6993bf7

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ docker build -t order-api .
6262

6363
# Run (with LocalStack env vars)
6464
export SQS_QUEUE_URL=$(cd ../infra && terraform output -raw sqs_queue_url)
65-
export DDB_TABLE=$(cd ../infra && terraform output -raw dynamodb_table)
65+
export DDB_TABLE=$(cd ../infra && terraform output -raw dynamodb_table_name)
6666
export AWS_ENDPOINT_URL=http://host.docker.internal:4566 # for Docker → LocalStack
6767

6868
docker run -p 8000:8000 \

scripts/quickstart.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
# Quick start local integration with LocalStack + Terraform + Docker services
3+
# Usage: ./scripts/localstack-quickstart.sh
4+
5+
set -euo pipefail
6+
cd "$(dirname "$(realpath "$0")")/.."
7+
8+
check_cmd() { command -v "$1" >/dev/null 2>&1 || { echo "Required command '$1' not found. Install it and retry."; exit 2; } }
9+
10+
check_cmd docker
11+
check_cmd terraform
12+
check_cmd aws
13+
check_cmd docker-compose || true
14+
15+
echo "1/5 Starting LocalStack..."
16+
cd localstack
17+
docker compose down -v || true
18+
docker compose up -d
19+
sleep 15
20+
21+
echo "2/5 Applying infra (terraform)..."
22+
cd ../infra
23+
rm -rf .terraform* terraform.tfstate* || true
24+
terraform init -input=false
25+
terraform apply -var-file=dev.tfvars -auto-approve
26+
27+
echo "3/5 Building and running order-api..."
28+
cd ../order-api
29+
docker build -t order-api .
30+
31+
SQS_QUEUE_URL=$(cd ../infra && terraform output -raw sqs_queue_url)
32+
DDB_TABLE=$(cd ../infra && terraform output -raw dynamodb_table_name)
33+
export AWS_ENDPOINT_URL="http://host.docker.internal:4566"
34+
35+
docker rm -f order-api 2>/dev/null || true
36+
docker run -d --name order-api -p 8000:8000 \
37+
-e SQS_QUEUE_URL="$SQS_QUEUE_URL" \
38+
-e DDB_TABLE="$DDB_TABLE" \
39+
-e AWS_ENDPOINT_URL="$AWS_ENDPOINT_URL" \
40+
order-api
41+
42+
echo "4/5 Building and running order-processor..."
43+
cd ../order-processor
44+
go mod tidy
45+
docker build -t order-processor .
46+
47+
HOST_PORT=${HOST_PORT:-9091}
48+
docker rm -f order-processor 2>/dev/null || true
49+
docker run -d --name order-processor -p ${HOST_PORT}:9090 \
50+
-e SQS_QUEUE_URL="$SQS_QUEUE_URL" \
51+
-e DDB_TABLE="$DDB_TABLE" \
52+
-e AWS_ENDPOINT_URL="$AWS_ENDPOINT_URL" \
53+
order-processor
54+
55+
echo "Done. Services running:"
56+
echo " - Order API: http://localhost:8000"
57+
echo " - Processor metrics/health: http://localhost:${HOST_PORT}"
58+
echo "Tip: run ./scripts/smoke.sh to verify end-to-end."

scripts/smoke.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
cd "$(dirname "$(realpath "$0")")/.."
4+
5+
command -v curl >/dev/null 2>&1 || { echo "curl required"; exit 2; }
6+
command -v jq >/dev/null 2>&1 || { echo "jq required"; exit 2; }
7+
8+
HOST_PORT=${HOST_PORT:-9091}
9+
10+
wait_for_url() {
11+
local url=$1; local timeout=${2:-60}; local interval=2; local elapsed=0
12+
while true; do
13+
if curl -s -f "$url" >/dev/null 2>&1; then return 0; fi
14+
sleep $interval
15+
elapsed=$((elapsed + interval))
16+
if [ "$elapsed" -ge "$timeout" ]; then return 1; fi
17+
done
18+
}
19+
20+
echo "Waiting for services..."
21+
wait_for_url "http://localhost:8000/health" 60 || { echo "Order API not ready"; exit 3; }
22+
wait_for_url "http://localhost:${HOST_PORT}/health" 60 || { echo "Processor not ready"; exit 4; }
23+
24+
echo "Obtaining token..."
25+
TOKEN=$(curl -s -X POST http://localhost:8000/login -H "Content-Type: application/json" -d '{"user_id":"u123","amount":1}' | jq -r .access_token)
26+
[ -n "$TOKEN" ] && [ "$TOKEN" != "null" ] || { echo "Failed to get token"; exit 5; }
27+
28+
echo "Posting order..."
29+
ORDER_RESP=$(curl -s -X POST http://localhost:8000/orders -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d '{"user_id":"u123","amount":999}')
30+
echo "Order response: $ORDER_RESP"
31+
32+
echo "Waiting for metrics..."
33+
for i in {1..15}; do
34+
if curl -s "http://localhost:${HOST_PORT}/metrics" | grep -q orders_processed_total; then
35+
echo "Metrics:"
36+
curl -s "http://localhost:${HOST_PORT}/metrics" | grep orders_processed_total || true
37+
echo "Smoke tests passed."
38+
exit 0
39+
fi
40+
sleep 2
41+
done
42+
43+
echo "Metrics did not appear in time" >&2
44+
exit 6

0 commit comments

Comments
 (0)