bindown

package module
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2020 License: MIT Imports: 10 Imported by: 0

README

bindown

godoc Go Report Card ci

bindown is a command-line utility to download, verify and install binary files. It is intended to be used in development and ci environments where it is important to guarantee the same version of the same binary is downloaded every time.

Installation

Using bootstrap-bindown.sh

This is the preferred method for ci or development environments. Each release contains a shell script bootstrap-bindown.sh that will download bindown for the current os. Place bootstrap-bindown.sh from the latest release in your project's repository. Don't forget to make it executable first (chmod +x bootstrap-bindown.sh on most systems). Then you can call bootstrap-bindown.sh before bindown in the projects bootstrap script or Makefile.

Usage
./bootstrap-bindown.sh -h
./bootstrap-bindown.sh: download the bindown binary

Usage: ./bootstrap-bindown.sh [-b bindir] [-d]
  -b sets bindir or installation directory, Defaults to ./bin
  -d turns on debug logging
Go get

If you happen to already have go installed on your system, you can install bindown with:

GO111MODULE=on go get -u github.com/willabides/bindown/v3/cmd/bindown 

Note the lowercase willabides. Pro tip: Your life will be easier with a lowercase GitHub username.

Config file properties

cache

The directory where bindown will cache downloads and extracted files. This is relative to the directory where the configuration file resides. cache paths should always use / as a delimiter even on Windows or other operating systems where the native delimiter isn't /.

Defaults to <path to config file>/.bindown

install_directory

The directory that bindown installs files to. This is relative to the directory where the configuration file resides. install_directory paths should always use / as a delimiter even on Windows or other operating systems where the native delimiter isn't /.

Defaults to <path to config file>/bin

dependencies

Dependencies are all the dependencies that bindown can install. It is a map where the key is the dependency's name.

Property Description
url The url to download a dependency from.
archive_path The path in the downloaded archive where the binary is located. Default is ./<dependency name>.
bin The name of the binary to be installed. Default is the name of the dependency.
link Whether to create a symlink to the bin instead of copying it.
template The name of a template to provide default values for this dependency. See templates.
vars A map of variables that will be interpolated in the url, archive_path and bin values. See vars
overrides A list of value overrides for certain systems. See overrides
substitutions Values that will be substituted for one variable. See substitutions
vars

Vars are key value pairs that are used in constructing url, archive_path and bin values using go templates. If you aren't familiar with go templates, all you need to know is that to use the value from a variable named "foo", you would write {{.foo}}. Go templates can do more than this, but that's all that is practical for bindown.

In addition to variables explicitly defined in vars, bindown adds os and arch variables based on the current system.

Consider this dependency:

myproject:
  url: https://github.com/me/myproject/releases/download/v{{.version}}/myproject_{{.version}}_{{.os}}_{{.arch}}.tar.gz
  archive_path: myproject_{{.version}}_{{.os}}_{{.arch}}/myproject
  vars:
    version: 1.2.3

When bindown is run for a linux/amd64 system, it will download from https://github.com/me/myproject/releases/download/v1.2.3/myproject_1.2.3_linux_amd64.tar.gz and use the archive path myproject_1.2.3_linux_amd64/myproject

substitutions

Substitutions provides replacement values for vars. The primary use case is for projects that don't use the same values for os and arch.

substitutions:
  arch:
    "386": i386
    amd64: x86_64
  os:
    darwin: Darwin
    linux: Linux
    windows: Windows
templates

Templates provide base values for dependencies. If a dependency has an unset value, the value from its template is used.

For vars, the value is initially set to the template's var map which is then overridden by values from the dependency. substitutions is handled similarly.

overrides concatenated with the template values coming first.

Template configuration is identical to dependencies.

overrides

Overrides allow you to override values for certain operating systems or system architectures.

It is a list of overrides that each contain a matcher and a dependency. Dependency properties are the same as described in dependencies. Matchers have two properties: os and arch that each contain a list of values to match. A system matches when it's os or arch value matches one of the values listed.

overrides:
  - matcher:
      os:
        - windows
    dependency:
      vars:
        archivepathsuffix: .exe
  - matcher:
      arch:
        - arm
        - arm64
    dependency:
      archive_path: special/path/for/arm

Usage

Usage: bindown <command>

Flags:
  --help                        Show context-sensitive help.
  --install-completions         install shell completions
  --configfile="bindown.yml"    file with bindown config ($BINDOWN_CONFIG_FILE)
  --cache=STRING                directory downloads will be cached ($BINDOWN_CACHE)
  --json                        use json instead of yaml for the config file

Commands:
  version

  download <dependency>
    download a dependency but don't extract or install it

  extract <dependency>
    download and extract a dependency but don't install it

  install <dependency>
    download, extract and install a dependency

  format
    formats the config file

  add-checksums <dependency>
    add checksums to the config file

  validate <dependency>
    validate that installs work

Run "bindown <command> --help" for more information on a command.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Cache        string                 `json:"cache,omitempty" yaml:"cache,omitempty"`
	InstallDir   string                 `json:"install_dir,omitempty" yaml:"install_dir,omitempty"`
	Dependencies map[string]*Dependency `json:"dependencies,omitempty" yaml:",omitempty"`
	Templates    map[string]*Dependency `json:"templates,omitempty" yaml:",omitempty"`
	URLChecksums map[string]string      `json:"url_checksums,omitempty" yaml:"url_checksums,omitempty"`
}

Config is our main config

func (*Config) AddChecksums

func (c *Config) AddChecksums(dependencies []string, systems []SystemInfo) error

AddChecksums downloads, calculates checksums and adds them to the config's URLChecksums. AddChecksums skips urls that already exist in URLChecksums.

func (*Config) BinName

func (c *Config) BinName(dep string, system SystemInfo) (string, error)

BinName returns the bin name for a downloader on a given system

func (Config) DownloadDependency

func (c Config) DownloadDependency(dependencyName string, sysInfo SystemInfo, opts *ConfigDownloadDependencyOpts) (string, error)

DownloadDependency downloads a dependency

func (Config) ExtractDependency

func (c Config) ExtractDependency(dependencyName string, sysInfo SystemInfo, opts *ConfigExtractDependencyOpts) (string, error)

ExtractDependency downloads and extracts a dependency

func (Config) ExtractPath

func (c Config) ExtractPath(dependencyName string, sysInfo SystemInfo) (string, error)

ExtractPath returns the path where a dependency will be extracted

func (Config) InstallDependency

func (c Config) InstallDependency(dependencyName string, sysInfo SystemInfo, opts *ConfigInstallDependencyOpts) (string, error)

InstallDependency downloads, extracts and installs a dependency

func (*Config) Validate

func (c *Config) Validate(dependencies []string, systems []SystemInfo) error

Validate installs the downloader to a temporary directory and returns an error if it was unsuccessful.

type ConfigAddChecksumsOptions

type ConfigAddChecksumsOptions struct {

	// Only add checksums for these dependencies. When Dependencies is empty, AddChecksums adds checksums for all
	//configured dependencies.
	Dependencies []string

	// Only add checksums for these system targets. When Systems is empty, AddChecksums adds checksums for all known
	// builds configured for each dependency.
	Systems []SystemInfo
}

ConfigAddChecksumsOptions contains options for Config.AddChecksums

type ConfigDownloadDependencyOpts

type ConfigDownloadDependencyOpts struct {
	TargetFile string
	Force      bool
}

ConfigDownloadDependencyOpts options for Config.DownloadDependency

type ConfigExtractDependencyOpts

type ConfigExtractDependencyOpts struct {
	TargetDirectory string
	Force           bool
}

ConfigExtractDependencyOpts options for Config.ExtractDependency

type ConfigInstallDependencyOpts

type ConfigInstallDependencyOpts struct {
	// TargetPath is the path where the executable should end up
	TargetPath string
	// Force - whether to force the install even if it already exists
	Force bool
}

ConfigInstallDependencyOpts provides options for Config.InstallDependency

type ConfigValidateOptions

type ConfigValidateOptions struct {

	// Only validates these dependencies. When Dependencies is empty, Validate validates all configured dependencies.
	Dependencies []string

	// Only validates system targets. When Systems is empty, AddChecksums validates all known builds configured for each
	//dependency.
	Systems []SystemInfo
}

ConfigValidateOptions contains options for Config.Validate

type Dependency

type Dependency struct {
	Template      *string                      `json:"template,omitempty" yaml:",omitempty"`
	URL           *string                      `json:"url,omitempty" yaml:",omitempty"`
	ArchivePath   *string                      `json:"archive_path,omitempty" yaml:"archive_path,omitempty"`
	BinName       *string                      `json:"bin,omitempty" yaml:"bin,omitempty"`
	Link          *bool                        `json:"link,omitempty" yaml:",omitempty"`
	Vars          map[string]string            `json:"vars,omitempty" yaml:",omitempty"`
	Overrides     []DependencyOverride         `json:"overrides,omitempty" yaml:",omitempty"`
	Substitutions map[string]map[string]string `json:"substitutions,omitempty" yaml:",omitempty"`
}

Dependency is something to download, extract and install

type DependencyOverride

type DependencyOverride struct {
	OverrideMatcher OverrideMatcher `json:"matcher" yaml:"matcher,omitempty"`
	Dependency      Dependency      `json:"dependency" yaml:",omitempty"`
}

DependencyOverride overrides a dependency's configuration

type OverrideMatcher

type OverrideMatcher struct {
	OS   []string `json:"os,omitempty" yaml:",omitempty"`
	Arch []string `json:"arch,omitempty" yaml:",omitempty"`
}

OverrideMatcher contains a list or oses and arches to match an override. If either os or arch is empty, all oses and arches match.

type SystemInfo

type SystemInfo struct {
	OS   string
	Arch string
}

SystemInfo contains os and architecture for a target system

func (SystemInfo) MarshalText

func (s SystemInfo) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler

func (*SystemInfo) String

func (s *SystemInfo) String() string

func (*SystemInfo) UnmarshalText

func (s *SystemInfo) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

Directories

Path Synopsis
cmd
bindown command
internal
cli
cli/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
jsonschema/schemafiles
Package schemafiles generated by go-bindata.// sources: ../../bindown.schema.json
Package schemafiles generated by go-bindata.// sources: ../../bindown.schema.json

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL