-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement
bldr update --dry
command
Only for GitHub tags and releases for now. Refs #48. Signed-off-by: Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
- Loading branch information
Showing
20 changed files
with
2,073 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
out | ||
/out | ||
/bldr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"runtime" | ||
"sort" | ||
"sync" | ||
"text/tabwriter" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/talos-systems/bldr/internal/pkg/solver" | ||
"github.com/talos-systems/bldr/internal/pkg/update" | ||
) | ||
|
||
type pkgInfo struct { | ||
file string | ||
source string | ||
} | ||
|
||
type updateInfo struct { | ||
file string | ||
*update.LatestInfo | ||
} | ||
|
||
var updateCmdFlag struct { | ||
all bool | ||
dry bool | ||
} | ||
|
||
// updateCmd represents the `update` command. | ||
var updateCmd = &cobra.Command{ | ||
Use: "update", | ||
Short: "Update pkgs", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if !updateCmdFlag.dry { | ||
log.Fatal("Real update is not implemented yet; pass `--dry` flag.") | ||
} | ||
|
||
loader := solver.FilesystemPackageLoader{ | ||
Root: pkgRoot, | ||
Context: options.GetVariables(), | ||
} | ||
|
||
packages, err := solver.NewPackages(&loader) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
l := log.New(log.Writer(), "[update] ", log.Flags()) | ||
if !debug { | ||
l.SetOutput(ioutil.Discard) | ||
} | ||
|
||
concurrency := runtime.GOMAXPROCS(-1) | ||
var wg sync.WaitGroup | ||
sources := make(chan *pkgInfo) | ||
updates := make(chan *updateInfo) | ||
for i := 0; i < concurrency; i++ { | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
|
||
for src := range sources { | ||
res, e := update.Latest(context.TODO(), src.source) | ||
if e != nil { | ||
l.Print(e) | ||
continue | ||
} | ||
|
||
updates <- &updateInfo{ | ||
file: src.file, | ||
LatestInfo: res, | ||
} | ||
} | ||
}() | ||
} | ||
|
||
var res []updateInfo | ||
done := make(chan struct{}) | ||
go func() { | ||
for update := range updates { | ||
res = append(res, *update) | ||
} | ||
close(done) | ||
}() | ||
|
||
for _, node := range packages.ToSet() { | ||
for _, step := range node.Pkg.Steps { | ||
for _, src := range step.Sources { | ||
sources <- &pkgInfo{ | ||
file: node.Pkg.FileName, | ||
source: src.URL, | ||
} | ||
} | ||
} | ||
} | ||
close(sources) | ||
wg.Wait() | ||
close(updates) | ||
<-done | ||
|
||
sort.Slice(res, func(i, j int) bool { return res[i].file < res[j].file }) | ||
|
||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) | ||
fmt.Fprintf(w, "%s\t%s\t%s\n", "File", "Update", "URL") | ||
|
||
for _, info := range res { | ||
if updateCmdFlag.all || info.HasUpdate { | ||
url := info.LatestURL | ||
if url == "" { | ||
url = info.BaseURL | ||
} | ||
|
||
fmt.Fprintf(w, "%s\t%t\t%s\n", info.file, info.HasUpdate, url) | ||
} | ||
} | ||
|
||
if err = w.Flush(); err != nil { | ||
log.Fatal(err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
updateCmd.Flags().BoolVarP(&updateCmdFlag.all, "all", "a", false, "List all packages, not only updated") | ||
updateCmd.Flags().BoolVar(&updateCmdFlag.dry, "dry", false, "Dry run: check for updates, but not actually update pkgs") | ||
rootCmd.AddCommand(updateCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,22 @@ | ||
module github.com/talos-systems/bldr | ||
|
||
go 1.14 | ||
go 1.16 | ||
|
||
require ( | ||
github.com/Masterminds/goutils v1.1.0 // indirect | ||
github.com/Masterminds/semver v1.5.0 // indirect | ||
github.com/Masterminds/sprig v2.22.0+incompatible | ||
github.com/alessio/shellescape v1.2.2 | ||
github.com/containerd/containerd v1.4.0-0 | ||
github.com/emicklei/dot v0.11.0 | ||
github.com/hashicorp/go-multierror v1.1.0 | ||
github.com/huandu/xstrings v1.3.1 // indirect | ||
github.com/mitchellh/copystructure v1.0.0 // indirect | ||
github.com/moby/buildkit v0.7.1 | ||
github.com/Masterminds/semver v1.5.0 | ||
github.com/Masterminds/sprig/v3 v3.2.2 | ||
github.com/alessio/shellescape v1.4.1 | ||
github.com/containerd/containerd v1.5.2 | ||
github.com/emicklei/dot v0.16.0 | ||
github.com/google/go-github/v35 v35.3.0 | ||
github.com/hashicorp/go-multierror v1.1.1 | ||
github.com/moby/buildkit v0.8.3 | ||
github.com/opencontainers/go-digest v1.0.0 | ||
github.com/opencontainers/image-spec v1.0.1 | ||
github.com/otiai10/copy v1.2.0 | ||
github.com/spf13/cobra v1.0.0 | ||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e | ||
gopkg.in/yaml.v2 v2.3.0 | ||
) | ||
|
||
replace ( | ||
github.com/containerd/containerd => github.com/containerd/containerd v1.3.1-0.20200512144102-f13ba8f2f2fd | ||
github.com/docker/docker => github.com/docker/docker v17.12.0-ce-rc1.0.20200310163718-4634ce647cf2+incompatible | ||
github.com/otiai10/copy v1.6.0 | ||
github.com/spf13/cobra v1.2.1 | ||
github.com/stretchr/testify v1.7.0 | ||
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 | ||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c | ||
gopkg.in/yaml.v2 v2.4.0 | ||
) |
Oops, something went wrong.