Skip to content

Commit d2c7574

Browse files
ejfineclaude
andcommitted
Copier update: support Clone Repository in Container Volume
Retarget the devcontainer workspace bind mount via WORKSPACE_MOUNT_TARGET so it works when VS Code clones the repo into a Docker volume. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent c48ec0c commit d2c7574

8 files changed

Lines changed: 26 additions & 4 deletions

File tree

‎.config/.copier-answers.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changes here will be overwritten by Copier
2-
_commit: v0.1.7
2+
_commit: v0.1.7-1-g74f764a1
33
_src_path: gh:LabAutomationAndScreening/copier-base-template.git
44
copier_answers_directory: .config
55
description: Copier template for creating Python libraries and executables

‎.devcontainer/devcontainer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@
6767
"initializeCommand": "sh .devcontainer/initialize-command.sh",
6868
"onCreateCommand": "sh .devcontainer/on-create-command.sh",
6969
"postStartCommand": "sh .devcontainer/post-start-command.sh"
70-
// Devcontainer context hash (do not manually edit this, it's managed by a pre-commit hook): 079f70d6 # spellchecker:disable-line
70+
// Devcontainer context hash (do not manually edit this, it's managed by a pre-commit hook): 6b104ca4 # spellchecker:disable-line
7171
}

‎.devcontainer/docker-compose.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
REPO_NAME: copier-python-package-template
1616
# You can run `devcontainer-info content-url` in codespaces to see what image base is
1717
volumes:
18-
- ..:/workspaces/copier-python-package-template:cached
18+
- ..:${WORKSPACE_MOUNT_TARGET:-/workspaces/copier-python-package-template}
1919
# Break out the venv folder as a separate docker volume for better performance on Windows hosts
2020
- python_venv:/workspaces/copier-python-package-template/.venv
2121
command: sleep infinity

‎.devcontainer/initialize-command.sh‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ if [ -n "$CODESPACES" ] && [ "$CODESPACES" = "true" ]; then
77
docker image prune --all --force
88
fi
99

10+
# "Clone Repository in Container Volume" runs this inside a bootstrap container that has the cloned volume mounted at /workspaces.
11+
# The compose bind mount of `..` then points at a path the Docker host doesn't have, so it gets retargeted onto /workspaces where VS Code's own volume mount replaces it.
12+
workspace_mount_type=$(docker inspect --format '{{range .Mounts}}{{if eq .Destination "/workspaces"}}{{.Type}}{{end}}{{end}}' "$HOSTNAME" 2>/dev/null || true)
13+
if [ "$workspace_mount_type" = "volume" ]; then
14+
echo "WORKSPACE_MOUNT_TARGET=/workspaces" > .devcontainer/.env
15+
else
16+
: > .devcontainer/.env
17+
fi
18+
1019
# ============== WARNING ==============================================================================
1120
# File is managed by copier template: gh:LabAutomationAndScreening/copier-base-template.git
1221
# See .config/.copier-managed-files.json for details.

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,7 @@ dist
126126
# Devcontainer
127127
# The devcontainer CLI writes this lock file to pin feature digests, but we are not using it yet
128128
.devcontainer/devcontainer-lock.json
129+
# Written by initialize-command.sh on every devcontainer start
130+
.devcontainer/.env
129131

130132
# Ignores specific to this repository

‎template/.devcontainer/docker-compose.yml.jinja‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
REPO_NAME: {% endraw %}{{ repo_name }}{% raw %}
99
# You can run `devcontainer-info content-url` in codespaces to see what image base is
1010
volumes:
11-
- ..:/workspaces/{% endraw %}{{ repo_name }}{% raw %}:cached
11+
- ..:${WORKSPACE_MOUNT_TARGET:-/workspaces/{% endraw %}{{ repo_name }}{% raw %}}
1212
# Break out the venv folder as a separate docker volume for better performance on Windows hosts
1313
- python_venv:/workspaces/{% endraw %}{{ repo_name }}{% raw %}/.venv
1414
command: sleep infinity

‎template/.devcontainer/initialize-command.sh‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ if [ -n "$CODESPACES" ] && [ "$CODESPACES" = "true" ]; then
77
docker image prune --all --force
88
fi
99

10+
# "Clone Repository in Container Volume" runs this inside a bootstrap container that has the cloned volume mounted at /workspaces.
11+
# The compose bind mount of `..` then points at a path the Docker host doesn't have, so it gets retargeted onto /workspaces where VS Code's own volume mount replaces it.
12+
workspace_mount_type=$(docker inspect --format '{{range .Mounts}}{{if eq .Destination "/workspaces"}}{{.Type}}{{end}}{{end}}' "$HOSTNAME" 2>/dev/null || true)
13+
if [ "$workspace_mount_type" = "volume" ]; then
14+
echo "WORKSPACE_MOUNT_TARGET=/workspaces" > .devcontainer/.env
15+
else
16+
: > .devcontainer/.env
17+
fi
18+
1019
# ============== WARNING ==============================================================================
1120
# File is managed by copier template: gh:LabAutomationAndScreening/copier-base-template.git
1221
# See .config/.copier-managed-files.json for details.

‎template/.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,7 @@ dist
126126
# Devcontainer
127127
# The devcontainer CLI writes this lock file to pin feature digests, but we are not using it yet
128128
.devcontainer/devcontainer-lock.json
129+
# Written by initialize-command.sh on every devcontainer start
130+
.devcontainer/.env
129131

130132
# Ignores specific to this repository

0 commit comments

Comments
 (0)