Skip to content

Commit

Permalink
feat: filter packages by OS/arch/engine tags (#85)
Browse files Browse the repository at this point in the history
Fixes #84
  • Loading branch information
agaffney authored Mar 6, 2024
1 parent 4d687ae commit 05c3a09
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
19 changes: 13 additions & 6 deletions pkgmgr/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ import (
"log/slog"
"os"
"path/filepath"
"runtime"
)

type Config struct {
BinDir string
CacheDir string
ConfigDir string
DataDir string
Logger *slog.Logger
Template *Template
BinDir string
CacheDir string
ConfigDir string
DataDir string
Logger *slog.Logger
Template *Template
RequiredPackageTags []string
}

func NewDefaultConfig() (Config, error) {
Expand Down Expand Up @@ -69,6 +71,11 @@ func NewDefaultConfig() (Config, error) {
"cardano-up",
),
Logger: slog.Default(),
RequiredPackageTags: []string{
"docker",
runtime.GOOS,
runtime.GOARCH,
},
}
return ret, nil
}
17 changes: 17 additions & 0 deletions pkgmgr/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,26 @@ type Package struct {
Description string `yaml:"description"`
InstallSteps []PackageInstallStep `yaml:"installSteps"`
Dependencies []string `yaml:"dependencies"`
Tags []string `yaml:"tags"`
PostInstallNotes string `yaml:"postInstallNotes"`
}

func (p Package) hasTags(tags []string) bool {
for _, tag := range tags {
foundTag := false
for _, pkgTag := range p.Tags {
if tag == pkgTag {
foundTag = true
break
}
}
if !foundTag {
return false
}
}
return true
}

func (p Package) install(cfg Config, context string) (string, error) {
// Update template vars
pkgName := fmt.Sprintf("%s-%s-%s", p.Name, p.Version, context)
Expand Down
8 changes: 7 additions & 1 deletion pkgmgr/pkgmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ func (p *PackageManager) initTemplate() {
}

func (p *PackageManager) AvailablePackages() []Package {
return p.availablePackages[:]
var ret []Package
for _, pkg := range p.availablePackages {
if pkg.hasTags(p.config.RequiredPackageTags) {
ret = append(ret, pkg)
}
}
return ret
}

func (p *PackageManager) Up() error {
Expand Down
7 changes: 7 additions & 0 deletions pkgmgr/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var RegistryPackages = []Package{
Name: "cardano-node",
Version: "8.7.3",
Description: "Cardano node software by Input Output Global",
Tags: []string{"docker", "linux", "darwin", "amd64", "arm64"},
InstallSteps: []PackageInstallStep{
{
Docker: &PackageInstallStepDocker{
Expand Down Expand Up @@ -53,6 +54,7 @@ docker exec -ti {{ .Package.Name }}-cardano-node cardano-cli $@
Name: "mithril-client",
Version: "0.5.17",
Description: "Mithril client by Input Output Global",
Tags: []string{"docker", "linux", "darwin", "amd64", "arm64"},
InstallSteps: []PackageInstallStep{
{
Docker: &PackageInstallStepDocker{
Expand All @@ -75,6 +77,7 @@ docker run --rm -ti ghcr.io/blinklabs-io/mithril-client:0.5.17 $@
Name: "mithril-client",
Version: "0.7.0",
Description: "Mithril client by Input Output Global",
Tags: []string{"docker", "linux", "darwin", "amd64", "arm64"},
InstallSteps: []PackageInstallStep{
{
Docker: &PackageInstallStepDocker{
Expand All @@ -98,20 +101,24 @@ docker run --rm -ti ghcr.io/blinklabs-io/mithril-client:0.7.0-1 $@
{
Name: "test-packageA",
Version: "1.0.2",
Tags: []string{"docker", "linux", "darwin", "amd64", "arm64"},
PostInstallNotes: "Notes for {{ .Package.Name }}",
},
{
Name: "test-packageA",
Version: "1.0.3",
Tags: []string{"docker", "linux", "darwin", "amd64", "arm64"},
PostInstallNotes: "Notes for {{ .Package.Name }}",
},
{
Name: "test-packageA",
Version: "2.1.3",
Tags: []string{"docker", "linux", "darwin", "amd64", "arm64"},
},
{
Name: "test-packageB",
Version: "0.1.0",
Tags: []string{"docker", "linux", "darwin", "amd64", "arm64"},
Dependencies: []string{
"test-packageA < 2.0.0, >= 1.0.2",
},
Expand Down

0 comments on commit 05c3a09

Please sign in to comment.