Skip to content

Commit f1c6f42

Browse files
committed
Move to scripts
1 parent 51a96a6 commit f1c6f42

File tree

4 files changed

+31
-73
lines changed

4 files changed

+31
-73
lines changed

docker/compose.full.yaml

Lines changed: 7 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,9 @@ services:
6969

7070
hatchet-create-db:
7171
image: postgres:latest
72-
command: >
73-
sh -c "
74-
set -e
75-
echo 'Waiting for PostgreSQL to be ready...'
76-
while ! pg_isready -h hatchet-postgres -p 5432 -U ${HATCHET_POSTGRES_USER:-hatchet_user}; do
77-
sleep 1
78-
done
79-
echo 'PostgreSQL is ready, checking if database exists...'
80-
if ! PGPASSWORD=${HATCHET_POSTGRES_PASSWORD:-hatchet_password} psql -h hatchet-postgres -p 5432 -U ${HATCHET_POSTGRES_USER:-hatchet_user} -lqt | grep -qw ${HATCHET_POSTGRES_DBNAME:-hatchet}; then
81-
echo 'Database does not exist, creating it...'
82-
PGPASSWORD=${HATCHET_POSTGRES_PASSWORD:-hatchet_password} createdb -h hatchet-postgres -p 5432 -U ${HATCHET_POSTGRES_USER:-hatchet_user} -w ${HATCHET_POSTGRES_DBNAME:-hatchet}
83-
else
84-
echo 'Database already exists, skipping creation.'
85-
fi
86-
"
72+
command: sh /scripts/create-hatchet-db.sh
73+
volumes:
74+
- ./scripts:/scripts
8775
environment:
8876
DATABASE_URL: "postgres://${HATCHET_POSTGRES_USER:-hatchet_user}:${HATCHET_POSTGRES_PASSWORD:-hatchet_password}@hatchet-postgres:5432/${HATCHET_POSTGRES_DBNAME:-hatchet}?sslmode=disable"
8977

@@ -169,58 +157,9 @@ services:
169157

170158
setup-token:
171159
image: ghcr.io/hatchet-dev/hatchet/hatchet-admin:v0.53.15
172-
command: >
173-
sh -c "
174-
set -e
175-
echo 'Starting token creation process...'
176-
177-
# Attempt to create token and capture both stdout and stderr
178-
TOKEN_OUTPUT=$$(/hatchet/hatchet-admin token create --config /hatchet/config --tenant-id 707d0855-80ab-4e1f-a156-f1c4546cbf52 2>&1)
179-
180-
# Extract the token (assuming it's the only part that looks like a JWT)
181-
TOKEN=$$(echo \"$$TOKEN_OUTPUT\" | grep -Eo 'eyJ[A-Za-z0-9_-]*\.eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*')
182-
183-
if [ -z \"$$TOKEN\" ]; then
184-
echo 'Error: Failed to extract token. Full command output:' >&2
185-
echo \"$$TOKEN_OUTPUT\" >&2
186-
exit 1
187-
fi
188-
189-
echo \"$$TOKEN\" > /tmp/hatchet_api_key
190-
echo 'Token created and saved to /tmp/hatchet_api_key'
191-
192-
# Copy token to final destination
193-
echo -n \"$$TOKEN\" > /hatchet_api_key/api_key.txt
194-
echo 'Token copied to /hatchet_api_key/api_key.txt'
195-
196-
# Verify token was copied correctly
197-
if [ \"$$(cat /tmp/hatchet_api_key)\" != \"$(cat /hatchet_api_key/api_key.txt)\" ]; then
198-
echo 'Error: Token copy failed, files do not match' >&2
199-
echo 'Content of /tmp/hatchet_api_key:'
200-
cat /tmp/hatchet_api_key
201-
echo 'Content of /hatchet_api_key/api_key.txt:'
202-
cat /hatchet_api_key/api_key.txt
203-
exit 1
204-
fi
205-
206-
echo 'Hatchet API key has been saved successfully'
207-
echo 'Token length:' $${#TOKEN}
208-
echo 'Token (first 20 chars):' $${TOKEN:0:20}
209-
echo 'Token structure:' $$(echo $$TOKEN | awk -F. '{print NF-1}') 'parts'
210-
# Check each part of the token
211-
for i in 1 2 3; do
212-
PART=$$(echo $$TOKEN | cut -d. -f$$i)
213-
echo 'Part' $$i 'length:' $${#PART}
214-
echo 'Part' $$i 'base64 check:' $$(echo $$PART | base64 -d >/dev/null 2>&1 && echo 'Valid' || echo 'Invalid')
215-
done
216-
# Final validation attempt
217-
if ! echo $$TOKEN | awk -F. '{print $$2}' | base64 -d 2>/dev/null | jq . >/dev/null 2>&1; then
218-
echo 'Warning: Token payload is not valid JSON when base64 decoded' >&2
219-
else
220-
echo 'Token payload appears to be valid JSON'
221-
fi
222-
"
160+
command: sh /scripts/setup-token.sh
223161
volumes:
162+
- ./scripts:/scripts
224163
- hatchet_certs:/hatchet/certs
225164
- hatchet_config:/hatchet/config
226165
- hatchet_api_key:/hatchet_api_key
@@ -252,13 +191,7 @@ services:
252191
- "${R2R_PORT:-7272}:${R2R_PORT:-7272}"
253192
env_file:
254193
- ./env/r2r.env
255-
command: >
256-
sh -c '
257-
if [ -z "$${HATCHET_CLIENT_TOKEN}" ]; then
258-
export HATCHET_CLIENT_TOKEN=$$(cat /hatchet_api_key/api_key.txt)
259-
fi
260-
exec uvicorn core.main.app_entry:app --host $${R2R_HOST} --port $${R2R_PORT}
261-
'
194+
command: sh /scripts/start-r2r.sh
262195
healthcheck:
263196
test: ["CMD", "curl", "-f", "http://localhost:${R2R_PORT:-7272}/v3/health"]
264197
interval: 6s
@@ -268,6 +201,7 @@ services:
268201
volumes:
269202
- ${R2R_CONFIG_PATH:-/}:${R2R_CONFIG_PATH:-/app/config}
270203
- hatchet_api_key:/hatchet_api_key:ro
204+
- ./scripts:/scripts
271205
extra_hosts:
272206
- host.docker.internal:host-gateway
273207
depends_on:

docker/scripts/create-hatchet-db.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -e
4+
echo 'Waiting for PostgreSQL to be ready...'
5+
while ! pg_isready -h hatchet-postgres -p 5432 -U ${HATCHET_POSTGRES_USER:-hatchet_user}; do
6+
sleep 1
7+
done
8+
9+
echo 'PostgreSQL is ready, checking if database exists...'
10+
if ! PGPASSWORD=${HATCHET_POSTGRES_PASSWORD:-hatchet_password} psql -h hatchet-postgres -p 5432 -U ${HATCHET_POSTGRES_USER:-hatchet_user} -lqt | grep -qw ${HATCHET_POSTGRES_DBNAME:-hatchet}; then
11+
echo 'Database does not exist, creating it...'
12+
PGPASSWORD=${HATCHET_POSTGRES_PASSWORD:-hatchet_password} createdb -h hatchet-postgres -p 5432 -U ${HATCHET_POSTGRES_USER:-hatchet_user} -w ${HATCHET_POSTGRES_DBNAME:-hatchet}
13+
else
14+
echo 'Database already exists, skipping creation.'
15+
fi
File renamed without changes.

docker/scripts/start-r2r.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
# Check if HATCHET_CLIENT_TOKEN is set, if not read it from the API key file
4+
if [ -z "${HATCHET_CLIENT_TOKEN}" ]; then
5+
export HATCHET_CLIENT_TOKEN=$(cat /hatchet_api_key/api_key.txt)
6+
fi
7+
8+
# Start the application
9+
exec uvicorn core.main.app_entry:app --host ${R2R_HOST} --port ${R2R_PORT}

0 commit comments

Comments
 (0)