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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

abukosek
Copy link
Contributor

@abukosek abukosek commented Nov 21, 2024

This PR:

  • Adds the --no-explorer flag, which disables starting the explorer and indexer.
  • Adds the --no-gateway flag, which disables starting the gateway.
  • If the gateway is disabled, the explorer and indexer are as well.
  • Reduces the size of the sapphire-localnet Docker image from 985MB to 932MB.
  • Reduces the number of layers in the sapphire-localnet Docker image.
  • Makes it easier to build components from unreleased branches (you no longer have to uncomment whole blocks of shell scripts, just a single line).
  • Moves all the version variables to the top, so you don't have to dig through all the crap in the Dockerfile just to bump a version.
  • Bumps CLI version to 0.10.3 and Nexus version to 0.4.2.

Closes #640.

@abukosek abukosek force-pushed the andrej/feature/no-explorer branch 2 times, most recently from 7a30d81 to 3ec05bd Compare November 21, 2024 11:41
Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.01%. Comparing base (b39df6c) to head (3ec05bd).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #653   +/-   ##
=======================================
  Coverage   59.01%   59.01%           
=======================================
  Files          40       40           
  Lines        4384     4384           
=======================================
  Hits         2587     2587           
  Misses       1574     1574           
  Partials      223      223           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@abukosek abukosek marked this pull request as ready for review November 21, 2024 11:54
@abukosek abukosek requested review from matevz and removed request for kostko and ptrus November 21, 2024 11:54
Copy link
Member

@matevz matevz left a comment

Choose a reason for hiding this comment

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

First pass, I'll test it tomorrow.


# Create symlinks for convenience and a dir to put all your rofls into,
# also print version info.
RUN ln -s ${OASIS_NODE_BINARY} ${OASIS_CLI_BINARY} /usr/local/bin \
Copy link
Member

Choose a reason for hiding this comment

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

Maybe also link the web3 gateway there for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that's useful, since the gateway is started at container startup if enabled and the user won't ever need to call it manually, whereas the CLI and node have useful commands. This is probably why the original author of these links only linked the node and CLI :)

Copy link
Member

@ptrus ptrus left a comment

Choose a reason for hiding this comment

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

A couple of minor suggestions. The updates to sapphire-localnet/Dockerfile are great, much clearer what versions of components are used.

@@ -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.

@@ -148,6 +150,11 @@ while [[ $# -gt 0 ]]; do
shift
shift
;;
--no-explorer)
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 also add a flag for disabling gateway?

Copy link
Member

@matevz matevz Nov 22, 2024

Choose a reason for hiding this comment

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

I would simply disable both the explorer and indexer, if --no-explorer is passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would simply disable both the explorer and indexer, if --no-explorer is passed.

That is already what happens, Peter suggested adding a similar option for the gateway :)

su -c "createdb -h 127.0.0.1 -p 5432 -U postgres nexus" postgres
# Once everything is initialized and setup, start Nexus and Explorer if enabled.
if [[ "${OASIS_DOCKER_START_EXPLORER}" == "yes" ]]; then
if [ ! -z "${OASIS_NEXUS_BINARY:-}" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove this check for the binary now and assume it's set if explorer is enabled? (like we do for gateway).

\
&& cd / \
&& if [ "x${OASIS_CORE_BRANCH}" != "x" ]; then \
git clone https://github.com/oasisprotocol/oasis-core.git --branch ${OASIS_CORE_BRANCH} --depth 1 \
Copy link
Member

Choose a reason for hiding this comment

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

Could we use a pattern that allows specifying either branch name or commit ref, and works in both cases?

I believe the clone->fetch->checkout as it is done for Explorer repository works with both. Maybe there's a more concise alternative, but it would be great if we would allow either branch name or specific commit refs to be specified for any component.

# ARG EXPLORER_REPO=https://github.com/oasisprotocol/explorer.git
# ARG EXPLORER_VERSION=v1.13.0
#ARG NEXUS_BRANCH=main

# TODO: Update to a released version once a version with localnet explorer support is available (https://github.com/oasisprotocol/explorer/issues/1597).
ARG EXPLORER_REPO=https://github.com/oasisprotocol/explorer.git
Copy link
Member

Choose a reason for hiding this comment

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

Feel free to remove the variable for the repository. I used it because my (very hacky) fork was used before explorer got some real support for localnet in oasisprotocol/explorer#1597 , but then forgot to remove it 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, ok :D

Copy link
Member

@matevz matevz left a comment

Choose a reason for hiding this comment

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

While you're at it, can you also move the explorer port 80 to 8548 (see the last bullet #640) and the docs accordingly.

@@ -148,6 +150,11 @@ while [[ $# -gt 0 ]]; do
shift
shift
;;
--no-explorer)
Copy link
Member

@matevz matevz Nov 22, 2024

Choose a reason for hiding this comment

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

I would simply disable both the explorer and indexer, if --no-explorer is passed.

@@ -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

@abukosek
Copy link
Contributor Author

While you're at it, can you also move the explorer port 80 to 8548 (see the last bullet #640) and the docs accordingly.

The port move seems to have already been done in a941da4

@abukosek
Copy link
Contributor Author

Ready for re-review :)

In a future PR, we can replace nodejs with nginx and save about 200MB+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sapphire-localnet: Add --no-explorer flag to disable Nexus and Explorer
3 participants