Skip to content

Commit d0a6ba2

Browse files
authored
fix(nvidia-cuda): simplify keyring installation (#36)
1 parent fd277d0 commit d0a6ba2

4 files changed

Lines changed: 29 additions & 9 deletions

File tree

‎features/src/nvidia-cuda/README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ A package which installs NVIDIA CUDA.
66

77
```json
88
"features": {
9-
"ghcr.io/postfinance/devcontainer-features/nvidia-cuda:0.1.0": {
9+
"ghcr.io/postfinance/devcontainer-features/nvidia-cuda:0.1.1": {
1010
"version": "latest",
11+
"keyringVersion": "1.1-1",
1112
"installLibraries": true,
1213
"installDevLibraries": true,
1314
"installCompiler": true,
@@ -23,6 +24,7 @@ A package which installs NVIDIA CUDA.
2324
| Option | Description | Type | Default Value | Proposals |
2425
|-----|-----|-----|-----|-----|
2526
| version | The version of NVIDIA CUDA to install. | string | latest | latest, 12.9, 13.1 |
27+
| keyringVersion | The version of the NVIDIA CUDA keyring to install. | string | 1.1-1 | latest, 1.1-1 |
2628
| installLibraries | Installs all runtime CUDA Library packages. | boolean | true | true, false |
2729
| installDevLibraries | Installs all development CUDA Library packages. | boolean | true | true, false |
2830
| installCompiler | Installs all CUDA compiler packages. | boolean | true | true, false |

‎features/src/nvidia-cuda/devcontainer-feature.json‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "nvidia-cuda",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"name": "NVIDIA CUDA",
55
"description": "A package which installs NVIDIA CUDA.",
66
"options": {
@@ -14,6 +14,15 @@
1414
"default": "latest",
1515
"description": "The version of NVIDIA CUDA to install."
1616
},
17+
"keyringVersion": {
18+
"type": "string",
19+
"proposals": [
20+
"latest",
21+
"1.1-1"
22+
],
23+
"default": "1.1-1",
24+
"description": "The version of the NVIDIA CUDA keyring to install."
25+
},
1726
"installLibraries": {
1827
"type": "boolean",
1928
"default": true,

‎features/src/nvidia-cuda/install.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
"./installer_$(detect_arch)" \
44
-version="${VERSION:-"latest"}" \
5+
-keyringVersion="${KEYRINGVERSION:-""}" \
56
-installLibraries="${INSTALLLIBRARIES:-"true"}" \
67
-installDevLibraries="${INSTALLDEVLIBRARIES:-"true"}" \
78
-installCompiler="${INSTALLCOMPILER:-"true"}" \

‎features/src/nvidia-cuda/installer.go‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import (
1515
"github.com/roemer/gover"
1616
)
1717

18+
//////////
19+
// Configuration
20+
//////////
21+
22+
const nvidiaDownloadBaseURL = "https://developer.download.nvidia.com"
23+
1824
//////////
1925
// Main
2026
//////////
@@ -29,6 +35,7 @@ func main() {
2935
func runMain() error {
3036
// Handle the flags
3137
version := flag.String("version", "latest", "")
38+
keyringVersion := flag.String("keyringVersion", "", "")
3239
installLibraries := flag.Bool("installLibraries", true, "")
3340
installDevLibraries := flag.Bool("installDevLibraries", true, "")
3441
installCompiler := flag.Bool("installCompiler", true, "")
@@ -42,12 +49,12 @@ func runMain() error {
4249
return err
4350
}
4451

45-
installer.HandleOverride(downloadUrl, "https://developer.download.nvidia.com", "nvidia-cuda-download-url")
52+
installer.HandleOverride(downloadUrl, nvidiaDownloadBaseURL, "nvidia-cuda-download-url")
4653

4754
// Create and process the feature
4855
feature := installer.NewFeature("NVIDIA CUDA", false,
4956
&cudaKeyringComponent{
50-
ComponentBase: installer.NewComponentBase("Keyring", installer.VERSION_LATEST),
57+
ComponentBase: installer.NewComponentBase("Keyring", *keyringVersion),
5158
DownloadUrl: *downloadUrl,
5259
},
5360
)
@@ -96,7 +103,7 @@ type cudaKeyringComponent struct {
96103
DownloadUrl string
97104
}
98105

99-
func (c *cudaKeyringComponent) getCudaRepo() (string, error) {
106+
func (c *cudaKeyringComponent) getCudaRepo(baseUrl string) (string, error) {
100107
osInfo, err := installer.Tools.System.GetOsInfo()
101108
if err != nil {
102109
return "", err
@@ -114,19 +121,20 @@ func (c *cudaKeyringComponent) getCudaRepo() (string, error) {
114121
if archPart == "arm64" {
115122
return "", fmt.Errorf("No CUDA binaries are available for ARM64")
116123
}
117-
return fmt.Sprintf("%s/compute/cuda/repos/%s%d/%s/", c.DownloadUrl, osInfo.Vendor, osInfo.MajorVersion(), archPart), nil
124+
return fmt.Sprintf("%s/compute/cuda/repos/%s%d/%s/", baseUrl, osInfo.Vendor, osInfo.MajorVersion(), archPart), nil
118125
}
119126
if osInfo.IsUbuntu() {
120-
return fmt.Sprintf("%s/compute/cuda/repos/%s%s/%s/", c.DownloadUrl, osInfo.Vendor, strings.ReplaceAll(osInfo.VersionId, ".", ""), archPart), nil
127+
return fmt.Sprintf("%s/compute/cuda/repos/%s%s/%s/", baseUrl, osInfo.Vendor, strings.ReplaceAll(osInfo.VersionId, ".", ""), archPart), nil
121128
}
122129
return "", fmt.Errorf("unsupported OS: %s", osInfo.Vendor)
123130
}
124131

125132
func (c *cudaKeyringComponent) GetAllVersions() ([]*gover.Version, error) {
126-
indexUrl, err := c.getCudaRepo()
133+
cudaRepo, err := c.getCudaRepo(nvidiaDownloadBaseURL)
127134
if err != nil {
128135
return nil, err
129136
}
137+
indexUrl := fmt.Sprintf("%s%s", cudaRepo, "index.html")
130138

131139
allVersions, err := installer.Tools.Http.GetVersionsFromHtmlIndex(
132140
indexUrl,
@@ -140,7 +148,7 @@ func (c *cudaKeyringComponent) GetAllVersions() ([]*gover.Version, error) {
140148

141149
func (c *cudaKeyringComponent) InstallVersion(version *gover.Version) error {
142150
// Download the file
143-
cudaRepo, err := c.getCudaRepo()
151+
cudaRepo, err := c.getCudaRepo(c.DownloadUrl)
144152
if err != nil {
145153
return err
146154
}

0 commit comments

Comments
 (0)