Skip to content

Commit d64024c

Browse files
committed
Add devcontainer configuration for development
This adds a complete development container configuration that includes: - Bun (for formatting and scripts) - Terraform (for module development) - Docker-in-Docker (for running tests) - VS Code extensions and settings The devcontainer automatically installs all dependencies on creation, making it easy for contributors to start developing without manual setup. Resolves #51
1 parent 2de6a57 commit d64024c

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-0
lines changed

.devcontainer/README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Development Container
2+
3+
This directory contains a Dev Container configuration that provides a complete development environment for the Coder Registry with all required dependencies pre-installed.
4+
5+
## What's Included
6+
7+
The dev container includes:
8+
9+
- **Bun** - JavaScript runtime and package manager (for formatting and scripts)
10+
- **Terraform** - Infrastructure as code tool (for module development)
11+
- **Docker** - Container runtime (for running tests with `--network=host`)
12+
- **Git** - Version control
13+
- **VS Code Extensions**:
14+
- HashiCorp Terraform
15+
- Bun for VS Code
16+
- Prettier
17+
18+
## Quick Start
19+
20+
### Using VS Code
21+
22+
1. Install the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
23+
2. Open this repository in VS Code
24+
3. When prompted, click "Reopen in Container" (or run the command "Dev Containers: Reopen in Container")
25+
4. Wait for the container to build and dependencies to install
26+
5. Start developing!
27+
28+
### Using GitHub Codespaces
29+
30+
1. Click the "Code" button on the GitHub repository
31+
2. Select "Codespaces" tab
32+
3. Click "Create codespace on main"
33+
4. Wait for the environment to be ready
34+
5. Start developing!
35+
36+
### Using Coder
37+
38+
You can also use this with Coder's `docker-devcontainer` template:
39+
40+
1. Create a new workspace using the `docker-devcontainer` template
41+
2. Point it to this repository
42+
3. Coder will automatically use the `.devcontainer/devcontainer.json` configuration
43+
44+
## What Happens on Startup
45+
46+
When the container is created, it automatically:
47+
48+
1. Installs Bun via the official installation script
49+
2. Runs `bun install` to install all project dependencies
50+
3. Sets up PATH to include Bun binaries
51+
4. Mounts Docker socket for Docker-in-Docker support
52+
5. Configures VS Code with recommended extensions and settings
53+
54+
## Development Workflow
55+
56+
Once inside the container, you can use all the standard commands:
57+
58+
```bash
59+
# Format code
60+
bun run fmt
61+
62+
# Run tests
63+
bun run test
64+
65+
# Create a new module
66+
./scripts/new_module.sh namespace/module-name
67+
68+
# Test a specific module
69+
cd registry/namespace/modules/module-name
70+
terraform init -upgrade
71+
terraform test -verbose
72+
```
73+
74+
## Notes
75+
76+
- The container uses `--network=host` flag which is required for Terraform tests
77+
- Docker socket is mounted to support Docker-based tests
78+
- All dependencies are installed automatically on container creation
79+
- The environment is based on Ubuntu for maximum compatibility
80+
81+
## Troubleshooting
82+
83+
**Bun not found after container creation:**
84+
- Restart the terminal or run: `source ~/.bashrc`
85+
- The PATH should include `~/.bun/bin`
86+
87+
**Docker not working:**
88+
- Ensure Docker is running on your host machine
89+
- Check that Docker socket is properly mounted
90+
91+
**Tests failing:**
92+
- Make sure you're using Linux or a compatible Docker runtime (Colima/OrbStack on macOS)
93+
- Verify Docker has network access with `--network=host`
94+
95+
## Contributing
96+
97+
This dev container configuration is part of the Coder Registry repository. If you find issues or have suggestions for improvements, please open an issue or pull request!

.devcontainer/devcontainer.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "Coder Registry Development",
3+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
4+
5+
"features": {
6+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
7+
"ghcr.io/devcontainers/features/terraform:1": {
8+
"version": "latest"
9+
},
10+
"ghcr.io/devcontainers/features/git:1": {},
11+
"ghcr.io/devcontainers/features/common-utils:2": {
12+
"installZsh": true,
13+
"installOhMyZsh": true
14+
}
15+
},
16+
17+
"postCreateCommand": "curl -fsSL https://bun.sh/install | bash && export BUN_INSTALL=\"$HOME/.bun\" && export PATH=\"$BUN_INSTALL/bin:$PATH\" && bun install",
18+
19+
"customizations": {
20+
"vscode": {
21+
"extensions": [
22+
"hashicorp.terraform",
23+
"oven.bun-vscode",
24+
"esbenp.prettier-vscode"
25+
],
26+
"settings": {
27+
"files.exclude": {
28+
"**/terraform.tfstate": true,
29+
"**/.terraform": true
30+
},
31+
"editor.formatOnSave": true,
32+
"editor.defaultFormatter": "esbenp.prettier-vscode",
33+
"[terraform]": {
34+
"editor.defaultFormatter": "hashicorp.terraform"
35+
}
36+
}
37+
}
38+
},
39+
40+
"remoteEnv": {
41+
"BUN_INSTALL": "${containerHome}/.bun",
42+
"PATH": "${containerHome}/.bun/bin:${containerEnv:PATH}"
43+
},
44+
45+
"forwardPorts": [],
46+
47+
"mounts": [
48+
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
49+
],
50+
51+
"runArgs": ["--network=host"]
52+
}

0 commit comments

Comments
 (0)