diff --git a/README.md b/README.md index 244603b..9a05ce4 100644 --- a/README.md +++ b/README.md @@ -27,45 +27,75 @@ In order to mount a docker volume, a `.solrc` configuration file needs to be cre The following command will create it. ```sh -solana-test-validator-docker init +solana-docker-shell init ``` -## Start solana-test-validator container +## Start container Start the container. The directory where this command is executed must be somewhere in the project directory containing `.solrc` file ```sh -solana-test-validator-docker start +solana-docker-shell start ``` -## Stop solana-test-validator container +## Stop container ```sh -solana-test-validator-docker stop +solana-docker-shell stop ``` +## Volumes -## Execute a command inside solana-test-validator container +When starting the container, three volumes are mounted: + +- solana-docker:/opt + Every tools needed are installed in `/opt` and mounted to named volume `solana-docker`. + This volume makes rust/cargo installations and builds caches persistent. + +- solana-docker-cache:/home/node/.cache + Some solana caches are stored in user home directory `/home/node/.cache` and mounted to named volume `solana-docker-cache`. + This volume makes solana caches persistent. + +- ${.solrc_directory}:/working_dir + When running `solana-docker-shell init`, a configuration file `.solrc` is created. The directory containing this file is mounted to `/working_dir`. + +## How to execute a command inside solana-test-validator container ```sh -solana-test-validator-docker exec "anchor --version" -solana-test-validator-docker exec "anchor build" -solana-test-validator-docker exec "cargo --version" -solana-test-validator-docker exec "yarn --version" -solana-test-validator-docker exec "solana --version" -solana-test-validator-docker exec "solana balance" -solana-test-validator-docker exec "solana airdrop 2" +solana-docker-shell exec "solana-test-validator --ledger /opt/.config/solana/.ledger -r --bind-address 0.0.0.0 --rpc-port 8899" +solana-docker-shell exec "anchor --version" +solana-docker-shell exec "anchor build" +solana-docker-shell exec "cargo --version" +solana-docker-shell exec "yarn --version" +solana-docker-shell exec "solana --version" +solana-docker-shell exec "solana balance" +solana-docker-shell exec "solana airdrop 2" ... ``` But simplier, you can also use directly these commands: ```sh +# Launch solana-test-validator. Any options of classic command solana-test-validator are supported... +solana-test-validator-docker --ledger /opt/.config/solana/.ledger -r --bind-address 0.0.0.0 --rpc-port 8899 + +# Use anchor anchor-docker --version anchor-docker build +... + +# or cargo cargo-docker --version +cargo-docker build +... + +# or yarn yarn-docker --version +yarn-docker install +... + +# or solana solana-docker --version solana-docker balance solana-docker airdrop 2 diff --git a/bin/anchor-docker.sh b/bin/anchor-docker.sh index a6073ab..5e78054 100755 --- a/bin/anchor-docker.sh +++ b/bin/anchor-docker.sh @@ -4,7 +4,7 @@ var shell = require('shelljs'); -if (shell.exec(`solana-test-validator-docker exec "anchor ${process.argv.slice(2).join(' ')}"`).code !== 0) { +if (shell.exec(`solana-docker-shell exec "anchor ${process.argv.slice(2).join(' ')}"`).code !== 0) { shell.echo('Error: anchor command failed'); shell.exit(1); } \ No newline at end of file diff --git a/bin/cargo-docker.sh b/bin/cargo-docker.sh index ac60e3c..d277ab1 100755 --- a/bin/cargo-docker.sh +++ b/bin/cargo-docker.sh @@ -4,7 +4,7 @@ var shell = require('shelljs'); -if (shell.exec(`solana-test-validator-docker exec "cargo ${process.argv.slice(2).join(' ')}"`).code !== 0) { +if (shell.exec(`solana-docker-shell exec "cargo ${process.argv.slice(2).join(' ')}"`).code !== 0) { shell.echo('Error: cargo command failed'); shell.exit(1); } \ No newline at end of file diff --git a/bin/solana-test-validator-docker.js b/bin/solana-docker-shell.js similarity index 100% rename from bin/solana-test-validator-docker.js rename to bin/solana-docker-shell.js diff --git a/bin/solana-docker.sh b/bin/solana-docker.sh index 4c992c8..d4000c9 100755 --- a/bin/solana-docker.sh +++ b/bin/solana-docker.sh @@ -4,7 +4,7 @@ var shell = require('shelljs'); -if (shell.exec(`solana-test-validator-docker exec "solana ${process.argv.slice(2).join(' ')}"`).code !== 0) { +if (shell.exec(`solana-docker-shell exec "solana ${process.argv.slice(2).join(' ')}"`).code !== 0) { shell.echo('Error: solana command failed'); shell.exit(1); } \ No newline at end of file diff --git a/bin/solana-test-validator-docker.sh b/bin/solana-test-validator-docker.sh new file mode 100755 index 0000000..5665c79 --- /dev/null +++ b/bin/solana-test-validator-docker.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env node + +'use strict'; + +var shell = require('shelljs'); + +if (shell.exec(`solana-docker-shell exec "solana-test-validator --ledger /opt/.config/solana/.ledger -r --bind-address 0.0.0.0 --rpc-port 8899"`).code !== 0) { + shell.echo('Error: solana-test-validator command failed'); + shell.exit(1); +} \ No newline at end of file diff --git a/bin/yarn-docker.sh b/bin/yarn-docker.sh index 3a5f0bb..d01c3cf 100755 --- a/bin/yarn-docker.sh +++ b/bin/yarn-docker.sh @@ -4,7 +4,7 @@ console.log("AAA") var shell = require('shelljsxxx'); -if (shell.exec(`solana-test-validator-docker exec "yarn ${process.argv.slice(2).join(' ')}"`).code !== 0) { +if (shell.exec(`solana-docker-shell exec "yarn ${process.argv.slice(2).join(' ')}"`).code !== 0) { shell.echo('Error: yarn command failed'); shell.exit(1); } \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index 59fb267..e0b0191 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -39,11 +39,10 @@ ENV PATH=$SOLANA_HOME/bin:$PATH # Prepare working directory WORKDIR /working_dir +# Disable strict mode on corepack +ENV COREPACK_ENABLE_STRICT=0 + # Setup configuration RUN solana config set -ud RUN solana-keygen new --no-bip39-passphrase -s -o /opt/.config/solana/id.json &&\ solana config set --url localhost --keypair /opt/.config/solana/id.json - -# Launch solana-test-validator - -ENTRYPOINT solana-test-validator --ledger /opt/.config/solana/.ledger -r --bind-address 0.0.0.0 --rpc-port 8899 && sh diff --git a/package.json b/package.json index 0658503..5125c6e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "solana-test-validator-docker", - "version": "1.0.12", + "version": "1.0.14", "description": "Solana docker CLI to facilitate usages of solana-test-validator, cargo and anchor", "keywords": [ "solana", @@ -22,6 +22,7 @@ "anchor-docker": "./bin/anchor-docker.sh", "cargo-docker": "./bin/cargo-docker.sh", "solana-docker": "./bin/solana-docker.sh", + "solana-docker-shell": "./bin/solana-docker-shell.js", "solana-test-validator-docker": "./bin/solana-test-validator-docker.js", "yarn-docker": "./bin/yarn-docker.sh" }, diff --git a/src/DockerShell.ts b/src/DockerShell.ts index 1cd63c9..e84b7ba 100644 --- a/src/DockerShell.ts +++ b/src/DockerShell.ts @@ -52,7 +52,7 @@ export class DockerShell { await this.createVolume('solana-docker'); await this.createVolume('solana-docker-cache'); const uid = this.config.uid || `$(id -u \${USER})`; - const launchCommand = `docker run ${detached ? '-d' : `${process.stdout.isTTY ? '-ti' : '-t'}`} --rm --name "${this.config.containerName}" ` + + const launchCommand = `docker run -d ${process.stdout.isTTY ? '-ti' : '-t'} --rm --name "${this.config.containerName}" ` + `--net=host ` + `-e TZ=${Intl.DateTimeFormat().resolvedOptions().timeZone} ` + `-u ${uid} ` + diff --git a/yarn.lock b/yarn.lock index 291dd92..be73bec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2602,6 +2602,7 @@ __metadata: anchor-docker: ./bin/anchor-docker.sh cargo-docker: ./bin/cargo-docker.sh solana-docker: ./bin/solana-docker.sh + solana-docker-shell: ./bin/solana-docker-shell.js solana-test-validator-docker: ./bin/solana-test-validator-docker.js yarn-docker: ./bin/yarn-docker.sh languageName: unknown