Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
"nginx",
"node",
"playwright-deps",
"sonar-scanner-cli",
"timezone",
"vault-cli",
"zig"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Below is a list with included features, click on the link for more details.
| [nginx](./features/src/nginx/README.md) | A package which installs Nginx. |
| [node](./features/src/node/README.md) | A package which installs Node.js. |
| [playwright-deps](./features/src/playwright-deps/README.md) | A package which installs the needed dependencies to run Playwright. |
| [sonar-scanner-cli](./features/src/sonar-scanner-cli/README.md) | A package which installs the SonarScanner CLI. |
| [timezone](./features/src/timezone/README.md) | A package which allows setting the timezone. |
| [vault-cli](./features/src/vault-cli/README.md) | A feature which installs the Vault CLI. |
| [zig](./features/src/zig/README.md) | A feature which installs Zig. |
Expand Down
11 changes: 11 additions & 0 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ func init() {
return publishFeature("playwright-deps")
})

////////// sonar-scanner-cli
gotaskr.Task("Feature:sonar-scanner-cli:Package", func() error {
return packageFeature("sonar-scanner-cli")
})
gotaskr.Task("Feature:sonar-scanner-cli:Test", func() error {
return testFeature("sonar-scanner-cli")
})
gotaskr.Task("Feature:sonar-scanner-cli:Publish", func() error {
return publishFeature("sonar-scanner-cli")
})

////////// timezone
gotaskr.Task("Feature:timezone:Package", func() error {
return packageFeature("timezone")
Expand Down
11 changes: 11 additions & 0 deletions features/src/sonar-scanner-cli/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Notes

### System Compatibility

Debian, Ubuntu

### Accessed Urls

Needs access to the following URL for downloading and resolving:
* https://binaries.sonarsource.com
* https://github.com
35 changes: 35 additions & 0 deletions features/src/sonar-scanner-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# SonarScanner CLI (sonar-scanner-cli)

A package which installs the SonarScanner CLI.

## Example Usage

```json
"features": {
"ghcr.io/postfinance/devcontainer-features/sonar-scanner-cli:0.1.0": {
"version": "latest",
"includeJre": true,
"downloadUrl": ""
}
}
```

## Options

| Option | Description | Type | Default Value | Proposals |
|-----|-----|-----|-----|-----|
| version | The version of SonarScanner CLI to install. | string | latest | latest, 6, 6.2.1.4610 |
| includeJre | A flag to indicate if the jre should be included in the download, otherwise a JRE needs to be installed in other ways. | boolean | true | true, false |
| downloadUrl | The download URL to use for the binaries. | string | <empty> | https://mycompany.com/artifactory/sonarsource-generic-remote/Distribution/sonar-scanner-cli |

## Notes

### System Compatibility

Debian, Ubuntu

### Accessed Urls

Needs access to the following URL for downloading and resolving:
* https://binaries.sonarsource.com
* https://github.com
35 changes: 35 additions & 0 deletions features/src/sonar-scanner-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"id": "sonar-scanner-cli",
"version": "0.1.0",
"name": "SonarScanner CLI",
"description": "A package which installs the SonarScanner CLI.",
"options": {
"version": {
"type": "string",
"proposals": [
"latest",
"6",
"6.2.1.4610"
],
"default": "latest",
"description": "The version of SonarScanner CLI to install."
},
"includeJre": {
"type": "boolean",
"default": true,
"description": "A flag to indicate if the jre should be included in the download, otherwise a JRE needs to be installed in other ways."
},
"downloadUrl": {
"type": "string",
"default": "",
"proposals": [
"https://mycompany.com/artifactory/sonarsource-generic-remote/Distribution/sonar-scanner-cli"
],
"description": "The download URL to use for the binaries."
}
},
"containerEnv": {
"PATH": "/usr/local/sonar-scanner/bin:${PATH}",
"SONAR_HOME": "/usr/local/sonar-scanner"
}
}
5 changes: 5 additions & 0 deletions features/src/sonar-scanner-cli/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
. ./functions.sh

"./installer_$(detect_arch)" \
-version="${VERSION:-"latest"}" \
-includeJre="${INCLUDEJRE:-"true"}"
107 changes: 107 additions & 0 deletions features/src/sonar-scanner-cli/installer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package main

import (
"builder/installer"
"flag"
"fmt"
"os"
"regexp"

"github.com/roemer/gover"
)

//////////
// Configuration
//////////

var versionRegex *regexp.Regexp = regexp.MustCompile(`(?m:)^(\d+).(\d+)(?:.(\d+)(?:.(\d+))?)?(?:-(rc\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", "")
includeJre := flag.Bool("includeJre", true, "")
downloadUrl := flag.String("downloadUrl", "", "")
flag.Parse()

// Load settings from an external file (global/per-feature overrides)
if err := installer.LoadOverrides(); err != nil {
return err
}
// Handle overrides and defaults
installer.HandleOverride(downloadUrl, "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli", "sonar-scanner-cli-download-url")

// Create and process the feature
feature := installer.NewFeature("SonarScanner CLI", true,
&sonarscannerCliComponent{
ComponentBase: installer.NewComponentBase("SonarScanner CLI", *version),
IncludeJre: *includeJre,
DownloadUrl: *downloadUrl,
})
return feature.Process()
}

//////////
// Implementation
//////////

type sonarscannerCliComponent struct {
*installer.ComponentBase
IncludeJre bool
DownloadUrl string
}

func (c *sonarscannerCliComponent) IsFullVersion(referenceVersion *gover.Version) bool {
return len(referenceVersion.Segments) == 4 && referenceVersion.DefinedSegmentCount() == 4
}

func (c *sonarscannerCliComponent) GetAllVersions() ([]*gover.Version, error) {
allTags, err := installer.Tools.GitHub.GetTags("SonarSource", "sonar-scanner-cli")
if err != nil {
return nil, err
}
return installer.Tools.Versioning.ParseVersionsFromList(allTags, versionRegex, true)
}

func (c *sonarscannerCliComponent) InstallVersion(version *gover.Version) error {
// Download the file
archPart, err := installer.Tools.System.MapArchitecture(map[string]string{
installer.AMD64: "x64",
installer.ARM64: "aarch64",
})
if err != nil {
return err
}
var fileName string
if c.IncludeJre {
fileName = fmt.Sprintf("sonar-scanner-cli-%s-linux-%s.zip", version.Raw, archPart)
} else {
fileName = fmt.Sprintf("sonar-scanner-cli-%s.zip", version.Raw)
}
downloadUrl, err := installer.Tools.Http.BuildUrl(c.DownloadUrl, fileName)
if err != nil {
return err
}
if err := installer.Tools.Download.ToFile(downloadUrl, fileName, "Sonar"); err != nil {
return err
}
// Extract it
if err := installer.Tools.Compression.ExtractZip(fileName, "/usr/local/sonar-scanner", true); err != nil {
return err
}
// Cleanup
if err := os.Remove(fileName); err != nil {
return err
}
return nil
}
9 changes: 9 additions & 0 deletions features/test/sonar-scanner-cli/install-with-jre.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/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_command_exists "sonar-scanner"
check_dir_exists "/usr/local/sonar-scanner/jre"
check_version "$(sonar-scanner --version | sed -n 3p | cut -b 20-)" "SonarScanner CLI 6.2.1.4610"
9 changes: 9 additions & 0 deletions features/test/sonar-scanner-cli/install-without-jre.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/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_command_exists "sonar-scanner"
check_dir_not_exists "/usr/local/sonar-scanner/jre"
check_version "$(sonar-scanner --version | sed -n 3p | cut -b 20-)" "SonarScanner CLI 7.3.0.5189"
31 changes: 31 additions & 0 deletions features/test/sonar-scanner-cli/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"install-with-jre": {
"build": {
"dockerfile": "Dockerfile",
"options": [
"--add-host=host.docker.internal:host-gateway"
]
},
"features": {
"./sonar-scanner-cli": {
"version": "6.2.1.4610",
"includeJre": "true"
}
}
},
"install-without-jre": {
"build": {
"dockerfile": "Dockerfile",
"options": [
"--add-host=host.docker.internal:host-gateway"
]
},
"features": {
"ghcr.io/devcontainers/features/java:1": {},
"./sonar-scanner-cli": {
"version": "7.3.0.5189",
"includeJre": "false"
}
}
}
}
5 changes: 5 additions & 0 deletions features/test/sonar-scanner-cli/test-images.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"mcr.microsoft.com/devcontainers/base:debian-11",
"mcr.microsoft.com/devcontainers/base:debian-12",
"mcr.microsoft.com/devcontainers/base:ubuntu-24.04"
]