Skip to content

Commit

Permalink
Add git version resolver for local go-install modules (#4)
Browse files Browse the repository at this point in the history
* add git resolver + early fixes

Signed-off-by: Alex Goodman <[email protected]>

* use git version resolver for go-install local modules

Signed-off-by: Alex Goodman <[email protected]>

* improve the bootstrapping experience a bit

Signed-off-by: Alex Goodman <[email protected]>

* add a little more verbosity for ci bootstrapping

Signed-off-by: Alex Goodman <[email protected]>

---------

Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman authored Sep 8, 2023
1 parent a0af27e commit 5141efd
Show file tree
Hide file tree
Showing 16 changed files with 377 additions and 31 deletions.
25 changes: 15 additions & 10 deletions .binny.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
tools:

# - name: binny
# version:
# # can be 'main', 'latest', or a specific version
# want: v0.1.0
# method: github-release
# method: go-install
# with:
# module: github.com/anchore/binny
# path: cmd/binny
- name: binny
version:
# since the module is ., "current" means whatever is checked out
want: current
method: go-install
with:
# aka: github.com/anchore/binny, without going through github / goproxy (stay local)
module: .
entrypoint: cmd/binny
ldflags:
- -X main.version={{ .Version }}
- -X main.gitCommit={{ .Version }}
- -X main.gitDescription={{ .Version }}
# note: sprig functions are available: http://masterminds.github.io/sprig/
- -X main.buildDate={{ now | date "2006-01-02T15:04:05Z07:00" }}

- name: gh
version:
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ ci-bootstrap-go:

.PHONY: ci-bootstrap-tools
ci-bootstrap-tools: $(BINNY)
$(BINNY) install -v
$(BINNY) install -vvv

# this is a bootstrapping catch-all, where if the target doesn't exist, we'll ensure the tools are installed and then try again
%:
make $(TASK)
$(TASK) $@

## Shim targets #################################

Expand Down
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,48 @@
# binny
manage a directory of binaries without a package manager

Manage a directory of binaries without a package manager.

## Installation

```bash
curl -sSfL https://raw.githubusercontent.com/anchore/binny/main/install.sh | sh -s -- -b /usr/local/bin
```

... or, you can specify a release version and destination directory for the installation:

```bash
curl -sSfL https://raw.githubusercontent.com/anchore/binny/main/install.sh | sh -s -- -b <DESTINATION_DIR> <RELEASE_VERSION>
```

## Usage

Keep a configuration in your repo with the binaries you want to manage. For example:
```yaml
# .binny.yaml
- name: gh
version:
want: v2.33.0
method: github-release
with:
repo: cli/cli

- name: quill
version:
want: v0.4.1
method: github-release
with:
repo: anchore/quill

- name: chronicle
version:
want: v0.7.0
method: github-release
with:
repo: anchore/chronicle
```
Then you can run:
- `benny install` to install all binaries in the configuration
- `benny install <name>` to install a specific binary
- `benny check` to verify all configured binaries are installed
- `benny update-lock` to update any pinned versions in the configuration with the latest available versions
11 changes: 7 additions & 4 deletions cmd/binny/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ func New(id clio.Identification) clio.Application {

root := command.Root(app)

root.AddCommand(command.Install(app))
root.AddCommand(command.Check(app))
root.AddCommand(command.Run(app))
root.AddCommand(command.UpdateLock(app))
root.AddCommand(
clio.VersionCommand(id),
command.Install(app),
command.Check(app),
command.Run(app),
command.UpdateLock(app),
)

return app
}
23 changes: 21 additions & 2 deletions cmd/binny/cli/command/update_lock.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package command

import (
"bytes"
"fmt"
"io"
"os"
"runtime"

"github.com/chainguard-dev/yam/pkg/yam/formatted"
"github.com/google/yamlfmt"
"github.com/google/yamlfmt/engine"
"github.com/google/yamlfmt/formatters/basic"
Expand Down Expand Up @@ -86,7 +88,7 @@ func getUpdatedConfig(cfg option.AppConfig, names []string) (*option.AppConfig,
if toolCfg.Version.Constraint != "" {
fields["constraint"] = fmt.Sprintf("%q", toolCfg.Version.Constraint)
}
log.WithFields(fields).Info("tool version pin is up to date")
log.WithFields(fields).Debug("tool version pin is up to date")
newCfgs = append(newCfgs, toolCfg)
continue
}
Expand Down Expand Up @@ -276,5 +278,22 @@ func formatYaml(contents string) (string, error) {
return "", fmt.Errorf("unable to format YAML: %w", err)
}

return string(out), nil
var node yaml.Node
if err = yaml.Unmarshal(out, &node); err != nil {
return "", fmt.Errorf("unable to unmarshal formatted YAML: %w", err)
}

var buf bytes.Buffer
enc := formatted.NewEncoder(&buf)
enc, err = enc.SetGapExpressions(".tools")
if err != nil {
return "", fmt.Errorf("unable to set gap expressions: %w", err)
}

err = enc.Encode(&node)
if err != nil {
return "", fmt.Errorf("unable to format YAML: %w", err)
}

return buf.String(), nil
}
32 changes: 30 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ go 1.20

require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/Masterminds/sprig/v3 v3.2.3
github.com/anchore/clio v0.0.0-20230823172630-c42d666061af
github.com/anchore/go-logger v0.0.0-20230725134548-c21dafa1ec5a
github.com/chainguard-dev/yam v0.0.0-20230904174023-8d3c53b7e9d7
github.com/creack/pty v1.1.18
github.com/gabriel-vasile/mimetype v1.4.2
github.com/go-git/go-git/v5 v5.8.1
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/yamlfmt v0.9.1-0.20230607021126-908b19015fc4
github.com/hashicorp/go-multierror v1.1.1
Expand All @@ -25,16 +28,26 @@ require (
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect
github.com/RageCage64/multilinediff v0.2.0 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/adrg/xdg v0.4.0 // indirect
github.com/anchore/fangs v0.0.0-20230807173929-13c94c86f47e // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/bmatcuk/doublestar/v4 v4.6.0 // indirect
github.com/braydonk/yaml v0.7.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/felixge/fgprof v0.9.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.9 // indirect
Expand All @@ -43,36 +56,51 @@ require (
github.com/gookit/color v1.5.4 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/nwaples/rardecode v1.1.0 // indirect
github.com/pborman/indent v1.2.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pierrec/lz4/v4 v4.1.15 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/profile v1.7.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.2.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/tools v0.6.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
Loading

0 comments on commit 5141efd

Please sign in to comment.