Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(localnet): Add --no-explorer flag and reduce size #653

Merged
merged 1 commit into from
Nov 29, 2024
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/ci-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
SAPPHIRE_PARATIME: ${{ github.workspace }}/oasis_core/sapphire-paratime
OASIS_NODE_DATADIR: /tmp/oasis-sapphire-benchmarks
OASIS_WEB3_GATEWAY: ${{ github.workspace }}/oasis-web3-gateway
OASIS_DOCKER_START_EXPLORER: no
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to describe the usage in the Sapphire Localnet chapter: https://github.com/oasisprotocol/docs/blob/main/docs/dapp/tools/localnet.mdx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR opened in docs: oasisprotocol/docs#1032

timeout-minutes: 30
steps:
- name: Checkout code
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
GATEWAY__CHAIN_ID: 42260
EMERALD_PARATIME: ${{ github.workspace }}/oasis_core/emerald-paratime
OASIS_NODE_DATADIR: /tmp/eth-runtime-test
OASIS_DOCKER_START_EXPLORER: no
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -116,6 +117,7 @@ jobs:
KEYMANAGER_ARTIFACT_URL: https://buildkite.com/organizations/oasisprotocol/pipelines/oasis-core-ci/builds/14038/jobs/0191c151-b95b-402c-9854-4e58effc95ab/artifacts/0191c156-f366-45b2-819b-e1eb9fd9ba16 # Find this at https://buildkite.com/oasisprotocol/oasis-core-ci/builds?branch=stable%2F<...> under "Build runtimes": simple-keymanager.mocksgx.
KEYMANAGER_BINARY: ${{ github.workspace }}/oasis_core/simple-keymanager
OASIS_NODE_DATADIR: /tmp/eth-runtime-test
OASIS_DOCKER_START_EXPLORER: no
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
4 changes: 4 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ be funded 10,000 TEST. Flags `-amount`, `-to`, `-n` can be added to specify an
initial ROSE deposit, existing mnemonic and the number of addresses to derive
and fund respectively.

By passing `--no-explorer`, the Explorer frontend and Nexus indexer won't be
started (useful if you want to reduce the container startup time a bit,
e.g. for CI tests).

WARNING: The image is running in *ephemeral mode*. A new chain state will be
initialized each time you start the container!

Expand Down
File renamed without changes.
30 changes: 23 additions & 7 deletions docker/common/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

rm -f /CONTAINER_READY

export OASIS_DOCKER_START_EXPLORER=${OASIS_DOCKER_START_EXPLORER:-yes}

export OASIS_DOCKER_NO_GATEWAY=${OASIS_DOCKER_NO_GATEWAY:-no}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to OASIS_DOCKER_START_GATEWAY, for consistency with explorer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I just remembered that enabling nexus/explorer while gateway is disabled wont work, so let's maybe catch that and error out (or alternative, if gateway is disabled also automatically disable nexus/explorer).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I'll fix that :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to OASIS_DOCKER_START_GATEWAY, for consistency with explorer?

I've kept this as-is for compatibility, but we can do a separate PR to change this in the future.

Copy link
Member

@ptrus ptrus Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait sorry, I was really stupid or something 😭 Nexus and Explorer will work just ok without web3-gateway?

Can you please just revert this part where gateway automatically disables nexus/explrer, and then also at the end move

  if [[ "${OASIS_DOCKER_START_EXPLORER}" == "yes" ]]; then
    notice "Nexus API listening on ${CYAN}http://localhost:8547${OFF}.\n"
    notice "Localnet Explorer available at ${CYAN}http://localhost:${EXPLORER_PORT}${OFF}.\n"
  fi

out of the nested IF.

This case where you don't have gateway and do have nexus is probably not really useful since there likely wont be any Sapphire transactions, but one might still use it if it's interested only in the cosnseus part or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, fixed! :)


export OASIS_NODE_LOG_LEVEL=${OASIS_NODE_LOG_LEVEL:-warn}
Expand Down Expand Up @@ -148,6 +150,16 @@ while [[ $# -gt 0 ]]; do
shift
shift
;;
--no-explorer)
# Don't start explorer and indexer.
OASIS_DOCKER_START_EXPLORER="no"
shift
;;
--no-gateway)
# Don't start web3 gateway.
OASIS_DOCKER_NO_GATEWAY="yes"
shift
;;
*)
echo "Unknown argument: $1"
exit 1;
Expand Down Expand Up @@ -351,8 +363,8 @@ else
sleep 10
fi

# Once everything is initialized and setup, start Nexus and Explorer.
if [ ! -z "${OASIS_NEXUS_BINARY:-}" ]; then
# Once everything is initialized and setup, start Nexus and Explorer if enabled.
if [[ "${OASIS_DOCKER_START_EXPLORER}" == "yes" ]]; then
Copy link
Member

@ptrus ptrus Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also please update the notices at the end of initialization so that Web3 Gateway, Explorer and Nexus addresses are not displayed when they are not enabled? We currently always display the addresses.

Other than that, the rest looks good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Fixed :)

notice "Creating database 'nexus'\n"
su -c "createdb -h 127.0.0.1 -p 5432 -U postgres nexus" postgres

Expand All @@ -369,9 +381,7 @@ if [ ! -z "${OASIS_NEXUS_BINARY:-}" ]; then
# Wait for Oasis Nexus to start.
while ! curl -s http://localhost:8547/ 2>1 &>/dev/null; do echo -n .; sleep 1; done
echo
fi

if [ ! -z "${OASIS_EXPLORER_DIR:-}" ]; then
notice "Waiting for Explorer to start"
cd ${OASIS_EXPLORER_DIR}
serve -s ${OASIS_EXPLORER_DIR} -l ${EXPLORER_PORT} > /var/log/explorer.log 2>&1 &
Expand Down Expand Up @@ -441,9 +451,15 @@ T_END="$(date +%s)"
echo
printf "${YELLOW}WARNING: The chain is running in ephemeral mode. State will be lost after restart!${OFF}\n\n"
notice "GRPC listening on ${CYAN}http://localhost:8544${OFF}.\n"
notice "Web3 RPC listening on ${CYAN}http://localhost:8545${OFF} and ${CYAN}ws://localhost:8546${OFF}. Chain ID: ${GATEWAY__CHAIN_ID}.\n"
notice "Nexus API listening on ${CYAN}http://localhost:8547${OFF}.\n"
notice "Localnet Explorer available at ${CYAN}http://localhost:${EXPLORER_PORT}${OFF}.\n"

if [[ "${OASIS_DOCKER_NO_GATEWAY}" == "no" ]]; then
notice "Web3 RPC listening on ${CYAN}http://localhost:8545${OFF} and ${CYAN}ws://localhost:8546${OFF}. Chain ID: ${GATEWAY__CHAIN_ID}.\n"
fi
if [[ "${OASIS_DOCKER_START_EXPLORER}" == "yes" ]]; then
notice "Nexus API listening on ${CYAN}http://localhost:8547${OFF}.\n"
notice "Localnet Explorer available at ${CYAN}http://localhost:${EXPLORER_PORT}${OFF}.\n"
fi

notice "Container start-up took ${CYAN}$((T_END-T_START))${OFF} seconds, node log level is set to ${CYAN}${OASIS_NODE_LOG_LEVEL}${OFF}.\n"

touch /CONTAINER_READY
Expand Down
2 changes: 1 addition & 1 deletion docker/emerald-localnet/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RUN wget https://github.com/oasisprotocol/nexus/releases/download/v${NEXUS_VERSI
# TODO: update once some support for localnet is added: https://github.com/oasisprotocol/explorer/issues/1597
ARG EXPLORER_REPO=https://github.com/oasisprotocol/explorer.git
ARG EXPLORER_VERSION=bcb125108db2f6439fcdd536f690b0edfd38aad7
COPY docker/common/explorer.env /nexus.env.production
COPY docker/common/nexus.env.production /nexus.env.production
RUN git clone ${EXPLORER_REPO} explorer --depth 1 \
&& cd explorer \
&& git fetch origin ${EXPLORER_VERSION} --depth 1 \
Expand Down
Loading