Skip to content

Commit 637bb0d

Browse files
committed
Add documentation on adding bootstrap/validation steps
1 parent 0158ed2 commit 637bb0d

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

docs/configuration.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,65 @@ services:
120120
- "8080:8080"
121121
```
122122

123+
124+
125+
### Adding bootstrap tasks
126+
127+
The Labspace configurator (which clones the repo) provides support to run bootstrap tasks to setup the project workspace, perform environment checks, etc.
128+
129+
To specify a setup script, set the `SETUP_SCRIPT` environment variable with a value to the full path of the script to execute.
130+
131+
> [!IMPORTANT]
132+
> If you are defining a script using Compose `configs`, you will need to escape all environment variables as Compose will replace values at config file creation. See the example below for an example.
133+
134+
The following example adds a setup script that will validate the Labspace is running in a Docker Offload environment with GPU access:
135+
136+
```yaml
137+
services:
138+
configurator:
139+
environment:
140+
PROJECT_CLONE_URL: https://github.com/dockersamples/labspace-fine-tuning
141+
SETUP_SCRIPT: /scripts/validate-environment.sh
142+
volumes:
143+
- /var/run/docker.sock:/var/run/docker.sock
144+
configs:
145+
- source: validation-script
146+
target: /scripts/validate-environment.sh
147+
configs:
148+
validation-script:
149+
content: |
150+
#!/bin/bash
151+
152+
set -e
153+
154+
# Get Docker info as JSON
155+
DOCKER_INFO=$(curl --unix-socket /var/run/docker.sock http://localhost/info)
156+
157+
# Check if running in Docker Offload environment
158+
echo "Checking Docker Offload environment..."
159+
OFFLOAD_LABEL=$(echo "$$DOCKER_INFO" | jq -r '.Labels[]? | select(startswith("cloud.docker.run.version="))')
160+
161+
if [ -z "$$OFFLOAD_LABEL" ]; then
162+
echo "Error: Not running in a Docker Offload environment."
163+
echo "Please enable Docker Offload and restart this Labspace"
164+
exit 1
165+
fi
166+
167+
echo "✓ Docker Offload environment detected"
168+
169+
# Check if GPU (nvidia runtime) is available
170+
echo "Checking GPU availability..."
171+
NVIDIA_RUNTIME=$(echo "$$DOCKER_INFO" | jq -r '.Runtimes.nvidia.path // empty')
172+
173+
if [ -z "$$NVIDIA_RUNTIME" ]; then
174+
echo "Error: GPU not available."
175+
echo "Docker Offload environment is not configured with GPUs. Please enable the GPU setting and try again."
176+
exit 1
177+
fi
178+
179+
echo "✓ GPU available: nvidia runtime found"
180+
181+
echo ""
182+
echo "All checks passed! Environment is ready."
183+
exit 0
184+
```

0 commit comments

Comments
 (0)