mirror of
https://github.com/fscotto/infra.git
synced 2026-11-26 13:49:52 +00:00
Compare commits
10 Commits
ffa9960c64
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a9ecffecf | ||
| 012cb3534b | |||
| 47acda71b6 | |||
|
|
e74088e85b | ||
|
|
e2370ec91d | ||
|
|
59160abf0d | ||
| cdc102a970 | |||
| 66925b1d0d | |||
| 3facf61866 | |||
| 0b30890464 |
15
AGENTS.md
15
AGENTS.md
@@ -564,7 +564,7 @@ validated exports of older historical data will use a dedicated Atlas NFS datase
|
||||
- Shared agent dotfiles live in `ai_agents_dotfiles`; rendered configs live in `ai_agents_templates`.
|
||||
- Every `ai_agents.<agent>` entry has independent `install_enabled`, `deploy_enabled`, and `uninstall_enabled` flags. Installation and removal must not both be true for the same agent; the common pre-task fails before changes when they conflict.
|
||||
- Fedora, Void desktop, and WSL workstation profiles consume the shared agent definitions; do not duplicate package entries in profile-specific vars. IBM Bob on the workstation follows its own flags.
|
||||
- WSL (`deadalus`) keeps only Claude Code installed; every other managed agent (including IBM Bob) is disabled and selected for removal through host overrides. Existing user state remains untouched.
|
||||
- WSL (`deadalus`) installs Claude Code, Codex and the Cline CLI; every other managed agent (including IBM Bob) is disabled and selected for removal through host overrides. `cline_deploy_enabled: true` also keeps Cline's cross-tool AGENTS pointer, global rules, and shared `~/.config/ai` context deployed on the host for the ecaas/cdp devcontainer bind mounts. Existing user state remains untouched.
|
||||
- `dotfiles_common` deploys `ai_agents_dotfiles` and renders `ai_agents_templates` only when deployment is enabled.
|
||||
- Removal is limited to the managed npm packages and `/usr/local/bin/bob`; never remove agent dotfiles, instructions, credentials, or user data.
|
||||
- Keep `.config/ai/` as the common instruction source; update agent-specific entrypoints to reference it rather than duplicating instruction text.
|
||||
@@ -604,3 +604,16 @@ validated exports of older historical data will use a dedicated Atlas NFS datase
|
||||
not depend on the AdGuard container during startup.
|
||||
- Aegis iCloudPD has been retired and is no longer managed by this role. Its service, Quadlet,
|
||||
data, and MFA state were removed with the operator's explicit authorization.
|
||||
|
||||
## Project Devcontainer Generator
|
||||
- `cmd/devcontainer/` generates standalone per-project language configurations;
|
||||
it does not replace existing deadalus ecaas/cdp provisioning or remove host tools.
|
||||
- Keep shared Git/agent behavior documented in `docs/project-devcontainers.md`.
|
||||
- Focused validation: `go -C cmd/devcontainer test ./...`.
|
||||
- Real engine builds, host credential forwarding and Fedora SELinux/Podman checks
|
||||
require target-host validation; do not report generator tests as runtime evidence.
|
||||
|
||||
- `devcontainer_generator` builds the CLI natively on Fedora graphical desktops
|
||||
and development workstations and installs it in `~/.local/bin/devcontainer`.
|
||||
Validate with `ansible-playbook ansible/site.yml --limit ikaros --tags devcontainer_generator --check --diff`;
|
||||
check mode skips compilation and binary installation explicitly.
|
||||
|
||||
15
README.md
15
README.md
@@ -598,8 +598,11 @@ instructions, credentials, and user data. Installation and removal are mutually
|
||||
exclusive per agent: the playbook fails before making changes when both flags are
|
||||
true for the same agent. Servers set `ai_agents: {}` and therefore manage none.
|
||||
|
||||
On WSL (`deadalus`), every managed coding agent except Claude Code is disabled through
|
||||
On WSL (`deadalus`), Claude Code, Codex and the Cline CLI are installed through
|
||||
`profile_workstation_dev_common`. Every other managed coding agent is disabled through
|
||||
host overrides and its managed npm package or `bob` binary is selected for removal.
|
||||
`cline_deploy_enabled: true` also keeps Cline's cross-tool AGENTS pointer, global rules,
|
||||
and shared `~/.config/ai` context deployed on the WSL host for the ecaas/cdp devcontainers.
|
||||
Existing configuration, credentials, and user data are left untouched.
|
||||
|
||||
The shared agent context is centralized in `dotfiles/common/.config/ai/` and
|
||||
@@ -890,3 +893,13 @@ For a future Void desktop host:
|
||||
4. Put hardware-specific details in `host_vars/<host>.yml`.
|
||||
|
||||
The legacy `void` and `desktop` groups remain compatibility parents, so hosts in `platform_void` and `graphical_desktop` still receive the existing Void and desktop variables.
|
||||
|
||||
## Project devcontainer generator
|
||||
|
||||
Generate a reusable language environment for an existing project with
|
||||
`devcontainer ~/src/project --language python --agents codex,cline`.
|
||||
Git and selected coding-agent configuration are shared from the development host.
|
||||
See [profiles, host requirements and validation](docs/project-devcontainers.md).
|
||||
|
||||
Deploy `~/.local/bin/devcontainer` on a Fedora desktop/workstation with
|
||||
`ansible-playbook ansible/site.yml --limit ikaros --tags devcontainer_generator -K`.
|
||||
|
||||
@@ -91,6 +91,7 @@ fedora_nerd_fonts:
|
||||
fedora_flatpak_packages:
|
||||
- be.alexandervanhee.gradia
|
||||
- com.spotify.Client
|
||||
- org.desktop_plus.desktop-plus
|
||||
- org.onlyoffice.desktopeditors
|
||||
- org.telegram.desktop
|
||||
|
||||
@@ -129,7 +130,8 @@ vscode_extensions:
|
||||
- esbenp.prettier-vscode
|
||||
- github.remotehub
|
||||
- ms-azuretools.vscode-containers
|
||||
- ms-azuretools.vscode-docker
|
||||
# ms-azuretools.vscode-docker is deprecated: since June 2025 it is just an
|
||||
# extension pack wrapping Container Tools. Only the real extension is kept.
|
||||
- ms-vscode-remote.remote-containers
|
||||
- ms-vscode-remote.remote-ssh
|
||||
- ms-vscode-remote.remote-ssh-edit
|
||||
@@ -139,11 +141,25 @@ vscode_extensions:
|
||||
- ms-vscode.remote-explorer
|
||||
- ms-vscode.remote-repositories
|
||||
- ms-vscode.remote-server
|
||||
- pkief.material-icon-theme
|
||||
- redhat.vscode-xml
|
||||
- redhat.vscode-yaml
|
||||
- saoudrizwan.claude-dev
|
||||
- vscodevim.vim
|
||||
vscode_settings: null
|
||||
# Managed user settings deploy as a full-file overlay with a timestamped backup;
|
||||
# any manual settings.json edit is converged away on the next run. These keys cover
|
||||
# the podman Dev Containers engine selection and the Container Tools clients.
|
||||
# editor.fontFamily uses the canonical 'JetBrainsMono Nerd Font' family name: the
|
||||
# live 'JetBriansMono NF' was a typo whose fallback chain rendered Liberation Mono.
|
||||
vscode_settings:
|
||||
containers.containerClient: com.microsoft.visualstudio.containers.podman
|
||||
containers.orchestratorClient: com.microsoft.visualstudio.orchestrators.podmancompose
|
||||
dev.containers.dockerPath: podman
|
||||
editor.cursorStyle: block
|
||||
editor.fontFamily: "'JetBrainsMono Nerd Font', 'Droid Sans Mono', monospace"
|
||||
editor.formatOnPaste: true
|
||||
workbench.iconTheme: material-icon-theme
|
||||
workbench.startupEditor: none
|
||||
# User-level keybindings apply to every window, including Dev Containers, SSH and WSL remotes.
|
||||
# Keys avoid Ctrl+<letter>, which the Vim extension uses for its motions; Alt is not bound by Vim.
|
||||
vscode_keybindings:
|
||||
|
||||
@@ -5,21 +5,24 @@ workstation_ecaas_workspace: "{{ user_home }}/Work/sipo/ecaas"
|
||||
workstation_cdp_workspace: "{{ user_home }}/Work/sipo/cdp"
|
||||
workstation_ecaas_git_required_ca: ecaas.datacenter.comune.roma.crt
|
||||
|
||||
# Claude Code is the only coding agent on WSL; every other managed agent is removed.
|
||||
# Claude Code, Codex and the Cline CLI are the coding agents installed on WSL; every
|
||||
# other managed agent is disabled. Cline's cross-tool instructions (.agents/AGENTS.md,
|
||||
# .cline/rules/) and the shared ~/.config/ai context are deployed for the ecaas/cdp
|
||||
# devcontainers, and the cline npm package is installed by profile_workstation_dev_common.
|
||||
claude_code_install_enabled: true
|
||||
claude_code_uninstall_enabled: false
|
||||
opencode_install_enabled: false
|
||||
opencode_deploy_enabled: false
|
||||
opencode_uninstall_enabled: true
|
||||
codex_install_enabled: false
|
||||
codex_install_enabled: true
|
||||
codex_deploy_enabled: false
|
||||
codex_uninstall_enabled: true
|
||||
codex_uninstall_enabled: false
|
||||
gemini_cli_install_enabled: false
|
||||
gemini_cli_deploy_enabled: false
|
||||
gemini_cli_uninstall_enabled: true
|
||||
cline_install_enabled: false
|
||||
cline_deploy_enabled: false
|
||||
cline_uninstall_enabled: true
|
||||
cline_install_enabled: true
|
||||
cline_deploy_enabled: true
|
||||
cline_uninstall_enabled: false
|
||||
ibm_bob_install_enabled: false
|
||||
ibm_bob_uninstall_enabled: true
|
||||
|
||||
|
||||
@@ -246,15 +246,15 @@ gnome_gsettings_settings:
|
||||
- schema: org.gnome.shell
|
||||
key: disabled-extensions
|
||||
value: >-
|
||||
['window-list@gnome-shell-extensions.gcampax.github.com', 'background-logo@fedorahosted.org', 'apps-menu@gnome-shell-extensions.gcampax.github.com', 'places-menu@gnome-shell-extensions.gcampax.github.com']
|
||||
['window-list@gnome-shell-extensions.gcampax.github.com', 'background-logo@fedorahosted.org', 'apps-menu@gnome-shell-extensions.gcampax.github.com', 'places-menu@gnome-shell-extensions.gcampax.github.com', 'maximize-new-windows@VitalyOstanin']
|
||||
- schema: org.gnome.shell
|
||||
key: enabled-extensions
|
||||
value: >-
|
||||
['status-icons@gnome-shell-extensions.gcampax.github.com', 'gnome-ui-tune@itstime.tech', 'appindicatorsupport@rgcjonas.gmail.com', 'bluetooth-battery-monitor@v8v88v8v88.com', 'clipboard-indicator@tudmotu.com', 'status-area-horizontal-spacing@mathematical.coffee.gmail.com', 'MaximizeWindowIntoNewWorkspace@kyleross.com', 'maximize-new-windows@VitalyOstanin']
|
||||
['status-icons@gnome-shell-extensions.gcampax.github.com', 'gnome-ui-tune@itstime.tech', 'appindicatorsupport@rgcjonas.gmail.com', 'bluetooth-battery-monitor@v8v88v8v88.com', 'clipboard-indicator@tudmotu.com', 'status-area-horizontal-spacing@mathematical.coffee.gmail.com', 'MaximizeWindowIntoNewWorkspace@kyleross.com', 'gnome-shell-extension-maximized-by-default@stiggimy.github.com']
|
||||
- schema: org.gnome.shell
|
||||
key: favorite-apps
|
||||
value: >-
|
||||
['org.gnome.Nautilus.desktop', 'org.mozilla.firefox.desktop', 'com.spotify.Client.desktop', 'net.thunderbird.Thunderbird.desktop', 'org.telegram.desktop.desktop', 'Cline.desktop', 'com.microsoft.VSCode.desktop', 'org.gnome.Ptyxis.desktop', 'virt-manager.desktop']
|
||||
['org.gnome.Nautilus.desktop', 'org.mozilla.firefox.desktop', 'com.spotify.Client.desktop', 'net.thunderbird.Thunderbird.desktop', 'org.telegram.desktop.desktop', 'Cline.desktop', 'org.desktop_plus.desktop-plus.desktop', 'com.microsoft.VSCode.desktop', 'org.gnome.Ptyxis.desktop', 'virt-manager.desktop']
|
||||
- schema: org.gnome.shell
|
||||
key: remember-mount-password
|
||||
value: "true"
|
||||
|
||||
4
ansible/roles/devcontainer_generator/defaults/main.yml
Normal file
4
ansible/roles/devcontainer_generator/defaults/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
devcontainer_generator_go_binary: /usr/bin/go
|
||||
devcontainer_generator_install_go: true
|
||||
devcontainer_generator_build_dir: "{{ user_home }}/.cache/infra/devcontainer-generator"
|
||||
64
ansible/roles/devcontainer_generator/tasks/main.yml
Normal file
64
ansible/roles/devcontainer_generator/tasks/main.yml
Normal file
@@ -0,0 +1,64 @@
|
||||
---
|
||||
- name: Install Go compiler for the devcontainer generator
|
||||
ansible.builtin.dnf:
|
||||
name: golang
|
||||
state: present
|
||||
when: devcontainer_generator_install_go | bool
|
||||
|
||||
- name: Ensure devcontainer generator directories exist
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
owner: "{{ username }}"
|
||||
group: "{{ user_group }}"
|
||||
mode: "0755"
|
||||
loop:
|
||||
- "{{ user_home }}/.local/bin"
|
||||
- "{{ devcontainer_generator_build_dir }}"
|
||||
|
||||
- name: Copy devcontainer generator sources
|
||||
ansible.builtin.copy:
|
||||
src: "{{ playbook_dir }}/../cmd/devcontainer/"
|
||||
dest: "{{ devcontainer_generator_build_dir }}/src/"
|
||||
owner: "{{ username }}"
|
||||
group: "{{ user_group }}"
|
||||
mode: preserve
|
||||
|
||||
- name: Build devcontainer generator for the target host
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- "{{ devcontainer_generator_go_binary }}"
|
||||
- build
|
||||
- -trimpath
|
||||
- -buildvcs=false
|
||||
- -o
|
||||
- "{{ devcontainer_generator_build_dir }}/devcontainer"
|
||||
- .
|
||||
chdir: "{{ devcontainer_generator_build_dir }}/src"
|
||||
become_user: "{{ username }}"
|
||||
environment:
|
||||
GOCACHE: "{{ devcontainer_generator_build_dir }}/go-cache"
|
||||
GOTOOLCHAIN: local
|
||||
GOPROXY: "off"
|
||||
GOSUMDB: "off"
|
||||
CGO_ENABLED: "0"
|
||||
# Compilation refreshes a cached artifact; copy below reports installation changes.
|
||||
changed_when: false
|
||||
when: not ansible_check_mode
|
||||
|
||||
- name: Install devcontainer generator in the user PATH
|
||||
ansible.builtin.copy:
|
||||
src: "{{ devcontainer_generator_build_dir }}/devcontainer"
|
||||
remote_src: true
|
||||
dest: "{{ user_home }}/.local/bin/devcontainer"
|
||||
owner: "{{ username }}"
|
||||
group: "{{ user_group }}"
|
||||
mode: "0755"
|
||||
when: not ansible_check_mode
|
||||
|
||||
- name: Explain devcontainer generator check-mode behavior
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
Check mode validates package and source deployment only. Compilation and
|
||||
installation of {{ user_home }}/.local/bin/devcontainer require a normal run.
|
||||
when: ansible_check_mode
|
||||
@@ -66,6 +66,7 @@
|
||||
loop:
|
||||
- { path: .claude, mode: "0700" }
|
||||
- { path: .cline, mode: "0700" }
|
||||
- { path: .agents, mode: "0755" }
|
||||
- { path: .config/ai, mode: "0755" }
|
||||
- { path: .config/glab-cli, mode: "0700" }
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
loop:
|
||||
- { path: .claude, mode: "0700" }
|
||||
- { path: .cline, mode: "0700" }
|
||||
- { path: .agents, mode: "0755" }
|
||||
- { path: .config/ai, mode: "0755" }
|
||||
- { path: .config/glab-cli, mode: "0700" }
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
{{ ('type=bind,source=' ~ user_home ~ '/.local/state/devcontainer-bash-history/cdp,target=/home/vscode/.bash_history.d') | to_json }},
|
||||
{{ ('type=bind,source=' ~ user_home ~ '/.claude,target=/home/vscode/.claude') | to_json }},
|
||||
{{ ('type=bind,source=' ~ user_home ~ '/.cline,target=/home/vscode/.cline') | to_json }},
|
||||
{{ ('type=bind,source=' ~ user_home ~ '/.agents,target=/home/vscode/.agents,readonly') | to_json }},
|
||||
{{ ('type=bind,source=' ~ user_home ~ '/.m2,target=/home/vscode/.m2') | to_json }},
|
||||
{{ ('type=bind,source=' ~ user_home ~ '/.config/glab-cli,target=/home/vscode/.config/glab-cli') | to_json }},
|
||||
{{ ('type=bind,source=' ~ user_home ~ '/.kube,target=/home/vscode/.kube') | to_json }}
|
||||
@@ -45,6 +46,7 @@
|
||||
"ms-kubernetes-tools.vscode-kubernetes-tools",
|
||||
"angular.ng-template",
|
||||
"dbaeumer.vscode-eslint",
|
||||
"saoudrizwan.claude-dev",
|
||||
"emmanuelbeziat.vscode-great-icons"
|
||||
],
|
||||
"settings": {
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
{{ ('type=bind,source=' ~ user_home ~ '/.local/state/devcontainer-bash-history/ecaas,target=/home/vscode/.bash_history.d') | to_json }},
|
||||
{{ ('type=bind,source=' ~ user_home ~ '/.claude,target=/home/vscode/.claude') | to_json }},
|
||||
{{ ('type=bind,source=' ~ user_home ~ '/.cline,target=/home/vscode/.cline') | to_json }},
|
||||
{{ ('type=bind,source=' ~ user_home ~ '/.agents,target=/home/vscode/.agents,readonly') | to_json }},
|
||||
{{ ('type=bind,source=' ~ user_home ~ '/.m2,target=/home/vscode/.m2') | to_json }},
|
||||
{{ ('type=bind,source=' ~ user_home ~ '/.config/glab-cli,target=/home/vscode/.config/glab-cli') | to_json }}
|
||||
],
|
||||
@@ -40,6 +41,7 @@
|
||||
"vmware.vscode-boot-dev-pack",
|
||||
"redhat.vscode-xml",
|
||||
"redhat.vscode-yaml",
|
||||
"saoudrizwan.claude-dev",
|
||||
"emmanuelbeziat.vscode-great-icons"
|
||||
],
|
||||
"settings": {
|
||||
|
||||
@@ -152,3 +152,12 @@
|
||||
|
||||
roles:
|
||||
- profile_workstation_dev_wsl
|
||||
|
||||
- name: Deploy project devcontainer generator
|
||||
hosts: platform_fedora
|
||||
become: true
|
||||
tags: [devcontainer_generator]
|
||||
|
||||
roles:
|
||||
- role: devcontainer_generator
|
||||
when: "'graphical_desktop' in group_names or 'workstation_dev_fedora' in group_names"
|
||||
|
||||
11
cmd/devcontainer/delta.Dockerfile
Normal file
11
cmd/devcontainer/delta.Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
RUN apt-get update \
|
||||
&& arch="$(dpkg --print-architecture)" \
|
||||
&& case "$arch" in \
|
||||
amd64) sha256=ea4f0222950ee750a3d38dd80d03bce4cee07a3f63928fc47548383bcaf23093 ;; \
|
||||
arm64) sha256=0edc36cf514f1bd84becac3e94ee8ae9f8818c6a1f99f7b2ee67b362afa253d3 ;; \
|
||||
*) echo "Unsupported architecture for delta: $arch" >&2; exit 1 ;; \
|
||||
esac \
|
||||
&& curl -fsSL --retry 3 "https://github.com/dandavison/delta/releases/download/0.19.2/git-delta_0.19.2_${arch}.deb" -o /tmp/git-delta.deb \
|
||||
&& echo "$sha256 /tmp/git-delta.deb" | sha256sum -c - \
|
||||
&& apt-get install -y --no-install-recommends /tmp/git-delta.deb \
|
||||
&& rm -rf /var/lib/apt/lists/* /tmp/git-delta.deb
|
||||
3
cmd/devcontainer/go.mod
Normal file
3
cmd/devcontainer/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module github.com/fscotto/infra/cmd/devcontainer
|
||||
|
||||
go 1.22
|
||||
351
cmd/devcontainer/main.go
Normal file
351
cmd/devcontainer/main.go
Normal file
@@ -0,0 +1,351 @@
|
||||
// Command devcontainer generates project configurations sharing host Git and agent state.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed delta.Dockerfile
|
||||
var deltaDockerfile string
|
||||
|
||||
type profile struct {
|
||||
Image, Packages string
|
||||
Extensions []string
|
||||
}
|
||||
type agent struct {
|
||||
Package string
|
||||
Extension string
|
||||
Paths []string
|
||||
}
|
||||
type mount struct {
|
||||
Type string `json:"type"`
|
||||
Source string `json:"source"`
|
||||
Target string `json:"target"`
|
||||
ReadOnly bool `json:"readOnly"`
|
||||
}
|
||||
|
||||
func exists(path string) bool { _, err := os.Stat(path); return err == nil }
|
||||
func isDir(path string) bool { info, err := os.Stat(path); return err == nil && info.IsDir() }
|
||||
func quote(s string) string { return "'" + strings.ReplaceAll(s, "'", "'\"'\"'") + "'" }
|
||||
func symlink(path string) bool {
|
||||
info, err := os.Lstat(path)
|
||||
return err == nil && info.Mode()&os.ModeSymlink != 0
|
||||
}
|
||||
|
||||
func selectAgents(selection, home string) ([]string, error) {
|
||||
result := []string{}
|
||||
candidates := strings.Split(selection, ",")
|
||||
if selection == "none" {
|
||||
return result, nil
|
||||
}
|
||||
if selection == "auto" {
|
||||
candidates = nil
|
||||
for name := range agents {
|
||||
candidates = append(candidates, name)
|
||||
}
|
||||
sort.Strings(candidates)
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for _, name := range candidates {
|
||||
name = strings.TrimSpace(name)
|
||||
a, ok := agents[name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unknown agent %q", name)
|
||||
}
|
||||
available := true
|
||||
for _, path := range a.Paths {
|
||||
if !isDir(filepath.Join(home, path)) {
|
||||
available = false
|
||||
}
|
||||
}
|
||||
if selection == "auto" && !available {
|
||||
continue
|
||||
}
|
||||
if !seen[name] {
|
||||
result = append(result, name)
|
||||
seen[name] = true
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func generate(project, language, home string, selected []string, local []string, force bool) (string, error) {
|
||||
p, ok := profiles[language]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unknown language %q", language)
|
||||
}
|
||||
project, err := filepath.Abs(project)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
project, err = filepath.EvalSymlinks(project)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
home, err = filepath.Abs(home)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
home, err = filepath.EvalSymlinks(home)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !isDir(project) {
|
||||
return "", fmt.Errorf("project directory does not exist: %s", project)
|
||||
}
|
||||
if home == "/" || strings.ContainsAny(home, "\n\r$,\\\"") {
|
||||
return "", errors.New("unsupported host home path")
|
||||
}
|
||||
target := filepath.Join(project, ".devcontainer")
|
||||
if symlink(target) {
|
||||
return "", errors.New("refusing a symlinked .devcontainer directory")
|
||||
}
|
||||
if exists(target) && !force {
|
||||
return "", errors.New(".devcontainer already exists; use --force to replace generated files")
|
||||
}
|
||||
paths := []struct {
|
||||
path string
|
||||
readonly bool
|
||||
}{{".gitconfig", true}, {".config/git", true}, {".gitignore_global", true}, {".config/ai", true}}
|
||||
claude := false
|
||||
for _, name := range selected {
|
||||
a, ok := agents[name]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unknown agent %q", name)
|
||||
}
|
||||
for _, path := range a.Paths {
|
||||
if !isDir(filepath.Join(home, path)) {
|
||||
return "", fmt.Errorf("missing host directory for %s: %s", name, filepath.Join(home, path))
|
||||
}
|
||||
paths = append(paths, struct {
|
||||
path string
|
||||
readonly bool
|
||||
}{path, false})
|
||||
}
|
||||
if name == "claude" {
|
||||
claude = true
|
||||
}
|
||||
}
|
||||
if claude {
|
||||
paths = append(paths, struct {
|
||||
path string
|
||||
readonly bool
|
||||
}{".claude.json", false})
|
||||
}
|
||||
mounts := []mount{}
|
||||
for _, item := range paths {
|
||||
if exists(filepath.Join(home, item.path)) {
|
||||
destination := filepath.Join(home, item.path)
|
||||
if item.path == ".gitconfig" {
|
||||
destination = "/run/host-gitconfig"
|
||||
}
|
||||
mounts = append(mounts, mount{"bind", "${localEnv:HOME}/" + item.path, destination, item.readonly})
|
||||
}
|
||||
}
|
||||
// The devcontainers node feature ships an nvm-based Node outside sudo's
|
||||
// secure_path, which broke the postCreateCommand npm install. Copy the
|
||||
// official Node image binaries into /usr/local instead, exactly like the
|
||||
// ecaas and cdp devcontainers, so sudo npm works in every profile.
|
||||
needsNode := len(selected) > 0
|
||||
dockerfile := ""
|
||||
if needsNode {
|
||||
dockerfile += "FROM docker.io/library/node:22-bookworm-slim AS node\n"
|
||||
}
|
||||
dockerfile += fmt.Sprintf("FROM %s\nUSER root\nRUN apt-get update && apt-get install -y --no-install-recommends \\\n bash-completion ca-certificates curl fzf git git-lfs gnupg openssh-client ripgrep zoxide %s \\\n && rm -rf /var/lib/apt/lists/*\n", p.Image, p.Packages)
|
||||
if needsNode {
|
||||
dockerfile += "COPY --from=node /usr/local/bin/node /usr/local/bin/node\n"
|
||||
dockerfile += "COPY --from=node /usr/local/lib/node_modules/npm/ /usr/local/lib/node_modules/npm/\n"
|
||||
dockerfile += "RUN ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \\\n && ln -s ../lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx \\\n && node --version && npm --version\n"
|
||||
}
|
||||
dockerfile += deltaDockerfile
|
||||
if home != "/home/vscode" {
|
||||
dockerfile += "RUN usermod --home " + quote(home) + " --move-home vscode\n"
|
||||
}
|
||||
// Docker ENV uses its own quoting syntax, rather than shell quoting.
|
||||
envHome, _ := json.Marshal(home)
|
||||
dockerfile += "ENV HOME=" + string(envHome) + "\n"
|
||||
if language == "python" {
|
||||
dockerfile += "RUN python -m pip install --no-cache-dir uv ruff ty\n"
|
||||
}
|
||||
if language == "infra" {
|
||||
dockerfile += "RUN python -m pip install --no-cache-dir ansible-core ansible-lint yamllint\n"
|
||||
}
|
||||
// The container installs the profile extensions, the VS Code extension of
|
||||
// every selected agent and the extensions currently installed in the local
|
||||
// VS Code, captured at generation time. Regenerate to refresh the local set.
|
||||
extensions := append([]string{}, p.Extensions...)
|
||||
addExtension := func(id string) {
|
||||
if !slices.ContainsFunc(extensions, func(e string) bool { return strings.EqualFold(e, id) }) {
|
||||
extensions = append(extensions, id)
|
||||
}
|
||||
}
|
||||
for _, name := range selected {
|
||||
if id := agents[name].Extension; id != "" {
|
||||
addExtension(id)
|
||||
}
|
||||
}
|
||||
for _, id := range local {
|
||||
addExtension(strings.TrimSpace(id))
|
||||
}
|
||||
slices.Sort(extensions)
|
||||
config := map[string]any{
|
||||
"name": filepath.Base(project) + " — " + language,
|
||||
"build": map[string]string{"dockerfile": "Dockerfile"},
|
||||
"remoteUser": "vscode", "updateRemoteUserUID": true,
|
||||
"containerEnv": map[string]string{"HOME": home}, "mounts": mounts,
|
||||
"customizations": map[string]any{"vscode": map[string]any{"extensions": extensions}},
|
||||
}
|
||||
if len(selected) > 0 {
|
||||
packages := []string{}
|
||||
for _, name := range selected {
|
||||
packages = append(packages, quote(agents[name].Package))
|
||||
}
|
||||
config["postCreateCommand"] = "sudo npm install --global --no-audit --no-fund " + strings.Join(packages, " ")
|
||||
}
|
||||
if claude {
|
||||
config["remoteEnv"] = map[string]string{"ANTHROPIC_AUTH_TOKEN": "${localEnv:ANTHROPIC_AUTH_TOKEN}"}
|
||||
}
|
||||
dockerfile += "USER vscode\n"
|
||||
if exists(filepath.Join(home, ".gitconfig")) {
|
||||
dockerfile += "RUN git config --global include.path /run/host-gitconfig\n"
|
||||
}
|
||||
var data bytes.Buffer
|
||||
encoder := json.NewEncoder(&data)
|
||||
encoder.SetEscapeHTML(false)
|
||||
encoder.SetIndent("", " ")
|
||||
if err := encoder.Encode(config); err != nil {
|
||||
return "", err
|
||||
}
|
||||
files := []struct{ name, content string }{{"Dockerfile", dockerfile}, {"devcontainer.json", data.String()}}
|
||||
// Validate every output before replacing any file.
|
||||
for _, file := range files {
|
||||
path := filepath.Join(target, file.name)
|
||||
if info, err := os.Lstat(path); err == nil {
|
||||
if !info.Mode().IsRegular() {
|
||||
return "", fmt.Errorf("refusing non-regular output: %s", path)
|
||||
}
|
||||
} else if !os.IsNotExist(err) {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
if err := os.MkdirAll(target, 0755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
for _, file := range files {
|
||||
if err := writeAtomic(filepath.Join(target, file.name), file.content); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return target, nil
|
||||
}
|
||||
|
||||
func writeAtomic(path, content string) error {
|
||||
file, err := os.CreateTemp(filepath.Dir(path), ".devcontainer-*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(file.Name())
|
||||
if _, err = io.WriteString(file, content); err != nil {
|
||||
file.Close()
|
||||
return err
|
||||
}
|
||||
if err = file.Chmod(0644); err != nil {
|
||||
file.Close()
|
||||
return err
|
||||
}
|
||||
if err = file.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Rename(file.Name(), path)
|
||||
}
|
||||
|
||||
// discoverLocalExtensions lists the extensions installed in the local VS Code.
|
||||
// A missing or failing code binary is not fatal: the generated container then
|
||||
// only carries the profile and agent extensions.
|
||||
func discoverLocalExtensions(stderr io.Writer) []string {
|
||||
path, err := exec.LookPath("code")
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, "note: no local VS Code found; skipping locally installed extensions")
|
||||
return nil
|
||||
}
|
||||
out, err := exec.Command(path, "--list-extensions").Output()
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "warning: could not list local VS Code extensions: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
extensions := []string{}
|
||||
for _, line := range strings.Split(string(out), "\n") {
|
||||
if id := strings.TrimSpace(line); id != "" {
|
||||
extensions = append(extensions, id)
|
||||
}
|
||||
}
|
||||
return extensions
|
||||
}
|
||||
|
||||
func run(args []string, home string, out, stderr io.Writer) error {
|
||||
flags := flag.NewFlagSet("devcontainer", flag.ContinueOnError)
|
||||
flags.SetOutput(stderr)
|
||||
language := flags.String("language", "", "c-cpp, go, rust, python, node, java, infra (required)")
|
||||
selection := flags.String("agents", "auto", "auto, none, or comma-separated codex,cline,opencode,claude,gemini")
|
||||
force := flags.Bool("force", false, "Replace the two generated files")
|
||||
flags.Usage = func() {
|
||||
fmt.Fprintln(stderr, "Usage: devcontainer PROJECT --language LANGUAGE [--agents AGENTS] [--force]")
|
||||
flags.PrintDefaults()
|
||||
}
|
||||
// Accept the project's original position before the flags as well as flags first.
|
||||
if len(args) > 0 && !strings.HasPrefix(args[0], "-") {
|
||||
args = append(append([]string{}, args[1:]...), args[0])
|
||||
}
|
||||
if err := flags.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
if flags.NArg() != 1 || *language == "" {
|
||||
flags.Usage()
|
||||
return errors.New("one project and --language are required")
|
||||
}
|
||||
selected, err := selectAgents(*selection, home)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
local := discoverLocalExtensions(stderr)
|
||||
target, err := generate(flags.Arg(0), *language, home, selected, local, *force)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
names := strings.Join(selected, ", ")
|
||||
if names == "" {
|
||||
names = "none"
|
||||
}
|
||||
fmt.Fprintf(out, "Created %s; agents: %s\n", target, names)
|
||||
if len(local) > 0 {
|
||||
fmt.Fprintf(out, "Included %d local VS Code extensions.\n", len(local))
|
||||
}
|
||||
fmt.Fprintln(out, "Open the project in VS Code and choose Dev Containers: Reopen in Container.")
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
home, err := os.UserHomeDir()
|
||||
if err == nil {
|
||||
err = run(os.Args[1:], home, os.Stdout, os.Stderr)
|
||||
}
|
||||
if errors.Is(err, flag.ErrHelp) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
281
cmd/devcontainer/main_test.go
Normal file
281
cmd/devcontainer/main_test.go
Normal file
@@ -0,0 +1,281 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func setup(t *testing.T) (string, string) {
|
||||
t.Helper()
|
||||
root := t.TempDir()
|
||||
home, project := filepath.Join(root, "host home"), filepath.Join(root, "project with spaces")
|
||||
for _, path := range []string{home, project} {
|
||||
if err := os.MkdirAll(path, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
return home, project
|
||||
}
|
||||
func read(t *testing.T, path string) string {
|
||||
t.Helper()
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
func put(t *testing.T, path, content string) {
|
||||
t.Helper()
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(path, []byte(content), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
type vscodeCustomizations struct {
|
||||
Customizations struct {
|
||||
Vscode struct {
|
||||
Extensions []string `json:"extensions"`
|
||||
} `json:"vscode"`
|
||||
} `json:"customizations"`
|
||||
}
|
||||
|
||||
func extensionsOf(t *testing.T, target string) []string {
|
||||
t.Helper()
|
||||
var config vscodeCustomizations
|
||||
if err := json.Unmarshal([]byte(read(t, filepath.Join(target, "devcontainer.json"))), &config); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return config.Customizations.Vscode.Extensions
|
||||
}
|
||||
|
||||
func TestProfiles(t *testing.T) {
|
||||
for name := range profiles {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
home, project := setup(t)
|
||||
target, err := generate(project, name, home, nil, nil, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var config map[string]any
|
||||
if err := json.Unmarshal([]byte(read(t, filepath.Join(target, "devcontainer.json"))), &config); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if config["containerEnv"].(map[string]any)["HOME"] != home {
|
||||
t.Fatal("wrong home")
|
||||
}
|
||||
if _, ok := config["postCreateCommand"]; ok {
|
||||
t.Fatal("unexpected agent install")
|
||||
}
|
||||
want := append([]string{}, profiles[name].Extensions...)
|
||||
slices.Sort(want)
|
||||
if got := extensionsOf(t, target); !slices.Equal(got, want) {
|
||||
t.Fatalf("wrong extensions: %v", got)
|
||||
}
|
||||
dockerfile := read(t, filepath.Join(target, "Dockerfile"))
|
||||
if !strings.HasPrefix(dockerfile, "FROM "+profiles[name].Image+"\n") || !strings.HasSuffix(dockerfile, "USER vscode\n") {
|
||||
t.Fatal("wrong Dockerfile")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
func TestSharedConfig(t *testing.T) {
|
||||
home, project := setup(t)
|
||||
put(t, filepath.Join(home, ".codex/auth.json"), "secret-value")
|
||||
put(t, filepath.Join(home, ".gitconfig"), "[user]\nname = Test\n")
|
||||
target, err := generate(project, "python", home, []string{"codex"}, nil, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
configText := read(t, filepath.Join(target, "devcontainer.json"))
|
||||
dockerfile := read(t, filepath.Join(target, "Dockerfile"))
|
||||
if strings.Contains(configText+dockerfile, "secret-value") {
|
||||
t.Fatal("credential leaked")
|
||||
}
|
||||
var config struct {
|
||||
Mounts []mount
|
||||
PostCreateCommand string
|
||||
}
|
||||
if err := json.Unmarshal([]byte(configText), &config); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foundGit, foundAgent := false, false
|
||||
for _, m := range config.Mounts {
|
||||
if m.Target == "/run/host-gitconfig" {
|
||||
foundGit = m.ReadOnly
|
||||
}
|
||||
if m.Target == filepath.Join(home, ".codex") {
|
||||
foundAgent = !m.ReadOnly
|
||||
}
|
||||
}
|
||||
if !foundGit || !foundAgent || !strings.Contains(dockerfile, "include.path /run/host-gitconfig") {
|
||||
t.Fatal("incorrect sharing")
|
||||
}
|
||||
if !strings.Contains(config.PostCreateCommand, "@openai/codex") || !strings.Contains(dockerfile, "COPY --from=node /usr/local/bin/node") {
|
||||
t.Fatal("missing CLI install or embedded Node")
|
||||
}
|
||||
if !slices.Contains(extensionsOf(t, target), "openai.chatgpt") {
|
||||
t.Fatal("agent VS Code extension missing")
|
||||
}
|
||||
}
|
||||
func TestAgentAndLocalExtensions(t *testing.T) {
|
||||
home, project := setup(t)
|
||||
put(t, filepath.Join(home, ".cline/state/config"), "")
|
||||
put(t, filepath.Join(home, ".agents/AGENTS.md"), "")
|
||||
local := []string{"github.remotehub", "SAOUDRIZWAN.claude-dev", "ms-vscode.cpptools"}
|
||||
target, err := generate(project, "python", home, []string{"cline"}, local, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []string{"ms-python.python", "charliermarsh.ruff", "saoudrizwan.claude-dev", "github.remotehub", "ms-vscode.cpptools"}
|
||||
slices.Sort(want)
|
||||
if got := extensionsOf(t, target); !slices.Equal(got, want) {
|
||||
t.Fatalf("extensions mismatch: %v", got)
|
||||
}
|
||||
}
|
||||
func TestAgentsShipNpmInsideSudoPath(t *testing.T) {
|
||||
for name := range profiles {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
home, project := setup(t)
|
||||
put(t, filepath.Join(home, ".cline/state/config"), "")
|
||||
put(t, filepath.Join(home, ".agents/AGENTS.md"), "")
|
||||
target, err := generate(project, name, home, []string{"cline"}, nil, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var config map[string]any
|
||||
if err := json.Unmarshal([]byte(read(t, filepath.Join(target, "devcontainer.json"))), &config); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, hasFeature := config["features"]; hasFeature {
|
||||
t.Fatal("the nvm-based node feature breaks the sudo npm postCreateCommand")
|
||||
}
|
||||
post, _ := config["postCreateCommand"].(string)
|
||||
if !strings.Contains(post, "sudo npm install") {
|
||||
t.Fatalf("missing npm agent install: %q", post)
|
||||
}
|
||||
dockerfile := read(t, filepath.Join(target, "Dockerfile"))
|
||||
if !strings.HasPrefix(dockerfile, "FROM docker.io/library/node:22-bookworm-slim AS node\n") ||
|
||||
!strings.Contains(dockerfile, "COPY --from=node /usr/local/bin/node /usr/local/bin/node") ||
|
||||
!strings.Contains(dockerfile, "ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm") {
|
||||
t.Fatal("npm must be reachable inside sudo's secure_path")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
func TestOverwriteAndSymlinks(t *testing.T) {
|
||||
home, project := setup(t)
|
||||
target, err := generate(project, "go", home, nil, nil, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before := read(t, filepath.Join(target, "Dockerfile"))
|
||||
if _, err := generate(project, "rust", home, nil, nil, false); err == nil {
|
||||
t.Fatal("overwrote existing configuration")
|
||||
}
|
||||
path := filepath.Join(target, "devcontainer.json")
|
||||
if err := os.Remove(path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
victim := filepath.Join(home, "victim")
|
||||
put(t, victim, "keep")
|
||||
if err := os.Symlink(victim, path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := generate(project, "rust", home, nil, nil, true); err == nil {
|
||||
t.Fatal("accepted symlink")
|
||||
}
|
||||
if read(t, victim) != "keep" || read(t, filepath.Join(target, "Dockerfile")) != before {
|
||||
t.Fatal("changed files before rejecting symlink")
|
||||
}
|
||||
}
|
||||
func TestInvalidInputs(t *testing.T) {
|
||||
for _, kind := range []string{"agent", "language", "missing-directory", "home", "target-symlink"} {
|
||||
t.Run(kind, func(t *testing.T) {
|
||||
home, project := setup(t)
|
||||
language := "go"
|
||||
var selected []string
|
||||
switch kind {
|
||||
case "agent":
|
||||
selected = []string{"codex"}
|
||||
case "language":
|
||||
language = "unknown"
|
||||
case "missing-directory":
|
||||
project = filepath.Join(project, "missing")
|
||||
case "home":
|
||||
home = "/"
|
||||
case "target-symlink":
|
||||
if err := os.Symlink(home, filepath.Join(project, ".devcontainer")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := generate(project, language, home, selected, nil, true); err == nil {
|
||||
t.Fatal("invalid input accepted")
|
||||
}
|
||||
if exists(filepath.Join(project, ".devcontainer/Dockerfile")) {
|
||||
t.Fatal("wrote invalid configuration")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
func TestAgentSelection(t *testing.T) {
|
||||
home, _ := setup(t)
|
||||
put(t, filepath.Join(home, ".codex/config.toml"), "")
|
||||
got, err := selectAgents("auto", home)
|
||||
if err != nil || strings.Join(got, ",") != "codex" {
|
||||
t.Fatalf("auto: %v %v", got, err)
|
||||
}
|
||||
got, err = selectAgents("codex,codex", home)
|
||||
if err != nil || len(got) != 1 {
|
||||
t.Fatal("duplicate agents")
|
||||
}
|
||||
if _, err := selectAgents("invalid", home); err == nil {
|
||||
t.Fatal("unknown agent accepted")
|
||||
}
|
||||
}
|
||||
func TestCLI(t *testing.T) {
|
||||
for _, first := range []bool{true, false} {
|
||||
t.Run(map[bool]string{true: "project-first", false: "flags-first"}[first], func(t *testing.T) {
|
||||
home, project := setup(t)
|
||||
args := []string{"--language", "go", "--agents", "none", project}
|
||||
if first {
|
||||
args = []string{project, "--language", "go", "--agents", "none"}
|
||||
}
|
||||
var out bytes.Buffer
|
||||
if err := run(args, home, &out, &out); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(out.String(), "agents: none") {
|
||||
t.Fatal("missing output")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
func TestLocalExtensionDiscovery(t *testing.T) {
|
||||
bin := t.TempDir()
|
||||
script := filepath.Join(bin, "code")
|
||||
if err := os.WriteFile(script, []byte("#!/bin/sh\necho a.b\necho c.d\n"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("PATH", bin+string(os.PathListSeparator)+os.Getenv("PATH"))
|
||||
home, project := setup(t)
|
||||
var out bytes.Buffer
|
||||
if err := run([]string{project, "--language", "go", "--agents", "none"}, home, &out, &out); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []string{"a.b", "c.d", "golang.go"}
|
||||
slices.Sort(want)
|
||||
if got := extensionsOf(t, filepath.Join(project, ".devcontainer")); !slices.Equal(got, want) {
|
||||
t.Fatalf("extensions mismatch: %v", got)
|
||||
}
|
||||
if !strings.Contains(out.String(), "Included 2 local VS Code extensions.") {
|
||||
t.Fatal("missing local extensions summary")
|
||||
}
|
||||
}
|
||||
18
cmd/devcontainer/profiles.go
Normal file
18
cmd/devcontainer/profiles.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
var profiles = map[string]profile{
|
||||
"c-cpp": {Image: "mcr.microsoft.com/devcontainers/base:bookworm", Packages: "build-essential clang clangd cmake gdb valgrind universal-ctags cscope", Extensions: []string{"ms-vscode.cpptools", "ms-vscode.cmake-tools"}},
|
||||
"go": {Image: "mcr.microsoft.com/devcontainers/go:1.25-bookworm", Packages: "", Extensions: []string{"golang.go"}},
|
||||
"rust": {Image: "mcr.microsoft.com/devcontainers/rust:1-bookworm", Packages: "", Extensions: []string{"rust-lang.rust-analyzer"}},
|
||||
"python": {Image: "mcr.microsoft.com/devcontainers/python:3.13-bookworm", Packages: "", Extensions: []string{"ms-python.python", "charliermarsh.ruff"}},
|
||||
"node": {Image: "mcr.microsoft.com/devcontainers/javascript-node:22-bookworm", Packages: "", Extensions: []string{"esbenp.prettier-vscode"}},
|
||||
"java": {Image: "mcr.microsoft.com/devcontainers/java:21-bookworm", Packages: "maven", Extensions: []string{"vscjava.vscode-java-pack"}},
|
||||
"infra": {Image: "mcr.microsoft.com/devcontainers/python:3.13-bookworm", Packages: "shellcheck shfmt", Extensions: []string{"redhat.ansible", "redhat.vscode-yaml"}},
|
||||
}
|
||||
var agents = map[string]agent{
|
||||
"codex": {Package: "@openai/codex", Extension: "openai.chatgpt", Paths: []string{".codex"}},
|
||||
"cline": {Package: "cline", Extension: "saoudrizwan.claude-dev", Paths: []string{".cline", ".agents"}},
|
||||
"opencode": {Package: "opencode-ai", Extension: "sst-dev.opencode", Paths: []string{".config/opencode", ".local/share/opencode", ".local/state/opencode"}},
|
||||
"claude": {Package: "@anthropic-ai/claude-code@2.1.312", Extension: "anthropic.claude-code", Paths: []string{".claude"}},
|
||||
"gemini": {Package: "@google/gemini-cli", Extension: "Google.geminicodeassist", Paths: []string{".gemini"}},
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
Same toolset and mounts as the [ecaas container](deadalus-ecaas-devcontainer.md)
|
||||
(Git configuration and GitLab CAs, Bash configuration, `~/.m2`, `~/.claude`,
|
||||
`~/.cline`, `~/.config/ai`, Docker outside of Docker, Claude Code, Cline, delta,
|
||||
Great Icons), with these differences:
|
||||
`~/.cline`, `~/.agents`, `~/.config/ai`, Docker outside of Docker, Claude Code,
|
||||
Cline, delta, Great Icons), with these differences:
|
||||
|
||||
- Java 25 (`mcr.microsoft.com/devcontainers/java:25-bookworm`) is the default JDK
|
||||
and also runs the Java and Spring language servers; there is no second JDK.
|
||||
|
||||
@@ -19,8 +19,8 @@ Do not use the production context to build or open the workspace.
|
||||
|
||||
The container uses Java 11 for the application and Maven, and Java 21 only for
|
||||
the Java and Spring language servers. VS Code installs the Java and Spring Boot
|
||||
extension packs, XML, YAML and the VSCode Great Icons theme (selected as the
|
||||
file icon theme) inside the container. The Java
|
||||
extension packs, XML, YAML, the Cline extension and the VSCode Great Icons theme
|
||||
(selected as the file icon theme) inside the container. The Java
|
||||
pack includes Maven, the Java debugger and test integration. Prefer the project's
|
||||
Maven wrapper where present. Node is provided for the Claude and Cline CLIs.
|
||||
|
||||
@@ -84,7 +84,13 @@ the container; changes made by `glab` inside affect the WSL configuration.
|
||||
|
||||
Claude and Cline use the WSL configuration directly: `~/.claude` and `~/.cline`
|
||||
are bind-mounted read-write at `/home/vscode/.claude` and `/home/vscode/.cline`,
|
||||
and `~/.config/ai` read-only at `/home/vscode/.config/ai`. Settings, rules,
|
||||
the cross-tool `~/.agents` read-only at `/home/vscode/.agents`, and
|
||||
`~/.config/ai` read-only at `/home/vscode/.config/ai`, so rules, the AGENTS
|
||||
pointer and the shared AI context follow the WSL host. The playbook keeps
|
||||
Cline's managed configuration deployed on the host (`cline_deploy_enabled:
|
||||
true`) even though the cline CLI npm package is not installed there; the CLI
|
||||
ships inside the image and the VS Code Cline extension is installed through
|
||||
the devcontainer customizations. Settings, rules,
|
||||
skills, MCP configuration, sessions and **credential stores** are therefore
|
||||
shared with, and visible to, the container, and changes made inside it affect
|
||||
the WSL home. Host paths and tools referenced by rules or skills may need
|
||||
|
||||
138
docs/project-devcontainers.md
Normal file
138
docs/project-devcontainers.md
Normal file
@@ -0,0 +1,138 @@
|
||||
# Reusable project devcontainers
|
||||
|
||||
`cmd/devcontainer/` is a Go CLI using only the standard library. Build it with
|
||||
Go 1.22 or newer, from an `infra` checkout:
|
||||
|
||||
```sh
|
||||
go -C cmd/devcontainer build -o "$HOME/.local/bin/devcontainer" .
|
||||
```
|
||||
|
||||
Create `~/.local/bin` first if needed and keep it on `PATH`. The resulting binary
|
||||
has no Python dependency. Run it on **the development host**, against an existing
|
||||
project:
|
||||
|
||||
```sh
|
||||
devcontainer ~/src/my-project --language go
|
||||
devcontainer ~/src/my-project --language python --agents codex,cline
|
||||
devcontainer ~/src/my-project --language c-cpp --agents none
|
||||
```
|
||||
|
||||
## Ansible deployment
|
||||
|
||||
On ikaros, nymph or deadalus, from the local `infra` checkout:
|
||||
|
||||
```sh
|
||||
ansible-playbook ansible/site.yml --limit ikaros --tags devcontainer_generator -K
|
||||
```
|
||||
|
||||
Replace the limit with `nymph` or `deadalus` as appropriate. The task installs
|
||||
Fedora's Go compiler, copies the sources into the user's build cache, compiles
|
||||
natively without downloading Go modules, and installs `~/.local/bin/devcontainer`
|
||||
with mode `0755`. Subsequent runs update the executable only when its contents
|
||||
change. Rebuilds use the Go cache. The role targets Fedora graphical desktops
|
||||
and Fedora development workstations; it does not start any containers.
|
||||
|
||||
Check mode validates packages and source deployment but skips compilation and
|
||||
binary installation, and reports that limitation explicitly:
|
||||
|
||||
```sh
|
||||
ansible-playbook ansible/site.yml --limit ikaros --tags devcontainer_generator --check --diff
|
||||
```
|
||||
|
||||
Profiles: `c-cpp`, `go`, `rust`, `python`, `node`, `java`, `infra`. They generate
|
||||
`.devcontainer/devcontainer.json` and `Dockerfile`. The generated
|
||||
`customizations.vscode.extensions` list combines the profile extensions, the VS
|
||||
Code extension of each selected agent (`cline` → `saoudrizwan.claude-dev`,
|
||||
`claude` → `anthropic.claude-code`, `codex` → `openai.chatgpt`, `gemini` →
|
||||
`Google.geminicodeassist`, `opencode` → `sst-dev.opencode`) and every extension
|
||||
installed in the local VS Code, captured through `code --list-extensions` at
|
||||
generation time; regenerate after installing or removing extensions on the
|
||||
host. Without a local VS Code on PATH only the profile and agent extensions are
|
||||
included. Open the project in local VS
|
||||
Code (in Fedora WSL on deadalus) and choose **Reopen in Container**. The generator
|
||||
never builds or starts a container, selects a Docker context, modifies application
|
||||
sources, or removes host packages. Existing `.devcontainer` directories are refused;
|
||||
`--force` replaces only the two generated files, so commit or back up edits first.
|
||||
|
||||
The definitions live centrally in the generator; generated files are standalone.
|
||||
Regenerate explicitly to take updates. Profile images select a language version
|
||||
or release family, not immutable digests; npm agents other than Claude currently
|
||||
resolve the latest release at container creation, matching the host lifecycle.
|
||||
Agent containers copy Node from the official `docker.io/library/node` image into
|
||||
`/usr/local` instead of using the nvm-based node feature, so the
|
||||
`sudo npm install` postCreateCommand works in every profile.
|
||||
Rebuilds are therefore not bit-for-bit reproducible. Pin image digests and agent
|
||||
versions in generated project files when a project requires that guarantee.
|
||||
Project-specific dependencies, ports, services and build commands belong in the
|
||||
project configuration. The `infra` profile provides Ansible and linters; install
|
||||
that project's collection requirements inside it separately.
|
||||
|
||||
## Shared Git and agents
|
||||
|
||||
Like the ecaas/cdp model, executables run inside the container and personal
|
||||
configuration stays on the host. The generator detects existing configuration
|
||||
paths without reading credentials. With `--agents auto` (the default), it selects
|
||||
agents whose configuration directories already exist. Explicit agent selection
|
||||
fails if required directories are missing. Supported agents: `codex`, `cline`,
|
||||
`opencode`, `claude`, `gemini`. IBM Bob and desktop applications are not included.
|
||||
|
||||
Host `~/.gitconfig` is mounted read-only at `/run/host-gitconfig` and included from
|
||||
a writable container Git config, allowing VS Code to register its credential
|
||||
helper. Existing `~/.config/git` and `~/.gitignore_global` are mounted read-only.
|
||||
Git, Git LFS, delta, OpenSSH and GnuPG are installed. VS Code Dev Containers handles
|
||||
SSH-agent and HTTPS credential-helper forwarding; start VS Code from the host
|
||||
session with its working agent. No SSH/GPG private-key directories are mounted.
|
||||
GPG signing needs a functioning agent-forwarding setup and a test with your key;
|
||||
the generator does not provision it. Host-specific helpers, `pinentry`, external
|
||||
Git includes, conditional includes and CA paths still need container-compatible
|
||||
configuration or additional narrowly scoped mounts. Recreate the container after
|
||||
replacing a bind-mounted configuration file atomically on the host.
|
||||
|
||||
`~/.config/ai` is mounted read-only when present. Selected agents mount their host
|
||||
configuration/state directories read-write, including credentials, sessions and
|
||||
rules; changes inside the container affect the host. OpenCode also shares its
|
||||
XDG data/state directories. The container user remains `vscode`, with its home set
|
||||
to the **same absolute path as the generating host**, so Codex's absolute
|
||||
`model_instructions_file` keeps working. This does not mount the full home.
|
||||
For a different host home path, regenerate there. Host-only programs referenced
|
||||
by agent settings are not made available automatically.
|
||||
|
||||
Claude also mounts `~/.claude.json` when present and forwards
|
||||
`ANTHROPIC_AUTH_TOKEN` using `${localEnv:ANTHROPIC_AUTH_TOKEN}` as on deadalus.
|
||||
Start VS Code from a shell that exports it; no token value is generated. Host
|
||||
keyring-backed logins require separate integration; sharing a directory does not
|
||||
forward the desktop keyring. VS Code extension storage is not shared.
|
||||
|
||||
Only existing paths are mounted. Regenerate after configuring an additional
|
||||
agent. Generated files use `${localEnv:HOME}` for mount sources and contain no
|
||||
credential contents, but do contain the host's absolute home path.
|
||||
|
||||
## Runtime and validation
|
||||
|
||||
Use a local development container engine. Docker CE is currently provisioned on
|
||||
deadalus; ikaros explicitly has Podman, while nymph's runtime needs verification.
|
||||
Podman (5+) works through VS Code's `dev.containers.dockerPath: podman` per the
|
||||
official Dev Containers documentation: the extension drives the container CLI
|
||||
and needs neither the `podman-docker` shim nor a daemon socket or `DOCKER_HOST`.
|
||||
Never install `podman-docker` where docker-ce provides the real Docker CLI
|
||||
(deadalus). Generation alone does not configure the engine; the `desktop_gnome`
|
||||
profile deploys `dev.containers.dockerPath: podman` with its managed VS Code
|
||||
settings, while compatible
|
||||
rootless/UID configuration and SELinux bind-mount access must be validated on the
|
||||
Fedora target host. Do not recursively relabel the personal home.
|
||||
No engine socket is mounted inside these containers by default; add access only
|
||||
for projects that need to launch sibling containers.
|
||||
|
||||
Host-side regression checks:
|
||||
|
||||
```sh
|
||||
go -C cmd/devcontainer test ./...
|
||||
go -C cmd/devcontainer vet ./...
|
||||
```
|
||||
|
||||
On the target host, build/open a generated project, check the language toolchain,
|
||||
`git config --show-origin --get user.email`, `git ls-remote origin HEAD` against
|
||||
the expected development remote, and each selected agent's version/login.
|
||||
Run project tests and verify signing if enabled. These runtime checks require the
|
||||
real host and are separate from generator tests. Existing ecaas/cdp Ansible
|
||||
provisioning is unchanged.
|
||||
@@ -5,6 +5,7 @@ Always follow:
|
||||
- preserve layering
|
||||
- avoid duplication
|
||||
- validate before applying changes
|
||||
- safety directives: always apply `~/.config/ai/rules/safety.md`
|
||||
|
||||
Task-specific file loading:
|
||||
- For general background on the user, the environment, and stable preferences, read `~/.config/ai/memory/chatgpt/knowledge/00-profilo.md`
|
||||
|
||||
@@ -10,3 +10,4 @@ Never break an existing host.
|
||||
## Git Rules
|
||||
|
||||
- Never auto-commit; always ask the user before committing
|
||||
- Never add your own or any other AI assistant's name as a Git co-author: no `Co-Authored-By: <agent>` trailers, no AI names among the authors. Commits are authored by the human operator only
|
||||
|
||||
Reference in New Issue
Block a user