Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support specifying a package #548

Merged
merged 1 commit into from
Jan 23, 2025
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 cmd/aqua-registry-updater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ func core(ctx context.Context, logE *logrus.Entry) error {
defer stop()
return ctrl.Update(ctx, logE, &controller.Param{ //nolint:wrapcheck
GitHubToken: crToken,
Args: os.Args[1:],
})
}
36 changes: 36 additions & 0 deletions pkg/controller/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/spf13/afero"
"github.com/suzuki-shunsuke/go-timeout/timeout"
"github.com/suzuki-shunsuke/logrus-error/logerr"
"oras.land/oras-go/v2/registry/remote"
)

func (c *Controller) Update(ctx context.Context, logE *logrus.Entry, param *Param) error { //nolint:funlen,cyclop
Expand Down Expand Up @@ -75,6 +76,10 @@ func (c *Controller) Update(ctx context.Context, logE *logrus.Entry, param *Para
})
}

if len(param.Args) != 0 {
return c.handleArgs(ctx, logE, param, data, repo, tag, cfg, ignorePkgsM)
}

var idx int
defer func() { //nolint:contextcheck
data.Packages = append(data.Packages[idx:], data.Packages[:idx]...)
Expand Down Expand Up @@ -110,6 +115,36 @@ func (c *Controller) Update(ctx context.Context, logE *logrus.Entry, param *Para
return nil
}

func (c *Controller) handleArgs(ctx context.Context, logE *logrus.Entry, param *Param, data *Data, repo *remote.Repository, tag string, cfg *Config, ignorePkgsM map[string]struct{}) error {
defer func() { //nolint:contextcheck
if err := c.writeData("data.json", data); err != nil {
logerr.WithError(logE, err).Error("update data.json")
return
}
logE.Info("pushing data.json to the container registry")
if err := pushFiles(context.Background(), repo, tag); err != nil {
logerr.WithError(logE, err).Error("push data.json to the container registry")
}
}()
for _, arg := range param.Args {
for i, pkg := range data.Packages {
if pkg.Name != arg {
continue
}
data.Packages = append(append(data.Packages[:i], data.Packages[i+1:]...), pkg)
if _, ok := ignorePkgsM[pkg.Name]; ok {
continue
}
logE := logE.WithField("pkg_name", pkg.Name)
logE.Info("handling a package")
if _, err := c.handlePackage(ctx, logE, pkg, cfg); err != nil {
logerr.WithError(logE, err).Error("handle a package")
}
}
}
return nil
}

func (c *Controller) listPkgYAML() ([]string, error) {
pkgPaths := []string{}
if err := fs.WalkDir(afero.NewIOFS(c.fs), "pkgs", func(p string, dirEntry fs.DirEntry, e error) error {
Expand Down Expand Up @@ -316,4 +351,5 @@ func (c *Controller) exec(ctx context.Context, command string, args ...string) e

type Param struct {
GitHubToken string
Args []string
}
Loading