Skip to content

Commit 47c1b34

Browse files
authored
Optimize devcontainer for faster startup (#9)
* Optimize devcontainer for faster startup - Disabled package upgrades (upgradePackages: false) - Removed heavy features: kubectl-helm-minikube, sshd - Changed Git to os-provided version for faster builds - Removed unnecessary packages from Dockerfile - Removed docker-compose.yml for simpler single-container setup - Streamlined postCreateCommand - Removed heavy VS Code extensions - Added setup-optional-tools.sh for on-demand tool installation - Added dependabot.yml for dependency management Estimated startup time reduced from 4-6 minutes to 1-2 minutes. Signed-off-by: Ihor Dvoretskyi <[email protected]> * Fix CI workflow to match optimized devcontainer - Remove docker-compose.yml validation steps - Remove tcl dependency installation - Remove kubectl and helm checks (not installed by default) - Remove tclsh check (not installed by default) - Keep only essential tool checks Signed-off-by: Ihor Dvoretskyi <[email protected]> * Fix Hadolint DL3008 warning in Dockerfile Add hadolint ignore comment for DL3008 warning about unpinned package versions. For a development template, using latest versions from the base image is preferred for flexibility and ease of maintenance. Signed-off-by: Ihor Dvoretskyi <[email protected]> * Fix Gitleaks by fetching full git history Add fetch-depth: 0 to checkout steps to ensure Gitleaks has access to the full commit history for scanning the commit range. Signed-off-by: Ihor Dvoretskyi <[email protected]> * Remove github-copilot-cli check from tests This tool is no longer installed as part of the optimized devcontainer. Signed-off-by: Ihor Dvoretskyi <[email protected]> * Add Python support for balanced operability Add Python 3.12 feature with pip and tools for a complete development experience. Python is nearly universal for scripting, automation, and development workflows. Changes: - Added Python 3.12 with pip and development tools - Added Python VS Code extensions (Python, Pylance) - Updated postCreateCommand to verify all core tools - Updated CI tests to verify Python installation - Updated README with more accurate feature list and timing This balances startup speed (2-3 min) with operational completeness. Signed-off-by: Ihor Dvoretskyi <[email protected]> * Add Claude Code CLI and extension by default Install Claude Code CLI via npm in postCreateCommand and include the Claude Dev VS Code extension for AI-assisted development. Changes: - Added Claude Code CLI installation via npm - Added anthropic.claude-dev VS Code extension - Updated postCreateCommand to verify claude installation - Updated CI tests to check for claude CLI - Updated README to list Claude Code in features Signed-off-by: Ihor Dvoretskyi <[email protected]> * Remove redundant setup-optional-tools.sh script Since all essential tools (including Claude Code CLI) are now installed by default in postCreateCommand, the optional tools script is redundant. Changes: - Removed .devcontainer/setup-optional-tools.sh - Updated README with better customization examples - Added examples for adding Kubernetes tools when needed Signed-off-by: Ihor Dvoretskyi <[email protected]> * Update security workflow for optimized devcontainer Improvements: - Remove redundant tcl installation step - Fix Dockerfile path in trigger (covered by .devcontainer/**) - Pin Trivy action to specific version (0.28.0) instead of @master - Add severity filtering (CRITICAL,HIGH) to focus on important issues - Improve workflow stability and reproducibility The workflow now properly scans the optimized devcontainer configuration. Signed-off-by: Ihor Dvoretskyi <[email protected]> * Update Claude Code extension reference in devcontainer configuration Signed-off-by: Ihor Dvoretskyi <[email protected]> --------- Signed-off-by: Ihor Dvoretskyi <[email protected]>
1 parent c751783 commit 47c1b34

File tree

7 files changed

+121
-76
lines changed

7 files changed

+121
-76
lines changed

.devcontainer/Dockerfile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
FROM mcr.microsoft.com/devcontainers/base:ubuntu-24.04
22

3-
# Install essential packages and set up directories
43
# hadolint ignore=DL3008
54
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
65
&& apt-get -y install --no-install-recommends \
76
curl \
87
wget \
98
jq \
109
build-essential \
11-
openssh-server \
12-
tcl \
1310
&& apt-get clean -y \
14-
&& rm -rf /var/lib/apt/lists/* \
15-
&& mkdir -p /run/sshd \
16-
&& mkdir -p /home/vscode/.ssh \
17-
&& chown -R vscode:vscode /home/vscode/.ssh \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
RUN mkdir -p /home/vscode/.ssh \
14+
&& chown -R vscode:vscode /home/vscode \
1815
&& chmod 700 /home/vscode/.ssh

.devcontainer/devcontainer.json

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
"ghcr.io/devcontainers/features/common-utils:2": {
1010
"installZsh": true,
1111
"username": "vscode",
12-
"upgradePackages": true
12+
"upgradePackages": false
1313
},
1414
"ghcr.io/devcontainers/features/git:1": {
15-
"version": "latest",
15+
"version": "os-provided",
1616
"ppa": false
1717
},
18+
"ghcr.io/devcontainers/features/python:1": {
19+
"version": "3.12",
20+
"installTools": true
21+
},
1822
"ghcr.io/devcontainers/features/node:1": {
1923
"version": "lts",
2024
"nodeGypDependencies": false,
@@ -25,14 +29,6 @@
2529
"moby": true,
2630
"dockerDashComposeVersion": "v2"
2731
},
28-
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {
29-
"version": "latest",
30-
"helm": "latest",
31-
"minikube": "latest"
32-
},
33-
"ghcr.io/devcontainers/features/sshd:1": {
34-
"version": "latest"
35-
},
3632
"ghcr.io/devcontainers/features/github-cli:1": {
3733
"version": "latest"
3834
}
@@ -44,8 +40,9 @@
4440
"github.copilot",
4541
"github.copilot-chat",
4642
"redhat.vscode-yaml",
47-
"ms-kubernetes-tools.vscode-kubernetes-tools",
48-
"blinksh.blink-fs"
43+
"ms-python.python",
44+
"ms-python.vscode-pylance",
45+
"anthropic.claude-code"
4946
],
5047
"settings": {
5148
"editor.formatOnSave": true,
@@ -57,8 +54,6 @@
5754
}
5855
}
5956
},
60-
"forwardPorts": [22],
61-
"postCreateCommand": "npm install -g @anthropic-ai/claude-code@latest @github/copilot && echo '🚀 Development environment ready! Docker, Kubernetes (Minikube), Claude Code, GitHub Copilot CLI, and SSH are configured.' && sudo service ssh start",
62-
"postStartCommand": "sudo service ssh restart",
57+
"postCreateCommand": "npm install -g @anthropic-ai/claude-code && python3 --version && node --version && docker --version && gh --version && claude --version && echo 'Development environment ready'",
6358
"remoteUser": "vscode"
6459
}

.devcontainer/docker-compose.yml

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

.github/dependabot.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Keep devcontainer dependencies up to date
2+
version: 2
3+
updates:
4+
# Monitor GitHub Actions
5+
- package-ecosystem: "github-actions"
6+
directory: "/"
7+
schedule:
8+
interval: "weekly"
9+
labels:
10+
- "dependencies"
11+
- "github-actions"
12+
13+
# Monitor Docker base images
14+
- package-ecosystem: "docker"
15+
directory: "/.devcontainer"
16+
schedule:
17+
interval: "weekly"
18+
labels:
19+
- "dependencies"
20+
- "docker"

.github/workflows/ci.yml

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,8 @@ jobs:
1717
steps:
1818
- name: Checkout
1919
uses: actions/checkout@v4
20-
21-
- name: Install missing dependencies
22-
run: sudo apt-get update && sudo apt-get install -y tcl
23-
24-
- name: Check Docker Compose file existence
25-
run: test -f .devcontainer/docker-compose.yml && echo "Docker Compose file exists"
26-
27-
- name: Validate docker-compose.yml
28-
run: docker compose -f .devcontainer/docker-compose.yml config
20+
with:
21+
fetch-depth: 0
2922

3023
- name: Lint Dockerfile
3124
uses: hadolint/[email protected]
@@ -48,27 +41,27 @@ jobs:
4841
steps:
4942
- name: Checkout
5043
uses: actions/checkout@v4
51-
52-
- name: Install missing dependencies
53-
run: sudo apt-get update && sudo apt-get install -y tcl
54-
55-
- name: Check Docker Compose version
56-
run: docker compose version
44+
with:
45+
fetch-depth: 0
5746

5847
- name: Test devcontainer functionality
5948
uses: devcontainers/[email protected]
6049
with:
6150
push: never
6251
runCmd: |
6352
# Test basic tools are available
64-
which tclsh || echo "tclsh is missing"
53+
which python3 || echo "python3 is missing"
54+
which pip3 || echo "pip3 is missing"
6555
which docker || echo "docker is missing"
66-
which kubectl || echo "kubectl is missing"
67-
which helm || echo "helm is missing"
6856
which gh || echo "gh is missing"
6957
which node || echo "node is missing"
7058
which npm || echo "npm is missing"
71-
which github-copilot-cli || echo "github-copilot-cli is missing"
59+
which claude || echo "claude is missing"
7260
# Test essential packages
61+
python3 --version
62+
node --version
63+
docker --version
64+
gh --version
65+
claude --version
7366
curl --version
7467
jq --version

.github/workflows/security.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ on:
88
branches: [ main ]
99
paths:
1010
- '.devcontainer/**'
11-
- 'Dockerfile'
1211
- '.github/workflows/security.yml'
1312
pull_request:
1413
branches: [ main ]
1514
paths:
1615
- '.devcontainer/**'
17-
- 'Dockerfile'
1816
- '.github/workflows/security.yml'
1917
workflow_dispatch: # Allow manual trigger
2018

@@ -30,21 +28,19 @@ jobs:
3028
- name: Checkout
3129
uses: actions/checkout@v4
3230

33-
- name: Install missing dependencies
34-
run: sudo apt-get update && sudo apt-get install -y tcl
35-
3631
- name: Build Docker image for scanning
3732
run: |
3833
IMAGE_NAME="dev-template:${{ github.sha }}"
3934
docker build -t "$IMAGE_NAME" .devcontainer/
4035
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
4136
4237
- name: Run Trivy vulnerability scanner
43-
uses: aquasecurity/trivy-action@master
38+
uses: aquasecurity/trivy-action@0.28.0
4439
with:
4540
image-ref: '${{ env.IMAGE_NAME }}'
4641
format: 'sarif'
4742
output: 'trivy-results.sarif'
43+
severity: 'CRITICAL,HIGH'
4844

4945
- name: Upload Trivy scan results to GitHub Security tab
5046
uses: github/codeql-action/upload-sarif@v3
@@ -70,12 +66,13 @@ jobs:
7066
retention-days: 30
7167

7268
- name: Run Trivy filesystem scan
73-
uses: aquasecurity/trivy-action@master
69+
uses: aquasecurity/trivy-action@0.28.0
7470
with:
7571
scan-type: 'fs'
7672
scan-ref: '.'
7773
format: 'sarif'
7874
output: 'trivy-fs-results.sarif'
75+
severity: 'CRITICAL,HIGH'
7976

8077
- name: Upload filesystem scan results
8178
uses: github/codeql-action/upload-sarif@v3

README.md

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,90 @@
33
[![CI](https://github.com/idvoretskyi/dev/actions/workflows/ci.yml/badge.svg)](https://github.com/idvoretskyi/dev/actions/workflows/ci.yml)
44
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/idvoretskyi/dev)
55

6-
This repository serves as a default generic GitHub Codespace template.
6+
This repository serves as an optimized GitHub Codespaces template for general development workflows.
77

88
## Features
99

1010
- Base image: Ubuntu 24.04
11-
- Pre-installed development tools
12-
- VS Code extensions for productivity
13-
- Configured with sensible defaults
11+
- Essential development tools:
12+
- Python 3.12 with pip
13+
- Node.js LTS with npm
14+
- Git (OS-provided)
15+
- Docker-in-Docker with Docker Compose v2
16+
- GitHub CLI
17+
- Claude Code CLI
18+
- Zsh with common utilities
19+
- Build essentials (gcc, make, etc.)
20+
- VS Code extensions:
21+
- Claude Dev (Anthropic)
22+
- Python language support
23+
- Docker support
24+
- GitHub Copilot
25+
- YAML support
26+
27+
## Performance Optimizations
28+
29+
The devcontainer balances speed with operability:
30+
31+
- Includes essential tools: Python, Node.js, Docker, Git, GitHub CLI, Claude Code CLI
32+
- Disabled package upgrades during build
33+
- Removed heavy features (kubectl, helm, minikube, sshd)
34+
- Uses OS-provided Git for faster builds
35+
- Installs Claude Code CLI via npm in postCreateCommand
36+
- Core VS Code extensions only
37+
38+
Estimated startup time: 2-3 minutes
1439

1540
## Usage
1641

42+
### GitHub Codespaces
1743
1. Click "Code" button on the GitHub repository
1844
2. Select "Create codespace on main"
1945
3. Wait for the environment to build
20-
4. Start coding!
2146

22-
## Customization
47+
### VS Code Local Dev Containers
48+
1. Clone this repository
49+
2. Open in VS Code
50+
3. Click "Reopen in Container" when prompted
51+
52+
## Using as a Template
53+
54+
### Method 1: GitHub Template
55+
Click "Use this template" button to create a new repository
56+
57+
### Method 2: Copy Configuration
58+
```bash
59+
cp -r .devcontainer /path/to/your/project/
60+
```
61+
62+
### Customization
63+
64+
Edit `.devcontainer/devcontainer.json` to add features or tools:
65+
66+
```json
67+
{
68+
"features": {
69+
"ghcr.io/devcontainers/features/java:1": {
70+
"version": "17"
71+
}
72+
},
73+
"postCreateCommand": "pip install -r requirements.txt"
74+
}
75+
```
2376

24-
You can customize this environment by:
77+
To add heavy tools like Kubernetes:
2578

26-
- Modifying `.devcontainer/devcontainer.json` to add VS Code extensions or settings
27-
- Editing `.devcontainer/Dockerfile` to install additional packages
28-
- Updating `.devcontainer/docker-compose.yml` to add services like databases
79+
```json
80+
{
81+
"features": {
82+
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {
83+
"version": "latest",
84+
"helm": "latest",
85+
"minikube": "none"
86+
}
87+
}
88+
}
89+
```
2990

3091
## License
3192

0 commit comments

Comments
 (0)