Skip to content

Commit e1346e8

Browse files
committed
Website/node-management: move example outputs to files and verify in CI
Move build-info example output and management script examples into separate files that are imported by the documentation. Add CI verification to ensure scripts work correctly and output matches documented examples. Changes: - Move build-info example output to build-info-example.txt - Create check-build-info-format.sh to verify output format - Combine backup scripts into backup-configuration.sh - Create manage-file-permissions.sh (combined from 3 separate scripts) - Create check-system-resources.sh - Create .env file creation scripts (empty, custom, archive variants) - Add test-management-scripts job to CI workflow - Add gh act run command comment to workflow - Update documentation to use CodeBlock imports for all scripts All scripts are tested in CI on ubuntu-22.04, ubuntu-24.04, and macos-latest to ensure they execute correctly.
1 parent febe155 commit e1346e8

16 files changed

+224
-60
lines changed

.github/workflows/test-docs-scripts-node-operators.yaml

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Test Documentation Scripts - Node Operators
22

33
# Test node-operators documentation scripts to ensure they work correctly
44
# These scripts demonstrate node management commands for users
5+
# Run locally: gh act -W .github/workflows/test-docs-scripts-node-operators.yaml
56
on:
67
push:
78
branches: [main, develop]
@@ -19,18 +20,82 @@ jobs:
1920
- name: Checkout repository
2021
uses: actions/checkout@v5
2122

22-
- name: Make scripts executable
23+
- name: Install Docker on macOS
24+
if: runner.os == 'macOS'
2325
run: |
24-
chmod +x website/docs/node-operators/scripts/*.sh
26+
brew install docker
27+
brew install colima
28+
colima start
2529
2630
- name: Test build-info-docker script
2731
run: |
2832
bash website/docs/node-operators/scripts/build-info-docker.sh
2933
3034
- name: Test build-info-docker-version script
3135
run: |
32-
bash website/docs/node-operators/scripts/build-info-docker-version.sh
36+
bash website/docs/node-operators/scripts/build-info-docker.sh
3337
3438
- name: Test verify-build-info-docker script
3539
run: |
3640
bash website/docs/node-operators/scripts/verify-build-info-docker.sh
41+
42+
- name: Check build-info output format matches example
43+
run: |
44+
bash website/docs/node-operators/scripts/check-build-info-format.sh
45+
46+
test-management-scripts:
47+
name: Test Management Scripts (${{ matrix.os }})
48+
runs-on: ${{ matrix.os }}
49+
strategy:
50+
matrix:
51+
os: [ubuntu-22.04, ubuntu-24.04, macos-latest]
52+
53+
steps:
54+
- name: Checkout repository
55+
uses: actions/checkout@v5
56+
57+
- name: Install timeout on macOS
58+
if: runner.os == 'macOS'
59+
run: |
60+
brew install coreutils
61+
sudo ln -s /opt/homebrew/bin/gtimeout /usr/local/bin/timeout || sudo ln -s /usr/local/bin/gtimeout /usr/local/bin/timeout
62+
63+
- name: Create test environment
64+
run: |
65+
mkdir -p mina-workdir/producer-key
66+
echo "test-key" > mina-workdir/producer-key/test.key
67+
mkdir -p ~/mina-backup
68+
69+
- name: Test backup-configuration script
70+
run: |
71+
bash website/docs/node-operators/scripts/backup-configuration.sh
72+
test -f ~/mina-backup/producer-key/test.key
73+
test -f mina-backup-$(date +%Y%m%d).tar.gz
74+
75+
- name: Test manage-file-permissions script
76+
run: |
77+
bash website/docs/node-operators/scripts/manage-file-permissions.sh
78+
79+
- name: Test check-system-resources script
80+
run: |
81+
timeout 5 bash website/docs/node-operators/scripts/check-system-resources.sh || true
82+
83+
- name: Test create-empty-env script
84+
run: |
85+
cd $(mktemp -d)
86+
bash $GITHUB_WORKSPACE/website/docs/node-operators/scripts/create-empty-env.sh
87+
test -f .env
88+
89+
- name: Test create-env-custom script
90+
run: |
91+
cd $(mktemp -d)
92+
bash $GITHUB_WORKSPACE/website/docs/node-operators/scripts/create-env-custom.sh
93+
test -f .env
94+
grep -q "MINA_RUST_TAG=latest" .env
95+
96+
- name: Test create-env-archive script
97+
run: |
98+
cd $(mktemp -d)
99+
bash $GITHUB_WORKSPACE/website/docs/node-operators/scripts/create-env-archive.sh
100+
test -f .env
101+
grep -q "POSTGRES_PASSWORD=mina" .env
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Version: 0341fff
2+
Build time: 2025-09-10T18:11:40.953050700Z
3+
Commit SHA: 0341fffedba4900371504ad4b30853674960a209
4+
Commit time: 2025-09-10T19:30:31.000000000+02:00
5+
Commit branch: release/v0.17.0
6+
Rustc channel: stable
7+
Rustc version: 1.84.1

website/docs/node-operators/node-management.mdx

Lines changed: 38 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ import BuildInfoNative from "!!raw-loader!./scripts/build-info-native.sh";
1111
import BuildInfoNativePath from "!!raw-loader!./scripts/build-info-native-path.sh";
1212
import VerifyBuildInfoDocker from "!!raw-loader!./scripts/verify-build-info-docker.sh";
1313
import VerifyBuildInfoNative from "!!raw-loader!./scripts/verify-build-info-native.sh";
14+
import BuildInfoExample from "!!raw-loader!./example-output/build-info-example.txt";
15+
import BackupConfiguration from "!!raw-loader!./scripts/backup-configuration.sh";
16+
import ManageFilePermissions from "!!raw-loader!./scripts/manage-file-permissions.sh";
17+
import CheckSystemResources from "!!raw-loader!./scripts/check-system-resources.sh";
18+
import CreateEmptyEnv from "!!raw-loader!./scripts/create-empty-env.sh";
19+
import CreateEnvCustom from "!!raw-loader!./scripts/create-env-custom.sh";
20+
import CreateEnvArchive from "!!raw-loader!./scripts/create-env-archive.sh";
1421

1522
# Node Management
1623

@@ -32,15 +39,9 @@ To check the build information of your Docker-based node:
3239

3340
Example output:
3441

35-
```
36-
Version: 0341fff
37-
Build time: 2025-09-10T18:11:40.953050700Z
38-
Commit SHA: 0341fffedba4900371504ad4b30853674960a209
39-
Commit time: 2025-09-10T19:30:31.000000000+02:00
40-
Commit branch: release/v0.17.0
41-
Rustc channel: stable
42-
Rustc version: 1.84.1
43-
```
42+
<CodeBlock language="text" title="example-output/build-info-example.txt">
43+
{BuildInfoExample}
44+
</CodeBlock>
4445

4546
For a specific version:
4647

@@ -168,36 +169,25 @@ docker compose up -d --force-recreate
168169

169170
Always backup your keys and configuration:
170171

171-
```bash
172-
# Backup producer key (if running block producer)
173-
cp -r mina-workdir/producer-key ~/mina-backup/
174-
175-
# Backup entire working directory
176-
tar -czf mina-backup-$(date +%Y%m%d).tar.gz mina-workdir/
177-
```
172+
<CodeBlock language="bash" title="scripts/backup-configuration.sh">
173+
{BackupConfiguration}
174+
</CodeBlock>
178175

179176
### Managing File Permissions
180177

181178
Docker containers often run as root, creating files owned by root on your host:
182179

183-
```bash
184-
# Check file ownership
185-
ls -la mina-workdir/
186-
187-
# Fix ownership for all files in mina-workdir
188-
sudo chown -R $(id -u):$(id -g) mina-workdir/
189-
190-
# Set appropriate permissions for the producer key
191-
chmod 600 mina-workdir/producer-key
192-
```
180+
<CodeBlock language="bash" title="scripts/manage-file-permissions.sh">
181+
{ManageFilePermissions}
182+
</CodeBlock>
193183

194184
<!-- prettier-ignore-start -->
195185

196186
:::tip Best Practice
197187

198-
Always fix file ownership after Docker operations to ensure your
199-
local user can properly access, backup, and manage the files. This is especially
200-
important for sensitive files like producer keys.
188+
Always fix file ownership after Docker operations to ensure your local user can
189+
properly access, backup, and manage the files. This is especially important for
190+
sensitive files like producer keys.
201191

202192
:::
203193

@@ -224,32 +214,23 @@ environment variables:
224214

225215
**For regular node and block producer:**
226216

227-
```bash
228-
# Quick fix: Create an empty .env file (has defaults)
229-
touch .env
230-
231-
# Or create with custom settings
232-
cat > .env << EOF
233-
MINA_RUST_TAG=latest
234-
MINA_FRONTEND_TAG=latest
235-
MINA_LIBP2P_PORT=8302
236-
MINA_LIBP2P_EXTERNAL_IP=
237-
MINA_PRIVKEY_PASS=
238-
COINBASE_RECEIVER=
239-
EOF
240-
```
217+
Quick fix: Create an empty .env file (has defaults)
218+
219+
<CodeBlock language="bash" title="scripts/create-empty-env.sh">
220+
{CreateEmptyEnv}
221+
</CodeBlock>
222+
223+
Or create with custom settings:
224+
225+
<CodeBlock language="bash" title="scripts/create-env-custom.sh">
226+
{CreateEnvCustom}
227+
</CodeBlock>
241228

242229
**For archive node (required):**
243230

244-
```bash
245-
# Archive node requires specific database settings
246-
cat > .env << EOF
247-
POSTGRES_PASSWORD=mina
248-
PG_PORT=5432
249-
PG_DB=archive
250-
MINA_RUST_TAG=latest
251-
EOF
252-
```
231+
<CodeBlock language="bash" title="scripts/create-env-archive.sh">
232+
{CreateEnvArchive}
233+
</CodeBlock>
253234

254235
Regular node docker-compose files have default values, but the archive node
255236
docker-compose file requires the `.env` file with PostgreSQL configuration.
@@ -266,11 +247,11 @@ docker-compose file requires the `.env` file with PostgreSQL configuration.
266247
### Performance Issues
267248

268249
1. Check system resources:
269-
```bash
270-
free -h
271-
df -h
272-
docker stats
273-
```
250+
251+
<CodeBlock language="bash" title="scripts/check-system-resources.sh">
252+
{CheckSystemResources}
253+
</CodeBlock>
254+
274255
2. Review node logs for warnings
275256
3. Consider adjusting Docker resource limits
276257

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
# Backup producer key (if running block producer)
3+
cp -r mina-workdir/producer-key ~/mina-backup/
4+
5+
# Backup entire working directory
6+
tar -czf "mina-backup-$(date +%Y%m%d).tar.gz" mina-workdir/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#!/bin/bash
12
docker run --rm o1labs/mina-rust:v0.17.0 build-info
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#!/bin/bash
12
docker run --rm o1labs/mina-rust:latest build-info
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#!/bin/bash
12
./target/release/mina build-info
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#!/bin/bash
12
mina build-info
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
# Verify that build-info output format matches the documented example
3+
4+
set -euo pipefail
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
EXAMPLE_FILE="$SCRIPT_DIR/../example-output/build-info-example.txt"
8+
9+
# Get actual build-info output
10+
echo "Getting build-info output..."
11+
ACTUAL_OUTPUT=$(docker run --rm o1labs/mina-rust:latest build-info)
12+
13+
# Extract field names from example file (everything before the colon)
14+
echo "Checking that all expected fields are present..."
15+
EXPECTED_FIELDS=(
16+
"Version"
17+
"Build time"
18+
"Commit SHA"
19+
"Commit time"
20+
"Commit branch"
21+
"Rustc channel"
22+
"Rustc version"
23+
)
24+
25+
# Check that each expected field exists in the actual output
26+
MISSING_FIELDS=()
27+
for field in "${EXPECTED_FIELDS[@]}"; do
28+
if ! echo "$ACTUAL_OUTPUT" | grep -q "^${field}:"; then
29+
MISSING_FIELDS+=("$field")
30+
fi
31+
done
32+
33+
if [ ${#MISSING_FIELDS[@]} -gt 0 ]; then
34+
echo "ERROR: Missing fields in build-info output:"
35+
printf ' - %s\n' "${MISSING_FIELDS[@]}"
36+
echo ""
37+
echo "Expected fields:"
38+
printf ' - %s\n' "${EXPECTED_FIELDS[@]}"
39+
echo ""
40+
echo "Actual output:"
41+
echo "$ACTUAL_OUTPUT"
42+
exit 1
43+
fi
44+
45+
# Verify field order matches the example
46+
echo "Checking that field order matches the example..."
47+
EXAMPLE_ORDER=$(grep -o '^[^:]*:' "$EXAMPLE_FILE")
48+
ACTUAL_ORDER=$(echo "$ACTUAL_OUTPUT" | grep -o '^[^:]*:')
49+
50+
if [ "$EXAMPLE_ORDER" != "$ACTUAL_ORDER" ]; then
51+
echo "ERROR: Field order doesn't match the example"
52+
echo ""
53+
echo "Expected order:"
54+
echo "$EXAMPLE_ORDER"
55+
echo ""
56+
echo "Actual order:"
57+
echo "$ACTUAL_ORDER"
58+
exit 1
59+
fi
60+
61+
echo "✓ Build-info format matches the documented example"
62+
echo ""
63+
echo "Actual output:"
64+
echo "$ACTUAL_OUTPUT"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
if command -v free &> /dev/null; then
3+
free -h
4+
else
5+
vm_stat | perl -ne '/page size of (\d+)/ and $size=$1; /Pages\s+([^:]+)[^\d]+(\d+)/ and printf("%-16s % 16.2f Mi\n", "$1:", $2 * $size / 1048576);'
6+
fi
7+
df -h
8+
docker stats

0 commit comments

Comments
 (0)