Code Monkey home page Code Monkey logo

godownloader's Introduction

Warning: this is no longer actively maintained.

See #161 for details.


GoReleaser Logo

GoDownloader

Download Go binaries as fast and easily as possible.

Software License Travis Go Report Card Go Doc Powered By: GoReleaser


This is the inverse of goreleaser. The goreleaser YAML file is read and creates a custom shell script that can download the right package and the right version for the existing machine.

If you use goreleaser already, this will create scripts suitable for "curl bash" style downloads.

This is also useful in CI/CD systems such as travis-ci.org.

  • Much faster then 'go get' (sometimes up to 100x)
  • Make sure your local environment (macOS) and the CI environment (Linux) are using the exact same versions of your go binaries.

CI/CD Example

Let's say you are using hugo, the static website generator, with travis-ci.

Your old .travis.yml file might have

install:
  - go get github.com/gohugoio/hugo

This can take up to 30 seconds!

Hugo doesn't have (yet) a godownloader.sh file. So we will make our own:

# create a godownloader script
godownloader --repo=gohugoio/hugo > ./godownloader-hugo.sh

and add godownloader-hugo.sh to your GitHub repo. Edit your .travis.yml as such

install:
  - ./godownloader-hugo.sh v0.37.1

Without a version number, GitHub is queried to get the latest version number.

install:
  - ./godownloader-hugo.sh

Typical download time is 0.3 seconds, or 100x improvement.

Your new hugo binary is in ./bin, so change your Makefie or scripts to use ./bin/hugo.

The default installation directory can be changed with the -b flag or the BINDIR environment variable.

Notes on Functionality

  • Only GitHub Releases are supported right now.
  • Checksums are checked.
  • Binares are installed using tar.gz or zip.
  • No OS-specific installs such as homebrew, deb, rpm. Everything is installed locally via a tar.gz or zip. Typically OS installs are done differently anyways (e.g. brew, apt-get, yum, etc).

Experimental support

Some people do not use Goreleaser (why!), so there is experimental support for the following alterative distributions.

"naked" releases on GitHub

A naked release is just the raw binary put on GitHub releases. Limited support can be done by

./goreleaser -source raw -repo [owner/repo] -exe [name] -nametpl [tpl]

Where exe is the final binary name, and tpl is the same type of name template that Goreleaser uses.

An example repo is at mvdan/sh. Note how the repo sh is different than the binary shfmt.

Equinox.io

Equinox.io is a really interesting platform. Take a look.

There is no API, so godownloader screen scrapes to figure out the latest release. Likewise, checksums are not verified.

./goreleaser -source equinoxio -repo [owner/repo]

While Equinox.io supports the concept of different release channels, only the stable channel is supported by godownloader.

Yes, it's true.

It's a go program that reads a YAML file that uses a template to make a posix shell script.

Other Resources and Inspiration

Other applications have written custom shell downloaders and installers:

golang/dep

The golang/dep package manager has a nice downloader, install.sh. Their trick to extract a version number from GitHub Releases is excellent:

$(echo "${LATEST_RELEASE}" | tr -s '\n' ' ' | sed 's/.*"tag_name":"//' | sed 's/".*//' )

This is probably based on masterminds/glide and its installer at https://glide.sh/get

kubernetes/helm

kubernetes/helm is a "tool for managing Kubernetes charts. Charts are packages of pre-configured Kubernetes resources."

It has a get script. Of note is that it won't re-install if the desired version is already present.

chef

Chef has the one of the most complete installers at https://omnitruck.chef.io/install.sh. In particular it has support for

  • Support for solaris and aix, and some other less common platforms
  • python or perl as installers if curl or wget isn't present
  • http proxy support

Caddy

Caddy is "the HTTP/2 web server with automatic HTTPS" and a NGINX replacement. It has a clever installer at https://getcaddy.com. Of note is GPG signature verification.

godownloader's People

Contributors

akupila avatar caarlos0 avatar client9 avatar crazy-max avatar dependabot-preview[bot] avatar docwhat avatar eklitzke avatar fat0troll avatar fundor333 avatar golangcidev avatar gopinath-langote avatar haya14busa avatar joemiller avatar jorinvo avatar kaihendry avatar kamilsk avatar lawrencegripper avatar ldez avatar lukeshu avatar mschneider82 avatar mverteuil avatar philippgille avatar renovate[bot] avatar ryanking avatar ryantking avatar shulima avatar syntaqx avatar tpounds avatar twpayne avatar vorandrew avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

godownloader's Issues

Broken master

Looking forward to giving this a try, but it seems busted!

   位 godownloader (master): gi
# github.com/goreleaser/godownloader
./main.go:122:12: project.Build undefined (type *config.Project has no field or method Build)
./main.go:123:10: project.Build undefined (type *config.Project has no field or method Build)
./shell_equinoxio.go:19:9: project.Build undefined (type config.Project has no field or method Build)
./shell_raw.go:32:9: project.Build undefined (type config.Project has no field or method Build)

idea: goinstaller

ok another idea.. maybe not good.

so godownloader got started since I was trying to sync macOS and travis-ci and another linux builder to use the exact same set of tools.

I just realized another way of doing this it to have a special downloader that

  1. given command line args, e.g. goinstaller client9/misspell tdewolff/minify ...
  2. go to the network and find goreleaser file
  3. use that to figure out what to download
  4. download it

can be done in parallel.

In other words, instead of godownloader making a shell script, it just actually does the download. And written in go, not gross shell.

For my travis-ci workflow, I would still need to install 'goinstaller' but that would be it.

now i don't care if the authors of a package have provided a godownloader script.

thoughts?

n

interesting.. if there wasn't a goreleaser.yaml file the goinstaller could make a 'best effort' as well.

option to write to file (if output is different)

Currently, the output is to stdout. However with a timestamp or version info this might create different output every time. This is fine for quick generation, but not good in other cases.

We want a flag to write to file only if the output is significantly different. If the script is different in only comments or a timestamp, then godownloader should not overwrite the file.

Needed for #39
Blocked by #56

add Code Generated DO NOT EDIT to shellfn.go

As per:

golang/go#13560 (comment)

Generated files are marked by a line of text that matches the regular expression, in Go syntax:
^// Code generated .* DO NOT EDIT\.$
The .* means the tool can put whatever folderol it wants in there, but the comment must be a single line and must start with Code generated and end with DO NOT EDIT., with a period.

The text may appear anywhere in the fi

Investigate curl -N flag, update shlibs

Added in

f451dc9#diff-83752e6cf679642f9650d58b739cb2c3

the command for curl added the -N flag

This turns off curl buffering. That's fine, but its not clear what problem this solved. (or maybe I missed it).

I don't see this in similar shell downloaders like:

https://github.com/golang/dep/blob/master/install.sh

Just curious on why, and to make sure it's in older curl versions.

@caarlos0 any ideas here on why it was added?

If it's needed, then I need to update client9/shlibs (no problem, just another thing to do).

n

adjust_arch command not found

Thanks again for the tooling!

I tried the following and got:

   位 gh-polls (master): godownloader -repo tj/gh-polls > install.sh
   位 gh-polls (master): sh install.sh
tj/gh-polls: checking GitHub for latest version
install.sh: line 287: adjust_arch: command not found

use uname_os , uname_arch self-check to catch bugs

Much of the code depends on converting uname values back into GOOS and GOARCH values.

However, I really have no idea what uname -m says when running on a arm64 or a ppc64le machine. We have a guess, but it might be wrong.

Make it report an error if we can't convert into a known value.

sync with goreleaser new yaml format

On master, goreleaser allows for multiple build stanzas.

Godownloader works correctly for older yaml files, but not the new format (travis is broken only for new format... old stuff is ok)

Bring godownloader up to date

@caarlos0 @jorinvo --Please excuse my delay, but I'm back to fix this up. I can't find the slack group to chat, so here I am filing a ticket. Any special new rules or processes I should be aware of ?

checksum file name may have changed or is now templated

Using latest bigs and old release of client9/misspell

client9/misspell INFO checking GitHub for latest tag
client9/misspell INFO found version: 0.3.0 for v0.3.0/mac/64bit
client9/misspell DEBUG downloading tarball https://github.com/client9/misspell/releases/download/v0.3.0/misspell_0.3.0_mac_64bit.tar.gz
client9/misspell DEBUG downloading checksum https://github.com/client9/misspell/releases/download/v0.3.0/misspell_0.3.0_checksums.txt
curl: (22) The requested URL returned error: 404 Not Found

turns out the checksum file didn't have the version number it in

https://github.com/client9/misspell/releases/download/v0.3.0/misspell_checksums.txt

Also, ugly CURL error

n

generate better log messages in script

currently, the script doesn't print very much. It should be say what it is doing.

Also:when it does it also doesn't say what script it's from. If multiple scripts are running in parallel, then the output is unclear as to what is happening.

requiring "v" prefix in version number

Hey,

thanks for a great project!

I've noticed that generated script assumes that version number is prefixed with "v". Is there a way to avoid it other than manual changes?

From goreleaser perspective those two formats v0.1.0 and 0.1.0 are equal

Note: we recommend the use of semantic versioning. We are not enforcing it though. We do remove the v prefix and then enforce that the next character is a number. So, v0.1.0 and 0.1.0 are virtually the same and are both accepted, while version0.1.0 is not.

use default from goreleaser instead of hardwire

default name of template is in pipeline/defaults/defaults.go:

const NameTemplate = "{{ .Binary }}_{{.Version}}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"

But GD isn't using it:

        // TODO: error on conditionals
        if target == "" || target == "{{ .Binary }}_{{ .Os }}_{{ .Arch }}{{ if .
Arm }}v{{ .Arm }}{{ end }}" {
                prefix = "if [ ! -z \"${ARM}\" ]; then ARM=\"v$ARM\"; fi"
                target = "{{ .Binary }}_{{ .Os }}_{{ .Arch }}{{ .Arm }}"
        }

gross.

Should godownloader be a flag or hook for goreleaser?

i.e. goreleaser --make-downloader or something

There are some good reasons for this. It makes the whole vendoring issue for godownloader goes away, less confusing for users, more eyeballs (and hopefully end users), and makes goreleaser that much more complete.

The downside is if we want to add a lot of flags to godownloader to do... I don't know what, it becomes harder (well we could do something like gorelease --make-downloader "option1,option2" or something

I've got a few more days of hacking on godownloader before it makes sense, but something to consider.

thoughts,

n

improve curl/wget abstraction

currently it's in one place at the bottom. but we need to use it in other places.
make it a function

need to support adding headers too.

Fails with gometalinter

$> godownloader -repo https://github.com/alecthomas/gometalinter > foo.sh
2018/03/09 16:23:01 Reading https://raw.githubusercontent.com/https://github.com/alecthomas/gometalinter/master/goreleaser.yml
2018/03/09 16:23:01 Issue reading https://raw.githubusercontent.com/https://github.com/alecthomas/gometalinter/master/goreleaser.yml returned: 404 Not Found
2018/03/09 16:23:01 Reading https://raw.githubusercontent.com/https://github.com/alecthomas/gometalinter/master/.goreleaser.yml
2018/03/09 16:23:01  info loading environment variables
2018/03/09 16:23:01  info snapshoting              
2018/03/09 16:23:01  info releasing to GitHub      
2018/03/09 16:23:01  info creating archives        
2018/03/09 16:23:01  info building binaries        
2018/03/09 16:23:01  info creating Linux packages with fpm
2018/03/09 16:23:01  info creating Linux packages with nfpm
2018/03/09 16:23:01  info creating Linux packages with snapcraft
2018/03/09 16:23:01  info calculating checksums    
2018/03/09 16:23:01  info signing artifacts        
2018/03/09 16:23:01  info creating Docker images   
2018/03/09 16:23:01  info releasing to Artifactory 
2018/03/09 16:23:01  info creating homebrew formula
2018/03/09 16:23:01  info creating Scoop Manifest  
$> sh ./foo.sh 
alecthomas/gometalinter info checking GitHub for latest tag
alecthomas/gometalinter info found version: 2.0.5 for v2.0.5/linux/amd64
install: cannot stat '/tmp/tmp.zqpty6BYN2/gometalinter': No such file or directory

The problem is that that after untarring the downloaded tarball in $TMPDIR, it assumes that $TMPDIR contains the binaries. But in this case $TMPDIR contains this:

ls -l /tmp/tmp.zqpty6BYN2/
total 39324
-rw-rw-r-- 1 autarch autarch      312 Mar  9 16:23 gometalinter-2.0.5-checksums.txt
drwxrwxr-x 2 autarch autarch     4096 Mar  9 16:23 gometalinter-2.0.5-linux-amd64
-rw-rw-r-- 1 autarch autarch 40258507 Mar  9 16:23 gometalinter-2.0.5-linux-amd64.tar.gz

godownloader as a service

Curious what you think of having a "hosted" version of this. Sort of like https://github.com/tj/bins but still pushing your own build artifacts. That might be a decent compromise. That way you don't have to update ./install.sh scripts often if it's improved for a platform.

Something like:

curl -sf https://bins.io/tj/node-prune | sh

or

curl -sf https://bins.io/github.com/tj/node-prune | sh

versioned

curl -sf https://bins.io/github.com/tj/[email protected] | sh

I'm sure some people would think it's sketchy, but I guess they can manually install :D

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    馃枛 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 馃搳馃搱馃帀

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google 鉂わ笍 Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.