fix(devcontainer): Dockerfile build fails when .dockerignore excludes .git/ (#1234)
CI / build (push) Successful in 24s
CI / helm (push) Successful in 25s
CI / lint (push) Successful in 3m21s
CI / quality (push) Successful in 3m46s
CI / typecheck (push) Successful in 4m1s
CI / benchmark-regression (push) Has been skipped
CI / security (push) Successful in 4m14s
CI / integration_tests (push) Successful in 8m55s
CI / unit_tests (push) Successful in 9m54s
CI / docker (push) Successful in 1m33s
CI / coverage (push) Successful in 12m33s
CI / e2e_tests (push) Successful in 19m38s
CI / status-check (push) Successful in 1s
CI / benchmark-publish (push) Successful in 28m27s

## Summary

Fixes the Docker build failure at step 30/30:
```
fatal: not a git repository (or any of the parent directories): .git
```

## Root Cause

`.dockerignore` excludes `.git/`, so `COPY . $APP_DIR` never copies the `.git` directory into the image. However, the final `RUN` step unconditionally runs `git clean -xdf`, which requires a git repository to exist.

## Fix

Wrapped `git clean -xdf` and `rm -rf .git` in a conditional that checks for `.git` directory existence first, falling through silently when absent:

```dockerfile
([ -d .git ] && git clean -xdf && rm -rf .git || true)
```

This makes the Dockerfile work correctly whether `.git` is present (e.g., if `.dockerignore` is modified) or absent (current behavior).

## Quality Gates

| Gate | Result |
|------|--------|
| lint | Pass |
| typecheck | Pass (0 errors) |
| pre-commit hooks | Pass |

(Dockerfile-only change — no Python code modified, so unit/integration tests are unaffected.)

Closes #1233

Reviewed-on: #1234
Reviewed-by: Luis Mendes <luis.mendes@cleverthis.com>
Co-authored-by: Brent E. Edwards <brent.edwards@cleverthis.com>
Co-committed-by: Brent E. Edwards <brent.edwards@cleverthis.com>
This commit was merged in pull request #1234.
This commit is contained in:
2026-03-31 21:14:46 +00:00
committed by Forgejo
parent dd3b0286e5
commit eed455d9f9
+82 -82
View File
@@ -25,36 +25,36 @@ RUN sudo apt-get update && \
sudo apt-get upgrade -y --no-install-recommends && \
sudo apt-get dist-upgrade -y --no-install-recommends && \
sudo apt-get install -y --no-install-recommends \
# Essential build tools
build-essential \
libportaudio2 \
iproute2 \
gcc \
g++ \
make \
# Development utilities
curl \
wget \
git \
vim \
nano \
jq \
gawk \
pandoc \
tree \
htop \
unzip \
ca-certificates \
# Shell enhancements
zsh \
# Networking tools
net-tools \
iputils-ping \
# Process management
procps \
# For MCP servers
gnupg \
lsb-release && \
# Essential build tools
build-essential \
libportaudio2 \
iproute2 \
gcc \
g++ \
make \
# Development utilities
curl \
wget \
git \
vim \
nano \
jq \
gawk \
pandoc \
tree \
htop \
unzip \
ca-certificates \
# Shell enhancements
zsh \
# Networking tools
net-tools \
iputils-ping \
# Process management
procps \
# For MCP servers
gnupg \
lsb-release && \
# Install Node.js 20 (required for many MCP servers)
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list && \
@@ -80,56 +80,56 @@ RUN sudo npm install -g @anthropic-ai/claude-code
# Install development tools globally
RUN sudo pip install --no-cache-dir \
"ruff>=0.4.0" \
"pyright>=1.1.400" \
"pre-commit>=3.8.0" \
"commitizen>=4.4.0" \
"nox>=2025.4.22" \
"uv-mcp" \
"uv>=0.8.0" \
"dev-kit-mcp-server" \
"mkdocs>=1.6.1" \
"mike>=2.0.0" \
"mkdocs-material>=9.6.0" \
"mkdocs-behave>=1.0.0" \
"mkdocstrings>=0.30.0" \
"mkdocstrings-python>=1.18.2" \
"pymdown-extensions>=10.16.1" \
"psutil>=7.1.0" \
"torch>=2.0.0" \
"transformers>=4.30.0" \
"tokenizers>=0.15.0" \
"hypothesis>=6.136.6" \
"aiofiles>=24.1.0" \
"pyhamcrest>=2.1.0" \
"numpy>=2.3.3" \
"huggingface-hub>=0.35.1" \
"mkdocs-kroki-plugin>=0.9.0" \
"torch>=2.0.0" \
"transformers>=4.30.0" \
"tokenizers>=0.15.0" \
"torch-geometric>=2.7.0" \
"rdflib>=7.1.4" \
"asv>=0.6.5"
"ruff>=0.4.0" \
"pyright>=1.1.400" \
"pre-commit>=3.8.0" \
"commitizen>=4.4.0" \
"nox>=2025.4.22" \
"uv-mcp" \
"uv>=0.8.0" \
"dev-kit-mcp-server" \
"mkdocs>=1.6.1" \
"mike>=2.0.0" \
"mkdocs-material>=9.6.0" \
"mkdocs-behave>=1.0.0" \
"mkdocstrings>=0.30.0" \
"mkdocstrings-python>=1.18.2" \
"pymdown-extensions>=10.16.1" \
"psutil>=7.1.0" \
"torch>=2.0.0" \
"transformers>=4.30.0" \
"tokenizers>=0.15.0" \
"hypothesis>=6.136.6" \
"aiofiles>=24.1.0" \
"pyhamcrest>=2.1.0" \
"numpy>=2.3.3" \
"huggingface-hub>=0.35.1" \
"mkdocs-kroki-plugin>=0.9.0" \
"torch>=2.0.0" \
"transformers>=4.30.0" \
"tokenizers>=0.15.0" \
"torch-geometric>=2.7.0" \
"rdflib>=7.1.4" \
"asv>=0.6.5"
# Install MCP servers globally (npm-based)
RUN sudo npm install -g \
@crunchloop/mcp-devcontainers \
kubernetes-mcp-server \
@opentofu/opentofu-mcp-server \
@modelcontextprotocol/server-filesystem \
@modelcontextprotocol/server-memory \
@modelcontextprotocol/server-sequential-thinking \
@modelcontextprotocol/server-postgres \
@treedy/pyright-mcp \
mcp-server-docker \
@cucumber/language-server && \
@crunchloop/mcp-devcontainers \
kubernetes-mcp-server \
@opentofu/opentofu-mcp-server \
@modelcontextprotocol/server-filesystem \
@modelcontextprotocol/server-memory \
@modelcontextprotocol/server-sequential-thinking \
@modelcontextprotocol/server-postgres \
@treedy/pyright-mcp \
mcp-server-docker \
@cucumber/language-server && \
# Install MCP servers (pip-based: fetch, git, sqlite) + LSP + security tools
sudo pip install --no-cache-dir \
robotframework-lsp \
mcp-server-fetch \
mcp-server-git \
mcp-server-sqlite \
semgrep
robotframework-lsp \
mcp-server-fetch \
mcp-server-git \
mcp-server-sqlite \
semgrep
# Create directories for MCP server configurations and logs
RUN mkdir -p ~/.config/claude-code \
@@ -215,10 +215,10 @@ RUN sudo pip install python-lsp-server[all]
# Install additional LSP servers
RUN sudo npm install -g \
yaml-language-server \
vscode-json-languageserver \
dockerfile-language-server-nodejs \
bash-language-server
yaml-language-server \
vscode-json-languageserver \
dockerfile-language-server-nodejs \
bash-language-server
ENV FORGEJO_URL="https://git.cleverthis.com/"
COPY .devcontainer/crush.json ${USER_HOME}/.config/crush/crush.json
@@ -231,8 +231,8 @@ WORKDIR $APP_DIR
RUN sudo chown -R ${USER_UID}:${USER_GID} "$APP_DIR" && \
cd $APP_DIR && \
git config --global --add safe.directory /app && \
git clean -xdf && \
rm -rf .git && \
# Clean and remove .git only if it was copied (not excluded by .dockerignore)
([ -d .git ] && git clean -xdf && rm -rf .git || true) && \
# So git doesn't complain about unusual permissions
sudo git config --system --add safe.directory ${APP_DIR}