From eb9c49a3e9bb21ee4aaec7615807b72e0575cf4c Mon Sep 17 00:00:00 2001 From: Matt Griswold Date: Mon, 23 Mar 2020 18:05:39 +0000 Subject: [PATCH] update docker entrypoint --- dockerfiles/super_node/Dockerfile | 4 +- dockerfiles/super_node/entrypoint.sh | 64 ++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100755 dockerfiles/super_node/entrypoint.sh diff --git a/dockerfiles/super_node/Dockerfile b/dockerfiles/super_node/Dockerfile index af3d4f27..fbed02a6 100644 --- a/dockerfiles/super_node/Dockerfile +++ b/dockerfiles/super_node/Dockerfile @@ -44,6 +44,7 @@ USER $USER # note: using $USER is merged, but not in the stable release yet COPY --chown=5000:5000 --from=builder /go/src/github.com/vulcanize/vulcanizedb/$CONFIG_FILE config.toml COPY --chown=5000:5000 --from=builder /go/src/github.com/vulcanize/vulcanizedb/dockerfiles/super_node/startup_script.sh . +COPY --chown=5000:5000 --from=builder /go/src/github.com/vulcanize/vulcanizedb/dockerfiles/super_node/entrypoint.sh . # keep binaries immutable @@ -51,9 +52,8 @@ COPY --from=builder /go/src/github.com/vulcanize/vulcanizedb/vulcanizedb vulcani COPY --from=builder /go/src/github.com/pressly/goose/cmd/goose/goose goose COPY --from=builder /go/src/github.com/vulcanize/vulcanizedb/db/migrations migrations/vulcanizedb COPY --from=builder /go/src/github.com/ipfs/go-ipfs/ipfs ipfs -# XXX dir is already writeable RUN touch vulcanizedb.log EXPOSE $EXPOSE_PORT_1 EXPOSE $EXPOSE_PORT_2 -CMD ["./startup_script.sh"] +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/dockerfiles/super_node/entrypoint.sh b/dockerfiles/super_node/entrypoint.sh new file mode 100755 index 00000000..04dcf74c --- /dev/null +++ b/dockerfiles/super_node/entrypoint.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# Runs the db migrations and starts the super node services + +# Exit if the variable tests fail +set -e +set +x + +# Check the database variables are set +# XXX set defaults, don't silently fail +#test $DATABASE_HOSTNAME +#test $DATABASE_NAME +#test $DATABASE_PORT +#test $DATABASE_USER +#test $DATABASE_PASSWORD +#test $IPFS_INIT +#test $IPFS_PATH +VDB_COMMAND=${VARIABLE:-headerSync} +set +e + +# Construct the connection string for postgres +VDB_PG_CONNECT=postgresql://$DATABASE_USER:$DATABASE_PASSWORD@$DATABASE_HOSTNAME:$DATABASE_PORT/$DATABASE_NAME?sslmode=disable + +# Run the DB migrations +echo "Connecting with: $VDB_PG_CONNECT" +echo "Running database migrations" +./goose -dir migrations/vulcanizedb postgres "$VDB_PG_CONNECT" up +rv=$? + +if [ $rv != 0 ]; then + echo "Could not run migrations. Are the database details correct?" + exit 1 +fi + +# Export our database variables so that the IPFS Postgres plugin can use them +export IPFS_PGHOST=$DATABASE_HOSTNAME +export IPFS_PGUSER=$DATABASE_USER +export IPFS_PGDATABASE=$DATABASE_NAME +export IPFS_PGPORT=$DATABASE_PORT +export IPFS_PGPASSWORD=$DATABASE_PASSWORD + + +if [ ! -d "~/.ipfs" ]; then + # initialize PG-IPFS + echo "Initializing Postgres-IPFS profile" + ./ipfs init --profile=postgresds + + rv=$? + if [ $rv != 0 ]; then + echo "Could not initialize ipfs" + exit 1 + fi +fi + +echo "Beginning the vulcanizedb super node process" +DEFAULT_OPTIONS="--config=config.toml" +VDB_FULL_CL=${VARIABLE:-$DEFAULT_OPTIONS} +# XXX stdout, not logfile +./vulcanizedb ${VDB_COMMAND} $VDB_FULL_CL +rv=$? + +if [ $rv != 0 ]; then + echo "VulcanizeDB startup failed" + exit 1 +fi \ No newline at end of file