Set stable WORKDIR so dotfiles install survives docroot swap (#45)#51
Merged
Conversation
The php base image leaves WORKDIR at /var/www/html, which
devcontainer_on_create.sh deletes and replaces with a symlink to the
mounted docroot. The devcontainer CLI starts its persistent setup shell
("shellServer") in WORKDIR with no -w flag, so that rm -rf orphans the
shell's cwd. The later dotfiles `git clone` runs in the same shellServer
and fails its getcwd() with "Unable to read current working directory".
The lifecycle commands run as separate execs (-w workspaceFolder), so
the cd "$WORKSPACE_FOLDER" added in #48 can't repair the shellServer.
Anchoring WORKDIR to /home/vscode keeps the shellServer's cwd valid
through the docroot swap.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The cd "$WORKSPACE_FOLDER" appended to devcontainer_on_create and devcontainer_post_create in #48 was meant to leave the devcontainer CLI's persistent shellServer in a valid cwd before the dotfiles clone. It can't: each lifecycle command runs in its own `/bin/sh -c` exec that exits as soon as the function returns, so the cd never touches the shellServer. The real fix is anchoring the image WORKDIR (prior commit). Kept _cwd_workspace at the top of each script — on_create's docroot symlink (ln -s "$(pwd)/web" ...) depends on a deterministic cwd, so that call is load-bearing, not part of the broken cwd-restore theory. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Dotfiles install still fails on the first
devcontainer upwith:Reopened #45 with the full analysis. The
_cwd_workspace/cd "$WORKSPACE_FOLDER"fix in #48 doesn't work, because lifecycle commands and the dotfiles clone run in different processes.Root cause
-w— so the shell inherits the image'sWORKDIR,/var/www/html(from thephpbase image; we never override it).devcontainer_on_create.sh:20doessudo rm -rf /var/www/html && sudo ln -s "$(pwd)/web" /var/www/html. Thatrm -rfunlinks the directory the shellServer is sitting in, orphaning its cwd.git cloneruns in that same shellServer;git-remote-httpscallsgetcwd(), getsENOENT, and aborts.docker exec -w /workspaces/<repo>processes, so thecd "$WORKSPACE_FOLDER"at the end of those scripts (from Fix dotfiles install (#45) and upgrade to PHP 8.4 #48) changes a process that immediately exits and never touches the shellServer.Fix
Set a stable
WORKDIRin the Dockerfile so the shellServer starts — and stays — in a directory the lifecycle scripts never delete:WORKDIR /home/vscodeThe docroot symlink swap on
on-create:20is unchanged. The_cwd_workspaceadditions from #48 are left in place as harmless lifecycle-script hygiene.Verification
Minimal reproduction of the mechanism (reproduces the exact error), and confirmation that anchoring the shell's cwd away from the deleted directory resolves it, is in #45. Building the image with this change and running
dcewith--dotfiles-repositoryset completes the clone successfully.Closes #45
🤖 Generated with Claude Code