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 @@ -16,6 +16,7 @@ jobs:
matrix:
feature: [
"browsers",
"build-essential",
"docker-out",
"git-lfs",
"go",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Below is a list with included features, click on the link for more details.
| Name | Description |
| --- | --- |
| [browsers](./features/src/browsers/README.md) | A package which installs various browsers. |
| [build-essential](./features/src/build-essential/README.md) | Installs essential build tools (e.g., gcc, g++, make, libc-dev) for compiling C/C++ and |
| [docker-out](./features/src/docker-out/README.md) | A feature which installs the Docker client and re-uses the host socket. |
| [git-lfs](./features/src/git-lfs/README.md) | A feature which installs Git LFS. |
| [go](./features/src/go/README.md) | A feature which installs Go. |
Expand Down
12 changes: 12 additions & 0 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

var featureList = []string{
"browsers",
"build-essential",
"docker-out",
"git-lfs",
"go",
Expand Down Expand Up @@ -62,6 +63,17 @@ func init() {
return publishFeature("browsers")
})

////////// 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")
})
gotaskr.Task("Feature:build-essential:Publish", func() error {
return publishFeature("build-essential")
})

////////// docker-out
gotaskr.Task("Feature:docker-out:Package", func() error {
return packageFeature("docker-out")
Expand Down
5 changes: 5 additions & 0 deletions features/src/build-essential/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Notes

### System Compatibility

Debian, Ubuntu
25 changes: 25 additions & 0 deletions features/src/build-essential/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Build Essential (build-essential)

A package which installs build essentials like gcc.

## Example Usage

```json
"features": {
"ghcr.io/postfinance/devcontainer-features/build-essential:0.1.0": {
"version": "latest"
}
}
```

## Options

| Option | Description | Type | Default Value | Proposals |
|-----|-----|-----|-----|-----|
| version | The version of the build essential package to install. | string | latest | latest, 12.9 |

## Notes

### System Compatibility

Debian, Ubuntu
17 changes: 17 additions & 0 deletions features/src/build-essential/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"id": "build-essential",
"version": "0.1.0",
"name": "Build Essential",
"description": "A package which installs build essentials like gcc.",
"options": {
"version": {
"type": "string",
"proposals": [
"latest",
"12.9"
],
"default": "latest",
"description": "The version of the build essential package to install."
}
}
}
4 changes: 4 additions & 0 deletions features/src/build-essential/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
. ./functions.sh

"./installer_$(detect_arch)" \
-version="${VERSION:-"latest"}"
85 changes: 85 additions & 0 deletions features/src/build-essential/installer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package main

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

"github.com/roemer/gotaskr/execr"
"github.com/roemer/gover"
)

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

const packageName = "build-essential"

var versionOnlyRegex *regexp.Regexp = regexp.MustCompile(`[^\|]*\|\s+([^\|]*)\s+\|.*$`)
var buildEssentialVersionRegex *regexp.Regexp = regexp.MustCompile(`^(?P<d1>\d+)\.(?P<d2>\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", "The version of build-essential to install.")
flag.Parse()

// Create and process the feature
feature := installer.NewFeature("Build Essential", true,
&buildEssentialComponent{
ComponentBase: installer.NewComponentBase(packageName, *version),
})
return feature.Process()
}

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

type buildEssentialComponent struct {
*installer.ComponentBase
}

func (c *buildEssentialComponent) GetAllVersions() ([]*gover.Version, error) {
if err := execr.Run(true, "apt-get", "update"); err != nil {
return []*gover.Version{}, err
}

str1, _, err := execr.RunGetOutput(true, "apt-cache", "madison", packageName)
if err != nil {
return []*gover.Version{}, err
}

allFiles := strings.Split(str1, "\n")
allVersions := []*gover.Version{}
for _, item := range allFiles {
matches := versionOnlyRegex.FindStringSubmatch(item)
if matches == nil {
continue
}
allVersions = append(allVersions, gover.MustParseVersionFromRegex(matches[1], buildEssentialVersionRegex))
}

return allVersions, nil
}

func (c *buildEssentialComponent) InstallVersion(version *gover.Version) error {
if version == gover.EmptyVersion {
return installer.Tools.Apt.InstallDependencies(packageName, "pkg-config", "libpcsclite-dev")
} else {
return installer.Tools.Apt.InstallDependencies(fmt.Sprintf(packageName+"=%s", version.Raw), "pkg-config", "libpcsclite-dev")
}
}
7 changes: 7 additions & 0 deletions features/test/build-essential/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/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_package_installed build-essential
13 changes: 13 additions & 0 deletions features/test/build-essential/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"install": {
"build": {
"dockerfile": "Dockerfile",
"options": [
"--add-host=host.docker.internal:host-gateway"
]
},
"features": {
"./build-essential": {}
}
}
}
5 changes: 5 additions & 0 deletions features/test/build-essential/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-22.04"
]