Skip to content

Commit

Permalink
Merge pull request #2 from tchambard/feat/docker/volumes
Browse files Browse the repository at this point in the history
Add volumes and prevent test-validator start
  • Loading branch information
tchambard authored Jun 3, 2024
2 parents ea1879e + 78f512f commit efb215a
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 23 deletions.
56 changes: 43 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/anchor-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion bin/cargo-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
File renamed without changes.
2 changes: 1 addition & 1 deletion bin/solana-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
10 changes: 10 additions & 0 deletions bin/solana-test-validator-docker.sh
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion bin/yarn-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
7 changes: 3 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/DockerShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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} ` +
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit efb215a

Please # to comment.