Skip to content

Commit dcb064d

Browse files
authored
Merge pull request #132 from dockersamples/add-local-mode-configurator
Add "local mode" to support locally defined content in a Labspace
2 parents ecb64fc + 44abf54 commit dcb064d

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

components/configurator/setup.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,27 @@ setup_project_directory() {
66
echo "📁 Setting up project directory"
77

88
clear_project_directory
9-
rm -rf /staging
10-
mkdir /staging
9+
clear_staging_directory
1110
cd /staging
1211

1312
# Setup project directory
1413
if [ "$DEV_MODE" = "true" ]; then
1514
echo "📁 Skipping clone because DEV_MODE is activated (project source will be directly mounted)"
1615
run_setup_script
1716
return
17+
elif [ "$LOCAL_MODE" = "true" ]; then
18+
echo "📁 Local mode enabled."
19+
if [ -z "$LOCAL_CONTENT_PATH" ]; then
20+
echo "Error: LOCAL_CONTENT_PATH environment variable is not set."
21+
exit 1
22+
fi
23+
24+
echo "📁 Using content in ${LOCAL_CONTENT_PATH} as source material"
25+
shopt -s dotglob
26+
cp -r "${LOCAL_CONTENT_PATH}/"* /staging
27+
shopt -u dotglob
28+
29+
run_setup_script
1830
else
1931
if [ -z "$PROJECT_CLONE_URL" ]; then
2032
echo "Error: PROJECT_CLONE_URL environment variable is not set."
@@ -60,6 +72,13 @@ run_setup_script() {
6072
fi
6173
}
6274

75+
clear_staging_directory() {
76+
if [ "$DEV_MODE" != "true" ]; then
77+
rm -rf /staging
78+
mkdir /staging
79+
fi
80+
}
81+
6382
clear_project_directory() {
6483
cd /project
6584

docs/configuration.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,29 @@ configs:
182182
echo ""
183183
echo "All checks passed! Environment is ready."
184184
exit 0
185-
```
185+
```
186+
187+
188+
### Using locally defined Labspace content
189+
190+
When a Labspace starts, it will, by default, clone the content from the content repo. However, there may be situations in which you want to skip this and use locally cloned content, such as running demos.
191+
192+
To do so, you need to:
193+
194+
1. Set the `LOCAL_MODE` environment variable for the `configurator` service to `true`
195+
2. Mount your content into the `configurator` service
196+
3. Specify the content location with the `LOCAL_CONTENT_PATH` environment variable in the `configurator` service
197+
198+
When the configurator runs, it will copy all files located at `LOCAL_CONTENT_PATH` into the volume used by the Labspace. Any defined setup scripts will still execute as configured. Since the content is copied, changes to files in the Labspace will change the copied files, making it easy to restart the Labspace from a known and valid state.
199+
200+
The following `compose.override.yaml` will mount the parent directory (since this is in the `.labspace` directory) into the configurator.
201+
202+
```yaml
203+
services:
204+
configurator:
205+
volumes:
206+
- ../:/custom-content
207+
environment:
208+
LOCAL_MODE: "true"
209+
LOCAL_CONTENT_PATH: /custom-content
210+
```

0 commit comments

Comments
 (0)