Skip to content

Commit 41e61d8

Browse files
authored
Merge pull request #112 from dockersamples/update-configurator-minify-and-setup-support
Add environment bootstrap/validation support
2 parents a0e6701 + 637bb0d commit 41e61d8

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

components/configurator/Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
FROM node:lts
1+
FROM debian:stable-slim
2+
3+
RUN apt update && \
4+
apt install -y curl jq openssl git && \
5+
apt clean && rm -rf /var/lib/apt/lists/*
6+
27
WORKDIR /usr/local/app
38
COPY ./setup.sh ./
49
CMD ["./setup.sh"]

components/configurator/setup.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ setup_project_directory() {
1313
# Setup project directory
1414
if [ "$DEV_MODE" = "true" ]; then
1515
echo "📁 Skipping clone because DEV_MODE is activated (project source will be directly mounted)"
16+
run_setup_script
1617
return
1718
else
1819
if [ -z "$PROJECT_CLONE_URL" ]; then
@@ -21,6 +22,7 @@ setup_project_directory() {
2122
fi
2223

2324
stage_git_repo
25+
run_setup_script
2426
fi
2527

2628
echo "📁 Copying staged files into /project"
@@ -46,7 +48,9 @@ stage_git_repo() {
4648
echo "🔄 Cloning project repository from $PROJECT_CLONE_URL"
4749

4850
git clone $PROJECT_CLONE_URL /staging
51+
}
4952

53+
run_setup_script() {
5054
if [ -n "$SETUP_SCRIPT" ]; then
5155
if [ -f "$SETUP_SCRIPT" ]; then
5256
bash "$SETUP_SCRIPT"

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)