Skip to content

Commit e8c7b67

Browse files
committed
Add claude-code devcontainer feature
1 parent 26783a9 commit e8c7b67

12 files changed

Lines changed: 238 additions & 0 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
feature: [
2626
"browsers",
2727
"build-essential",
28+
"claude-code",
2829
"cypress-deps",
2930
"docker-out",
3031
"dotnet",

‎README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Below is a list with included features, click on the link for more details.
1717
| --- | --- |
1818
| [browsers](./features/src/browsers/README.md) | Installs various browsers and their dependencies. |
1919
| [build-essential](./features/src/build-essential/README.md) | Installs build essentials like gcc. |
20+
| [claude-code](./features/src/claude-code/README.md) | Installs Claude Code, Anthropic's AI coding assistant CLI. |
2021
| [cypress-deps](./features/src/cypress-deps/README.md) | Installs all dependencies required to run Cypress. |
2122
| [docker-out](./features/src/docker-out/README.md) | Installs a Docker client which re-uses the host Docker socket. |
2223
| [dotnet](./features/src/dotnet/README.md) | A package which installs .NET SDKs, runtimes and workloads. |
@@ -142,3 +143,10 @@ and then run the installer:
142143
```bash
143144
/data/kubectl.bin --version=1.35.0
144145
```
146+
147+
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 {}`).
148+
149+
Here is a one-liner that prepares the defined feature in this project:
150+
```bash
151+
FEATURE="go"; go run "./build" --target "Feature:$FEATURE:Package"; mkdir -p ".devcontainer/$FEATURE"; tar -xvf "output/devcontainer-feature-$FEATURE.tgz" -C ".devcontainer/$FEATURE"
152+
```

‎build/build.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ func init() {
8686
gotaskr.Task("Feature:browsers:Package", func() error { return packageFeature("browsers") })
8787
gotaskr.Task("Feature:browsers:Test", func() error { return testFeature("browsers") })
8888

89+
////////// claude-code
90+
gotaskr.Task("Feature:claude-code:Package", func() error { return packageFeature("claude-code") })
91+
gotaskr.Task("Feature:claude-code:Test", func() error { return testFeature("claude-code") })
92+
8993
////////// build-essential
9094
gotaskr.Task("Feature:build-essential:Package", func() error { return packageFeature("build-essential") })
9195
gotaskr.Task("Feature:build-essential:Test", func() error { return testFeature("build-essential") })

‎features/src/claude-code/NOTES.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Notes
2+
3+
### System Compatibility
4+
5+
Debian, Ubuntu, Alpine
6+
7+
### Accessed Urls
8+
9+
Needs access to the following URL for downloading:
10+
* https://github.com
11+
12+
Needs access to the following URL for resolving:
13+
* https://api.github.com

‎features/src/claude-code/README.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# claude-code (claude-code)
2+
3+
Installs Claude Code, Anthropic's AI coding assistant CLI.
4+
5+
## Example Usage
6+
7+
```json
8+
"features": {
9+
"ghcr.io/postfinance/devcontainer-features/claude-code:1.0.0": {
10+
"version": "latest",
11+
"downloadUrl": ""
12+
}
13+
}
14+
```
15+
16+
## Options
17+
18+
| Option | Description | Type | Default Value | Proposals |
19+
|-----|-----|-----|-----|-----|
20+
| version | The version of Claude Code to install. | string | latest | latest, 2.1.123 |
21+
| downloadUrl | The download URL to use for Claude Code binaries. | string | <empty> | https://mycompany.com/artifactory/github-releases-remote |
22+
23+
## Notes
24+
25+
### System Compatibility
26+
27+
Debian, Ubuntu, Alpine
28+
29+
### Accessed Urls
30+
31+
Needs access to the following URL for downloading:
32+
* https://github.com
33+
34+
Needs access to the following URL for resolving:
35+
* https://api.github.com
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"id": "claude-code",
3+
"version": "1.0.0",
4+
"name": "claude-code",
5+
"description": "Installs Claude Code, Anthropic's AI coding assistant CLI.",
6+
"options": {
7+
"version": {
8+
"type": "string",
9+
"proposals": [
10+
"latest",
11+
"2.1.123"
12+
],
13+
"default": "latest",
14+
"description": "The version of Claude Code to install."
15+
},
16+
"downloadUrl": {
17+
"type": "string",
18+
"default": "",
19+
"proposals": [
20+
"https://mycompany.com/artifactory/github-releases-remote"
21+
],
22+
"description": "The download URL to use for Claude Code binaries."
23+
}
24+
}
25+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
. ./functions.sh
2+
3+
"./installer_$(detect_arch)" \
4+
-version="${VERSION:-"latest"}" \
5+
-downloadUrl="${DOWNLOADURL:-""}"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package main
2+
3+
import (
4+
"builder/installer"
5+
"flag"
6+
"fmt"
7+
"os"
8+
"path/filepath"
9+
"regexp"
10+
11+
"github.com/roemer/gover"
12+
)
13+
14+
//////////
15+
// Configuration
16+
//////////
17+
18+
var versionRegex *regexp.Regexp = regexp.MustCompile(`(?m)^v(?P<raw>(\d+)\.(\d+)\.(\d+))$`)
19+
20+
//////////
21+
// Main
22+
//////////
23+
24+
func main() {
25+
if err := runMain(); err != nil {
26+
fmt.Printf("Error: %v\n", err)
27+
os.Exit(1)
28+
}
29+
}
30+
31+
func runMain() error {
32+
// Handle the flags
33+
version := flag.String("version", "latest", "")
34+
downloadUrl := flag.String("downloadUrl", "", "")
35+
flag.Parse()
36+
37+
// Load settings from an external file
38+
if err := installer.LoadOverrides(); err != nil {
39+
return err
40+
}
41+
42+
// Apply override logic for URLs
43+
installer.HandleGitHubOverride(downloadUrl, "anthropics/claude-code", "claude-code-download-url")
44+
45+
// Create and process the feature
46+
feature := installer.NewFeature("claude-code", false,
47+
&claudeCodeComponent{
48+
ComponentBase: installer.NewComponentBase("claude-code", *version),
49+
DownloadUrl: *downloadUrl,
50+
})
51+
return feature.Process()
52+
}
53+
54+
//////////
55+
// Implementation
56+
//////////
57+
58+
type claudeCodeComponent struct {
59+
*installer.ComponentBase
60+
DownloadUrl string
61+
}
62+
63+
func (c *claudeCodeComponent) GetAllVersions() ([]*gover.Version, error) {
64+
tags, err := installer.Tools.GitHub.GetTags("anthropics", "claude-code")
65+
if err != nil {
66+
return nil, err
67+
}
68+
return installer.Tools.Versioning.ParseVersionsFromList(tags, versionRegex, true)
69+
}
70+
71+
func (c *claudeCodeComponent) InstallVersion(version *gover.Version) error {
72+
archPart, err := installer.Tools.System.MapArchitecture(map[string]string{
73+
installer.AMD64: "x64",
74+
installer.ARM64: "arm64",
75+
})
76+
if err != nil {
77+
return err
78+
}
79+
80+
// Use musl variant for Alpine (musl libc)
81+
osInfo, err := installer.Tools.System.GetOsInfo()
82+
if err != nil {
83+
return err
84+
}
85+
var fileName string
86+
if osInfo.IsAlpine() {
87+
fileName = fmt.Sprintf("claude-linux-%s-musl.tar.gz", archPart)
88+
} else {
89+
fileName = fmt.Sprintf("claude-linux-%s.tar.gz", archPart)
90+
}
91+
92+
// Download the file from GitHub releases
93+
downloadUrl, err := installer.Tools.Http.BuildUrl(c.DownloadUrl, "v"+version.Raw, fileName)
94+
if err != nil {
95+
return err
96+
}
97+
if err := installer.Tools.Download.ToFile(downloadUrl, fileName, "claude-code"); err != nil {
98+
return err
99+
}
100+
defer os.Remove(fileName)
101+
102+
// Extract to a temp directory
103+
tempDir, err := os.MkdirTemp("", "claude-code-extract")
104+
if err != nil {
105+
return err
106+
}
107+
defer os.RemoveAll(tempDir)
108+
109+
if err := installer.Tools.Compression.ExtractTarGz(fileName, tempDir, false); err != nil {
110+
return err
111+
}
112+
113+
// Install the binary
114+
return installer.Tools.System.InstallBinaryToUsrLocalBin(filepath.Join(tempDir, "claude"), "claude")
115+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -e
3+
4+
[[ -f "$(dirname "$0")/../functions.sh" ]] && source "$(dirname "$0")/../functions.sh"
5+
[[ -f "$(dirname "$0")/functions.sh" ]] && source "$(dirname "$0")/functions.sh"
6+
7+
check_file_exists "/usr/local/bin/claude"
8+
check_version "$(claude --version)" "2.1.123"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"install": {
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"options": [
6+
"--add-host=host.docker.internal:host-gateway"
7+
]
8+
},
9+
"features": {
10+
"./claude-code": {
11+
"version": "2.1.123"
12+
}
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)