-
-
Notifications
You must be signed in to change notification settings - Fork 288
feat: implement stellar-quickstart-up runtime installer #9282
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
Open
ulissesferreira
wants to merge
7
commits into
main
Choose a base branch
from
add-stellar-quickstart-up-package-impl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,008
−30
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2d117ab
feat: implement stellar-quickstart-up runtime installer
ulissesferreira 676aff2
docs(stellar-quickstart-up): link changelog entry to implementation PR
ulissesferreira 319d33a
fix(stellar-quickstart-up): address review feedback after rebase onto…
ulissesferreira 805397e
docs(stellar-quickstart-up): expand README with wrapper and endpoint …
ulissesferreira 9314d29
fix(stellar-quickstart-up): keep package version at 0.0.0 for CI
ulissesferreira 8f37a91
chore: update monorepo README graph and format stellar-quickstart-up
ulissesferreira a7eb2f5
fix(stellar-quickstart-up): avoid TOCTOU when reading image cache met…
ulissesferreira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,130 @@ | ||
| # `@metamask/stellar-quickstart-up` | ||
|
|
||
| Stellar Quickstart runtime installer for MetaMask E2E tests | ||
| `stellar-quickstart-up` installs a pinned [Stellar Quickstart](https://github.com/stellar/quickstart) | ||
| Docker image for local development and CI. It follows the same runtime-only shape as | ||
| `@metamask/foundryup`: this package pulls the image into the local Docker daemon, | ||
| stores image metadata in the MetaMask cache, and exposes a `stellar-quickstart` | ||
| wrapper in `node_modules/.bin`; the consuming test harness owns container | ||
| lifecycle, readiness checks, and seeding. | ||
|
|
||
| ## Installation | ||
| This package requires Docker to be installed and available on `PATH`. It does not | ||
| start or seed a Stellar node itself. | ||
|
|
||
| `yarn add @metamask/stellar-quickstart-up` | ||
| ## Usage | ||
|
|
||
| or | ||
| Install the package in the consuming repo: | ||
|
|
||
| `npm install @metamask/stellar-quickstart-up` | ||
| ```bash | ||
| yarn add @metamask/stellar-quickstart-up | ||
| npm install @metamask/stellar-quickstart-up | ||
| ``` | ||
|
|
||
| ## Contributing | ||
| For Yarn v4 projects, it is usually simplest to add package scripts in the | ||
| consuming repo: | ||
|
|
||
| This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme). | ||
| ```json | ||
| { | ||
| "scripts": { | ||
| "stellar-quickstart-up": "node_modules/.bin/stellar-quickstart-up", | ||
| "stellar-quickstart": "node_modules/.bin/stellar-quickstart" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Pull the pinned Stellar Quickstart image and install the wrapper: | ||
|
|
||
| ```bash | ||
| yarn stellar-quickstart-up install | ||
| ``` | ||
|
|
||
| Run the installed Stellar Quickstart wrapper: | ||
|
|
||
| ```bash | ||
| node_modules/.bin/stellar-quickstart --local | ||
| ``` | ||
|
|
||
| For MetaMask Extension E2E tests, the Stellar seeder should spawn | ||
| `node_modules/.bin/stellar-quickstart`, pass the desired network mode such as | ||
| `--local`, poll Horizon or RPC readiness, and perform wallet/funding seeding | ||
| itself. | ||
|
|
||
| ## Installed Artifacts | ||
|
|
||
| `stellar-quickstart-up` installs: | ||
|
|
||
| - a digest-pinned `stellar/quickstart` Docker image in the local Docker daemon | ||
| - cached image metadata under the MetaMask cache | ||
| - a `node_modules/.bin/stellar-quickstart` wrapper that runs: | ||
|
|
||
| ```bash | ||
| docker run --rm -i -p 8000:8000 stellar/quickstart:latest "$@" | ||
| ``` | ||
|
|
||
| ## CLI | ||
|
|
||
| ```bash | ||
| stellar-quickstart-up [install] [options] | ||
| stellar-quickstart-up cache clean [options] | ||
| ``` | ||
|
|
||
| Options: | ||
|
|
||
| - `--bin-directory <path>`: directory for generated wrappers. Defaults to | ||
| `node_modules/.bin`. | ||
| - `--cache-directory <path>`: artifact cache directory. Defaults to | ||
| `.metamask/cache`. | ||
| - `--docker-binary <path>`: Docker CLI binary. Defaults to `docker` on `PATH`. | ||
| - `--image-reference <reference>` and `--image-digest <digest>`: override the | ||
| pinned Stellar Quickstart image. | ||
| - `--help`: show help text. | ||
|
|
||
| ## Default Image | ||
|
|
||
| The package currently pins `stellar/quickstart:latest` with digest | ||
| `sha256:8ddf3ed87a5c07eab5202b0fd95f06fb5db3f48cacd7e69fdc0e22925f181168`. | ||
|
|
||
| The installer verifies the digest against the image `RepoDigests` reported by | ||
| `docker image inspect` after `docker pull`. | ||
|
|
||
| The installed wrapper defaults to `docker run --rm -i -p 8000:8000` and forwards | ||
| extra arguments to the container entrypoint, for example `--local`, `--testnet`, | ||
| or `--pubnet`. | ||
|
|
||
| With the default port mapping, the Quickstart services are available at: | ||
|
|
||
| - Horizon: `http://localhost:8000/` | ||
| - RPC: `http://localhost:8000/rpc` | ||
| - Friendbot: `http://localhost:8000/friendbot` | ||
|
|
||
| ## Cache | ||
|
|
||
| The cache defaults to `.metamask/cache` in the current repo. `enableGlobalCache` | ||
| is read by parsing `.yarnrc.yml` as YAML; when it is `true`, the cache moves to | ||
| `~/.cache/metamask`, matching the `@metamask/foundryup` behavior. | ||
|
|
||
| Clean only this package's cache namespace: | ||
|
|
||
| ```bash | ||
| yarn stellar-quickstart-up cache clean | ||
| ``` | ||
|
|
||
| ## Package Config | ||
|
|
||
| The consuming repo can override the pinned image reference, digest, and wrapper | ||
| `docker run` arguments in its root `package.json`: | ||
|
|
||
| ```json | ||
| { | ||
| "stellarQuickstartUp": { | ||
| "image": { | ||
| "version": "latest", | ||
| "reference": "stellar/quickstart:latest", | ||
| "digest": "sha256:8ddf3ed87a5c07eab5202b0fd95f06fb5db3f48cacd7e69fdc0e22925f181168" | ||
| }, | ||
| "runArgs": ["run", "--rm", "-i", "-p", "8000:8000"] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Supported package config keys are `stellarQuickstartUp`, `stellarquickstartup`, | ||
| and `stellar-quickstart-up`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/stellar-quickstart-up/src/bin/stellar-quickstart-up.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/usr/bin/env node | ||
| /* eslint-disable no-restricted-globals */ | ||
| import { | ||
| cleanStellarQuickstartCache, | ||
| installStellarQuickstart, | ||
| parseStellarQuickstartInstallCliOptions, | ||
| readStellarQuickstartInstallOptionsFromPackageJson, | ||
| } from '../install'; | ||
|
|
||
| async function main(): Promise<void> { | ||
| const [command, ...args] = process.argv.slice(2); | ||
|
|
||
| if (command === '--help' || command === 'help') { | ||
| printHelp(); | ||
| return; | ||
| } | ||
|
|
||
| if (command === 'cache' && args[0] === 'clean') { | ||
| await cleanStellarQuickstartCache({ | ||
| ...readStellarQuickstartInstallOptionsFromPackageJson(), | ||
| ...parseStellarQuickstartInstallCliOptions(args.slice(1)), | ||
| }); | ||
| console.log('[stellar-quickstart-up] cache cleaned'); | ||
| return; | ||
| } | ||
|
|
||
| const installArgs = command === 'install' ? args : process.argv.slice(2); | ||
| const result = await installStellarQuickstart({ | ||
| ...readStellarQuickstartInstallOptionsFromPackageJson(), | ||
| ...parseStellarQuickstartInstallCliOptions(installArgs), | ||
| }); | ||
|
|
||
| console.log( | ||
| `[stellar-quickstart-up] Stellar Quickstart image ${ | ||
| result.cacheHit ? 'found in cache' : 'installed' | ||
| }`, | ||
| ); | ||
| console.log( | ||
| `[stellar-quickstart-up] stellar-quickstart installed at ${result.binaryPath}`, | ||
| ); | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| console.error(error); | ||
| process.exit(1); | ||
| }); | ||
|
|
||
| function printHelp(): void { | ||
| console.log(`Usage: stellar-quickstart-up [install] [options] | ||
| stellar-quickstart-up cache clean [options] | ||
|
|
||
| Commands: | ||
| install Pull the Stellar Quickstart image and install wrappers. Default command. | ||
| cache clean Remove cached stellar-quickstart-up artifacts. | ||
|
|
||
| Options: | ||
| --bin-directory <path> Directory for executable wrappers. | ||
| Defaults to node_modules/.bin. | ||
| --cache-directory <path> Cache directory. Defaults to .metamask/cache. | ||
| --docker-binary <path> Docker CLI binary. Defaults to docker. | ||
| --image-reference <reference> Docker image reference override. | ||
| --image-digest <digest> Expected Docker image digest. | ||
| --help Show this help text.`); | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,15 @@ | ||
| /** | ||
| * Example function that returns a greeting for the given name. | ||
| * | ||
| * @param name - The name to greet. | ||
| * @returns The greeting. | ||
| */ | ||
| export default function greeter(name: string): string { | ||
| return `Hello, ${name}!`; | ||
| } | ||
| export { | ||
| STELLAR_QUICKSTART_DEFAULT_IMAGE, | ||
| STELLAR_QUICKSTART_DEFAULT_RUN_ARGS, | ||
| cleanStellarQuickstartCache, | ||
| getStellarQuickstartCacheDirectory, | ||
| installStellarQuickstart, | ||
| parseStellarQuickstartInstallCliOptions, | ||
| readStellarQuickstartInstallOptionsFromPackageJson, | ||
| } from './install'; | ||
| export type { | ||
| StellarQuickstartImageConfig, | ||
| StellarQuickstartInstallDependencies, | ||
| StellarQuickstartInstallOptions, | ||
| StellarQuickstartInstallResult, | ||
| } from './install'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.