Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docker/node.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ RUN yarn install && yarn build

FROM onfinality/subql-node-cosmos:v0.2.0

# Add system dependencies
RUN apk update
RUN apk add postgresql14-client

# NB: add SigNoz / OpenTelemetry dependencies
WORKDIR /usr/local/lib/node_modules/@subql/node-cosmos
RUN yarn add "@grpc/grpc-js" \
Expand All @@ -32,15 +36,20 @@ RUN chmod +x /usr/local/bin/yq

WORKDIR /app

# install global dependencies
RUN npm install -g graphile-migrate

# add the dependencies
ADD ./package.json yarn.lock /app/
RUN yarn install --frozen-lockfile --prod

# NB: replace built node-cosmos run module
COPY ./docker/node-cosmos /usr/local/lib/node_modules/@subql/node-cosmos
COPY ./.gmrc /app/.gmrc
COPY --from=builder /app/subql/packages/common /usr/local/lib/node_modules/@subql/node-cosmos/node_modules/@subql/common

COPY --from=builder /app/dist /app/dist
COPY --from=builder /app/migrations /app/migrations
ADD ./proto /app/proto
ADD ./project.yaml schema.graphql /app/
ADD ./scripts/node-entrypoint.sh /entrypoint.sh
Expand Down
21 changes: 21 additions & 0 deletions scripts/node-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,26 @@ if [[ ! -z "${NETWORK_ENDPOINT}" ]]; then
yq -i '.network.endpoint = strenv(NETWORK_ENDPOINT)' project.yaml
fi

export DATABASE_URL="postgres://$DB_USER:$DB_PASS@$DB_HOST:$DB_PORT/$DB_DATABASE"
export SHADOW_DATABASE_URL="postgres://$DB_USER:$DB_PASS@$DB_HOST:$DB_PORT/$SHADOW_DATABASE"
export ROOT_DATABASE_URL="postgres://$DB_USER:$DB_PASS@$DB_HOST:$DB_PORT/$ROOT_DATABASE"

export PGPASSWORD=$DB_PASS
has_migrations=$(psql -h $DB_HOST \
-U $DB_USER \
-p $DB_PORT \
-c "set schema 'graphile_migrate';" -c "\dt" $DB_DATABASE |
grep "migrations" |
wc -l)
echo "has_migrations: $has_migrations"


if [[ "$has_migrations" == "0" ]]; then
graphile-migrate reset --erase
fi

# catch-up migrations
graphile-migrate migrate

# run the main node
exec /sbin/tini -- /usr/local/lib/node_modules/@subql/node-cosmos/bin/run "$@"