-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickstart.sh
executable file
·108 lines (87 loc) · 2.86 KB
/
quickstart.sh
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
#!/bin/bash
TEST_SCRIPT_DIR=$(dirname "$0")
TEST_RUN_ID=$(date +%Y-%m-%d_%H%M%S)
TEST_RUN_DIR="$TEST_SCRIPT_DIR/runs/$TEST_RUN_ID"
DOCKER_COMPOSE_DIR="$TEST_RUN_DIR/examples/docker-compose"
TEST_API_KEY="this_is_a_test_api_key"
echo "Creating a new test run $TEST_RUN_DIR"
mkdir "$TEST_RUN_DIR"
git clone https://github.com/hookdeck/outpost.git "$TEST_RUN_DIR"
cp .env.example "$TEST_RUN_DIR/examples/docker-compose/.env"
cd "$DOCKER_COMPOSE_DIR"
wait_for_service() {
local url=$1
local timeout=6
while ! curl --fail --silent "$url"; do
printf '.'
sleep 5
((timeout--))
if [ $timeout -le 0 ]; then
echo "Timeout reached. Exiting."
exit 1
fi
done
}
# Update the <API_KEY> value within the new .env file
sed -i '' "s/apikey/$TEST_API_KEY/" .env
docker-compose -f compose.yml -f compose-rabbitmq.yml -f compose-postgres.yml up -d
# Wait until the services are running
echo "Waiting for the services to start"
wait_for_service "localhost:3333/api/v1/healthz"
echo ""
echo "✅ Services are up and running"
echo ""
echo "Creating a tenant"
# Create a tenant
curl --location --request PUT "localhost:3333/api/v1/$TEST_RUN_ID" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TEST_API_KEY"
# Create a webhook destination
echo ""
echo "Creating a webhook destination"
curl --location "localhost:3333/api/v1/$TEST_RUN_ID/destinations" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TEST_API_KEY" \
--data "{
\"type\": \"webhook\",
\"topics\": [\"*\"],
\"config\": {
\"url\": \"http://host.docker.internal:4444/webhook/$TEST_RUN_ID\"
}
}"
# Start a simple HTTP server in the background
printf "\n\nStarting a simple HTTP server in the background"
touch "server.log"
python3 "../../../../server.py" 4444 > "server.log" 2>&1 &
printf "\nWaiting for the test server to start..."
wait_for_service "localhost:4444"
printf "\n✅ Test server started"
# Capture the server's PID to kill it later
SERVER_PID=$!
# Capture the killing of the script and kill the server
trap "kill $SERVER_PID; echo 'Script interrupted. Killing the server...'; exit 1" INT TERM
# Publish an event
printf "\n\nPublishing an event"
EVENT_BODY='{"user_id":"userid"}'
curl --location 'localhost:3333/api/v1/publish' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TEST_API_KEY" \
--data "{
\"tenant_id\": \"$TEST_RUN_ID\",
\"topic\": \"user.created\",
\"eligible_for_retry\": true,
\"metadata\": {
\"meta\": \"data\"
},
\"data\": $EVENT_BODY
}"
# Example condition: wait for a specific log entry
printf "\nWaiting for the expected event to reach test server for test run $TEST_RUN_ID..."
while ! grep -q "$EVENT_BODY" "server.log"; do
printf '.'
sleep 5
done
echo ""
echo "✅ Received the expected request. Success! Exiting."
# Now kill the server
kill $SERVER_PID