Skip to content

Commit 009efce

Browse files
authored
Merge pull request #7 from tablackburn/devcontainer-cleanup
refactor: Replace custom Dockerfile with feature-based devcontainer
2 parents 0d6fdda + 767302c commit 009efce

6 files changed

Lines changed: 65 additions & 87 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 0 additions & 58 deletions
This file was deleted.

.devcontainer/devcontainer.json

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
{
2-
"name": "{{ModuleName}} DevContainer",
3-
"build": {
4-
"dockerfile": "Dockerfile",
5-
"context": ".."
2+
"name": "PowerShell Claude Code",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "devcontainer",
5+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
6+
"initializeCommand": "pwsh -NoProfile -File .devcontainer/setup-host.ps1",
7+
"features": {
8+
"ghcr.io/devcontainers/features/common-utils:2": {
9+
"installZsh": false,
10+
"installOhMyZsh": false,
11+
"username": "vscode",
12+
"userUid": "automatic",
13+
"userGid": "automatic"
14+
},
15+
"ghcr.io/devcontainers/features/github-cli:1": {},
16+
"ghcr.io/anthropics/devcontainer-features/claude-code:1": {}
617
},
718
"remoteUser": "vscode",
8-
"containerEnv": {
9-
"DEVCONTAINER": "true"
10-
},
11-
"mounts": [
12-
"source={{ModuleNameLower}}-pwsh-modules,target=/home/vscode/.local/share/powershell/Modules,type=volume",
13-
"source={{ModuleNameLower}}-pwsh-history,target=/home/vscode/.local/share/powershell/PSReadLine,type=volume"
14-
],
15-
"postCreateCommand": "pwsh ./build.ps1 -Task Init -Bootstrap",
19+
"postCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder} && pwsh ./build.ps1 -Task Init -Bootstrap",
1620
"customizations": {
1721
"vscode": {
1822
"extensions": [
19-
"ms-vscode.powershell",
20-
"anthropic.claude-code"
23+
"ms-vscode.powershell"
2124
],
2225
"settings": {
23-
"powershell.codeFormatting.preset": "OTBS",
24-
"powershell.scriptAnalysis.settingsPath": "./PSScriptAnalyzerSettings.psd1",
2526
"terminal.integrated.defaultProfile.linux": "pwsh",
26-
"terminal.integrated.profiles.linux": {
27-
"pwsh": {
28-
"path": "/usr/bin/pwsh",
29-
"icon": "terminal-powershell"
30-
},
31-
"bash": {
32-
"path": "/bin/bash",
33-
"icon": "terminal-bash"
34-
}
35-
}
27+
"powershell.scriptAnalysis.settingsPath": "PSScriptAnalyzerSettings.psd1"
3628
}
3729
}
3830
}

.devcontainer/docker-compose.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Docker Compose service for the devcontainer.
2+
# Variables are resolved from .devcontainer/.env, generated by setup-host.ps1.
3+
services:
4+
devcontainer:
5+
image: mcr.microsoft.com/powershell:ubuntu-24.04
6+
volumes:
7+
- ${LOCAL_WORKSPACE_FOLDER}:/workspaces/${LOCAL_WORKSPACE_FOLDER_BASENAME}:cached
8+
- gh-cli-config:/home/vscode/.config/gh
9+
- ${CLAUDE_HOST_HOME}/.claude:/home/vscode/.claude:cached
10+
- ${CLAUDE_HOST_HOME}/.claude.json:/home/vscode/.claude.json:ro
11+
command: sleep infinity
12+
13+
volumes:
14+
gh-cli-config:

.devcontainer/setup-host.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Resolve host paths for cross-platform devcontainer bind mounts.
2+
# Writes .devcontainer/.env for docker-compose variable substitution.
3+
# This runs on the HOST via initializeCommand before the container is created.
4+
5+
$claudeHome = if ($env:USERPROFILE) { $env:USERPROFILE } elseif ($env:HOME) { $env:HOME } else { $null }
6+
7+
if (-not $claudeHome) {
8+
Write-Warning 'Could not detect host home directory (neither USERPROFILE nor HOME is set).'
9+
Write-Warning 'Claude Code config bind mounts will not be available in the devcontainer.'
10+
return
11+
}
12+
13+
# Resolve the workspace folder (parent of .devcontainer/)
14+
$workspace = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
15+
$workspaceName = Split-Path $workspace -Leaf
16+
17+
# Normalize to forward slashes for Docker bind mount compatibility on Windows
18+
$claudeHome = $claudeHome -replace '\\', '/'
19+
$workspace = $workspace -replace '\\', '/'
20+
21+
$envContent = @"
22+
CLAUDE_HOST_HOME="$claudeHome"
23+
LOCAL_WORKSPACE_FOLDER="$workspace"
24+
LOCAL_WORKSPACE_FOLDER_BASENAME="$workspaceName"
25+
"@
26+
27+
$envPath = Join-Path $PSScriptRoot '.env'
28+
Set-Content -Path $envPath -Value $envContent
29+
Write-Host "Wrote devcontainer .env to $envPath"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ local.secrets.json
1919
# Claude Code local settings
2020
.claude/
2121

22+
# Devcontainer generated env (created by setup-host.ps1)
23+
.devcontainer/.env
24+
2225
# IDE specific
2326
.idea/
2427
*.suo

.vscode/extensions.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
"recommendations": [
3-
"ms-vscode.powershell",
4-
"editorconfig.editorconfig",
5-
"eamodio.gitlens"
3+
"ms-vscode.powershell"
64
]
75
}

0 commit comments

Comments
 (0)