diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf25336..801c6a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,7 @@ jobs: feature: [ "browsers", "build-essential", + "claude-code", "cypress-deps", "docker-out", "dotnet", diff --git a/README.md b/README.md index d5fd14a..2774328 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Below is a list with included features, click on the link for more details. | --- | --- | | [browsers](./features/src/browsers/README.md) | Installs various browsers and their dependencies. | | [build-essential](./features/src/build-essential/README.md) | Installs build essentials like gcc. | +| [claude-code](./features/src/claude-code/README.md) | Installs Claude Code, Anthropic's AI coding assistant CLI. | | [cypress-deps](./features/src/cypress-deps/README.md) | Installs all dependencies required to run Cypress. | | [docker-out](./features/src/docker-out/README.md) | Installs a Docker client which re-uses the host Docker socket. | | [dotnet](./features/src/dotnet/README.md) | A package which installs .NET SDKs, runtimes and workloads. | @@ -142,3 +143,10 @@ and then run the installer: ```bash /data/kubectl.bin --version=1.35.0 ``` + +Alternatively, you can just pack a feature (use the tasks from `build/build.go`) and simply extract it into a `.devcontainer` folder and then use it from there as a local feature (`.my-feature {}`). + +Here is a one-liner that prepares the defined feature in this project: +```bash +FEATURE="go"; go run "./build" --target "Feature:$FEATURE:Package"; mkdir -p ".devcontainer/$FEATURE"; tar -xvf "output/devcontainer-feature-$FEATURE.tgz" -C ".devcontainer/$FEATURE" +``` diff --git a/build/build.go b/build/build.go index 05f99c6..2edf26e 100644 --- a/build/build.go +++ b/build/build.go @@ -86,6 +86,10 @@ func init() { gotaskr.Task("Feature:browsers:Package", func() error { return packageFeature("browsers") }) gotaskr.Task("Feature:browsers:Test", func() error { return testFeature("browsers") }) + ////////// claude-code + gotaskr.Task("Feature:claude-code:Package", func() error { return packageFeature("claude-code") }) + gotaskr.Task("Feature:claude-code:Test", func() error { return testFeature("claude-code") }) + ////////// build-essential gotaskr.Task("Feature:build-essential:Package", func() error { return packageFeature("build-essential") }) gotaskr.Task("Feature:build-essential:Test", func() error { return testFeature("build-essential") }) diff --git a/features/src/claude-code/NOTES.md b/features/src/claude-code/NOTES.md new file mode 100644 index 0000000..30988a2 --- /dev/null +++ b/features/src/claude-code/NOTES.md @@ -0,0 +1,13 @@ +## Notes + +### System Compatibility + +Debian, Ubuntu, Alpine + +### Accessed Urls + +Needs access to the following URL for downloading: +* https://github.com + +Needs access to the following URL for resolving: +* https://api.github.com diff --git a/features/src/claude-code/README.md b/features/src/claude-code/README.md new file mode 100644 index 0000000..d48c51c --- /dev/null +++ b/features/src/claude-code/README.md @@ -0,0 +1,35 @@ +# claude-code (claude-code) + +Installs Claude Code, Anthropic's AI coding assistant CLI. + +## Example Usage + +```json +"features": { + "ghcr.io/postfinance/devcontainer-features/claude-code:1.0.0": { + "version": "latest", + "downloadUrl": "" + } +} +``` + +## Options + +| Option | Description | Type | Default Value | Proposals | +|-----|-----|-----|-----|-----| +| version | The version of Claude Code to install. | string | latest | latest, 2.1.123 | +| downloadUrl | The download URL to use for Claude Code binaries. | string | <empty> | https://mycompany.com/artifactory/github-releases-remote | + +## Notes + +### System Compatibility + +Debian, Ubuntu, Alpine + +### Accessed Urls + +Needs access to the following URL for downloading: +* https://github.com + +Needs access to the following URL for resolving: +* https://api.github.com diff --git a/features/src/claude-code/devcontainer-feature.json b/features/src/claude-code/devcontainer-feature.json new file mode 100644 index 0000000..5f2c136 --- /dev/null +++ b/features/src/claude-code/devcontainer-feature.json @@ -0,0 +1,25 @@ +{ + "id": "claude-code", + "version": "1.0.0", + "name": "claude-code", + "description": "Installs Claude Code, Anthropic's AI coding assistant CLI.", + "options": { + "version": { + "type": "string", + "proposals": [ + "latest", + "2.1.123" + ], + "default": "latest", + "description": "The version of Claude Code to install." + }, + "downloadUrl": { + "type": "string", + "default": "", + "proposals": [ + "https://mycompany.com/artifactory/github-releases-remote" + ], + "description": "The download URL to use for Claude Code binaries." + } + } +} diff --git a/features/src/claude-code/install.sh b/features/src/claude-code/install.sh new file mode 100755 index 0000000..13b2b54 --- /dev/null +++ b/features/src/claude-code/install.sh @@ -0,0 +1,5 @@ +. ./functions.sh + +"./installer_$(detect_arch)" \ + -version="${VERSION:-"latest"}" \ + -downloadUrl="${DOWNLOADURL:-""}" diff --git a/features/src/claude-code/installer.go b/features/src/claude-code/installer.go new file mode 100644 index 0000000..da5f467 --- /dev/null +++ b/features/src/claude-code/installer.go @@ -0,0 +1,115 @@ +package main + +import ( + "builder/installer" + "flag" + "fmt" + "os" + "path/filepath" + "regexp" + + "github.com/roemer/gover" +) + +////////// +// Configuration +////////// + +var versionRegex *regexp.Regexp = regexp.MustCompile(`(?m)^v(?P(\d+)\.(\d+)\.(\d+))$`) + +////////// +// Main +////////// + +func main() { + if err := runMain(); err != nil { + fmt.Printf("Error: %v\n", err) + os.Exit(1) + } +} + +func runMain() error { + // Handle the flags + version := flag.String("version", "latest", "") + downloadUrl := flag.String("downloadUrl", "", "") + flag.Parse() + + // Load settings from an external file + if err := installer.LoadOverrides(); err != nil { + return err + } + + // Apply override logic for URLs + installer.HandleGitHubOverride(downloadUrl, "anthropics/claude-code", "claude-code-download-url") + + // Create and process the feature + feature := installer.NewFeature("claude-code", false, + &claudeCodeComponent{ + ComponentBase: installer.NewComponentBase("claude-code", *version), + DownloadUrl: *downloadUrl, + }) + return feature.Process() +} + +////////// +// Implementation +////////// + +type claudeCodeComponent struct { + *installer.ComponentBase + DownloadUrl string +} + +func (c *claudeCodeComponent) GetAllVersions() ([]*gover.Version, error) { + tags, err := installer.Tools.GitHub.GetTags("anthropics", "claude-code") + if err != nil { + return nil, err + } + return installer.Tools.Versioning.ParseVersionsFromList(tags, versionRegex, true) +} + +func (c *claudeCodeComponent) InstallVersion(version *gover.Version) error { + archPart, err := installer.Tools.System.MapArchitecture(map[string]string{ + installer.AMD64: "x64", + installer.ARM64: "arm64", + }) + if err != nil { + return err + } + + // Use musl variant for Alpine (musl libc) + osInfo, err := installer.Tools.System.GetOsInfo() + if err != nil { + return err + } + var fileName string + if osInfo.IsAlpine() { + fileName = fmt.Sprintf("claude-linux-%s-musl.tar.gz", archPart) + } else { + fileName = fmt.Sprintf("claude-linux-%s.tar.gz", archPart) + } + + // Download the file from GitHub releases + downloadUrl, err := installer.Tools.Http.BuildUrl(c.DownloadUrl, "v"+version.Raw, fileName) + if err != nil { + return err + } + if err := installer.Tools.Download.ToFile(downloadUrl, fileName, "claude-code"); err != nil { + return err + } + defer os.Remove(fileName) + + // Extract to a temp directory + tempDir, err := os.MkdirTemp("", "claude-code-extract") + if err != nil { + return err + } + defer os.RemoveAll(tempDir) + + if err := installer.Tools.Compression.ExtractTarGz(fileName, tempDir, false); err != nil { + return err + } + + // Install the binary + return installer.Tools.System.InstallBinaryToUsrLocalBin(filepath.Join(tempDir, "claude"), "claude") +} diff --git a/features/test/claude-code/install.sh b/features/test/claude-code/install.sh new file mode 100755 index 0000000..2c61fbf --- /dev/null +++ b/features/test/claude-code/install.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +[[ -f "$(dirname "$0")/../functions.sh" ]] && source "$(dirname "$0")/../functions.sh" +[[ -f "$(dirname "$0")/functions.sh" ]] && source "$(dirname "$0")/functions.sh" + +check_file_exists "/usr/local/bin/claude" +check_version "$(claude --version)" "2.1.123" diff --git a/features/test/claude-code/scenarios.json b/features/test/claude-code/scenarios.json new file mode 100644 index 0000000..f76f864 --- /dev/null +++ b/features/test/claude-code/scenarios.json @@ -0,0 +1,15 @@ +{ + "install": { + "build": { + "dockerfile": "Dockerfile", + "options": [ + "--add-host=host.docker.internal:host-gateway" + ] + }, + "features": { + "./claude-code": { + "version": "2.1.123" + } + } + } +} diff --git a/features/test/claude-code/test-images.json b/features/test/claude-code/test-images.json new file mode 100644 index 0000000..42119c9 --- /dev/null +++ b/features/test/claude-code/test-images.json @@ -0,0 +1,6 @@ +[ + "mcr.microsoft.com/devcontainers/base:debian-11", + "mcr.microsoft.com/devcontainers/base:debian-12", + "mcr.microsoft.com/devcontainers/base:alpine", + "mcr.microsoft.com/devcontainers/base:ubuntu-24.04" +] diff --git a/override-all.env b/override-all.env index b1c2c21..2cfb281 100644 --- a/override-all.env +++ b/override-all.env @@ -66,6 +66,9 @@ KUBECTL_KUBESCORE_DOWNLOAD_URL="" # nginx NGINX_DOWNLOAD_URL="" +# claude-code +CLAUDE_CODE_DOWNLOAD_URL="" + # opencode OPENCODE_DOWNLOAD_URL=""