142
142
# export for psql, etc.
143
143
export PGPASSWORD=postgres
144
144
145
- DB_URL=" postgres://postgres:$PGPASSWORD @127.0.0.1:$PG_PORT /postgres"
145
+ # The URL for the postgres server we might launch
146
+ CONTAINER_DB_URL=" postgres://postgres:$PGPASSWORD @127.0.0.1:$PG_PORT /postgres"
147
+ # ... but we might like to use a different PG instance when just launching graphql-engine:
148
+ HASURA_GRAPHQL_DATABASE_URL=${HASURA_GRAPHQL_DATABASE_URL-$CONTAINER_DB_URL }
146
149
147
150
PG_CONTAINER_NAME=" hasura-dev-postgres-$PG_PORT "
148
151
149
- # We can remove psql as a dependency:
150
- DOCKER_PSQL=" docker exec -u postgres -it $PG_CONTAINER_NAME psql -p $PG_PORT "
152
+ # We can remove psql as a dependency by using it from the (running) PG container :
153
+ DOCKER_PSQL=" docker exec -u postgres -it $PG_CONTAINER_NAME psql $HASURA_GRAPHQL_DATABASE_URL "
151
154
152
- function wait_docker_postgres {
155
+ function wait_postgres {
153
156
echo -n " Waiting for postgres to come up"
154
- until $DOCKER_PSQL postgres -c ' \l' & > /dev/null; do
157
+ until ( $DOCKER_PSQL -c ' \l ' || psql $HASURA_GRAPHQL_DATABASE_URL -c ' \l' ) & > /dev/null; do
155
158
echo -n ' .' && sleep 0.2
156
159
done
157
160
echo " Ok"
@@ -202,26 +205,28 @@ if [ "$MODE" = "graphql-engine" ]; then
202
205
}
203
206
trap cleanup EXIT
204
207
205
-
208
+ export HASURA_GRAPHQL_DATABASE_URL # Defined above
206
209
export HASURA_GRAPHQL_SERVER_PORT=${HASURA_GRAPHQL_SERVER_PORT-8181}
207
210
208
- echo_pretty " We will connect to postgres container '$PG_CONTAINER_NAME '"
209
- echo_pretty " If you haven't yet, please launch a postgres container in a separate terminal with:"
211
+ echo_pretty " We will connect to postgres at '$HASURA_GRAPHQL_DATABASE_URL '"
212
+ echo_pretty " If you haven't overridden HASURA_GRAPHQL_DATABASE_URL, you can"
213
+ echo_pretty " launch a fresh postgres container for us to connect to, in a"
214
+ echo_pretty " separate terminal with:"
210
215
echo_pretty " $ $0 postgres"
211
- echo_pretty " or press CTRL-C and invoke graphql-engine manually"
212
216
echo_pretty " "
213
217
214
- RUN_INVOCATION=(cabal new-run --project-file=cabal.project.dev-sh --RTS -- exe:graphql-engine +RTS -N -T -RTS
215
- --database-url=" $DB_URL " serve
216
- --enable-console --console-assets-dir " $PROJECT_ROOT /console/static/dist" )
218
+ RUN_INVOCATION=(cabal new-run --project-file=cabal.project.dev-sh --RTS --
219
+ exe:graphql-engine +RTS -N -T -s -RTS serve
220
+ --enable-console --console-assets-dir " $PROJECT_ROOT /console/static/dist"
221
+ )
217
222
218
223
echo_pretty ' About to do:'
219
224
echo_pretty ' $ cabal new-build --project-file=cabal.project.dev-sh exe:graphql-engine'
220
225
echo_pretty " $ ${RUN_INVOCATION[*]} "
221
226
echo_pretty ' '
222
227
223
228
cabal new-build --project-file=cabal.project.dev-sh exe:graphql-engine
224
- wait_docker_postgres
229
+ wait_postgres
225
230
226
231
# Print helpful info after startup logs so it's visible:
227
232
{
337
342
338
343
if [ " $MODE " = " postgres" ]; then
339
344
launch_postgres_container
340
- wait_docker_postgres
345
+ wait_postgres
341
346
echo_pretty " Postgres logs will start to show up in realtime here. Press CTRL-C to exit and "
342
347
echo_pretty " shutdown this container."
343
348
echo_pretty " "
@@ -347,7 +352,7 @@ if [ "$MODE" = "postgres" ]; then
347
352
echo_pretty " $ PGPASSWORD=" $PGPASSWORD " psql -h 127.0.0.1 -p " $PG_PORT " postgres -U postgres"
348
353
echo_pretty " "
349
354
echo_pretty " Here is the database URL:"
350
- echo_pretty " $DB_URL "
355
+ echo_pretty " $CONTAINER_DB_URL "
351
356
echo_pretty " "
352
357
echo_pretty " If you want to launch a 'graphql-engine' that works with this database:"
353
358
echo_pretty " $ $0 graphql-engine"
@@ -375,19 +380,19 @@ elif [ "$MODE" = "test" ]; then
375
380
# rebuilding twice... ugh
376
381
cabal new-build --project-file=cabal.project.dev-sh exe:graphql-engine test:graphql-engine-tests
377
382
launch_postgres_container
378
- wait_docker_postgres
383
+ wait_postgres
379
384
380
385
# These also depend on a running DB:
381
386
if [ " $RUN_UNIT_TESTS " = true ]; then
382
387
echo_pretty " Running Haskell test suite"
383
- HASURA_GRAPHQL_DATABASE_URL=" $DB_URL " cabal new-run --project-file=cabal.project.dev-sh -- test:graphql-engine-tests
388
+ HASURA_GRAPHQL_DATABASE_URL=" $CONTAINER_DB_URL " cabal new-run --project-file=cabal.project.dev-sh -- test:graphql-engine-tests
384
389
fi
385
390
386
391
if [ " $RUN_INTEGRATION_TESTS " = true ]; then
387
392
GRAPHQL_ENGINE_TEST_LOG=/tmp/hasura-dev-test-engine.log
388
393
echo_pretty " Starting graphql-engine, logging to $GRAPHQL_ENGINE_TEST_LOG "
389
394
export HASURA_GRAPHQL_SERVER_PORT=8088
390
- cabal new-run --project-file=cabal.project.dev-sh -- exe:graphql-engine --database-url=" $DB_URL " serve --stringify-numeric-types \
395
+ cabal new-run --project-file=cabal.project.dev-sh -- exe:graphql-engine --database-url=" $CONTAINER_DB_URL " serve --stringify-numeric-types \
391
396
--enable-console --console-assets-dir ../console/static/dist \
392
397
& > " $GRAPHQL_ENGINE_TEST_LOG " & GRAPHQL_ENGINE_PID=$!
393
398
@@ -449,7 +454,7 @@ elif [ "$MODE" = "test" ]; then
449
454
450
455
451
456
# TODO MAYBE: fix deprecation warnings, make them an error
452
- if pytest -W ignore::DeprecationWarning --hge-urls http://127.0.0.1:$HASURA_GRAPHQL_SERVER_PORT --pg-urls " $DB_URL " $PYTEST_ARGS ; then
457
+ if pytest -W ignore::DeprecationWarning --hge-urls http://127.0.0.1:$HASURA_GRAPHQL_SERVER_PORT --pg-urls " $CONTAINER_DB_URL " $PYTEST_ARGS ; then
453
458
PASSED=true
454
459
else
455
460
PASSED=false
0 commit comments