• Stars
    star
    586
  • Rank 76,279 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Download files, folders, and release assets from a specific git commit, branch, or tag of public and private GitHub repos.

Maintained by Gruntwork.io

fetch

fetch makes it easy to download files, folders, or release assets from a specific commit, branch, or tag of a public or private GitHub repo.

Motivation

Gruntwork helps software teams get up and running on AWS with DevOps best practices and world-class infrastructure in about a day. Sometimes we publish scripts and binaries that clients use in their infrastructure, and we want an easy way to install a specific version of one of those scripts and binaries. While this is fairly straightforward to do with public GitHub repos, as you can usually curl or wget a public URL, it's much trickier to do with private GitHub repos, as you have to make multiple API calls, parse JSON responses, and handle authentication. Fetch makes it possible to handle all of these cases with a one-liner.

Features

  • Download from any git reference, such as a specific git tag, branch, or commit SHA.
  • Download a single file, a subset of files, or all files from the repo.
  • Download one or more binary assets from a specific release that match a regular expression.
  • Verify the SHA256 or SHA512 checksum of a binary asset.
  • Download from public repos, or from private repos by specifying a GitHub Personal Access Token.
  • Download from GitHub Enterprise.
  • When specifying a git tag, you can can specify either exactly the tag you want, or a Tag Constraint Expression to do things like "get the latest non-breaking version" of this repo. Note that fetch assumes git tags are specified according to Semantic Versioning principles.

Quick examples

Download folder /baz from tag 0.1.3 of a GitHub repo and save it to /tmp/baz:

fetch --repo="https://github.com/foo/bar" --tag="0.1.3" --source-path="/baz" /tmp/baz

Download a release asset matching named foo.exe from release 0.1.5 and save them to /tmp:

fetch --repo="https://github.com/foo/bar" --tag="0.1.5" --release-asset="foo.exe" /tmp

Download all release assets matching the regular expression, foo_linux-.* from release 0.1.5 and save them to /tmp:

fetch --repo="https://github.com/foo/bar" --tag="0.1.5" --release-asset="foo_linux-.*" /tmp

See more examples in the Examples section.

Installation

Download from releases page

Download the fetch binary from the GitHub Releases tab.

Install via package manager

Note that package managers are third party. The third party fetch packages may not be updated with the latest version, but are often close. Please check your version against the latest available on the releases page. If you want the latest version, the recommended installation option is to download from the releases page.

  • macOS: You can install fetch using Homebrew: brew install fetch.

  • Linux: Most Linux users can use Homebrew: brew install fetch.

Usage

Assumptions

fetch assumes that a repo's tags are in the format vX.Y.Z or X.Y.Z to support Semantic Versioning parsing. This allows you to specify a Tag Constraint Expression to do things like "get the latest non-breaking version" of this repo. Note that fetch also allows downloading a specific tag not in SemVer format.

General Usage

fetch [OPTIONS] <local-download-path>

The supported options are:

  • --repo (Required): The fully qualified URL of the GitHub repo to download from (e.g. https://github.com/foo/bar).
  • --ref (Optional): The git reference to download. If specified, will override --commit, --branch, and --tag.
  • --tag (Optional): The git tag to download. Can be a specific tag or a Tag Constraint Expression.
  • --branch (Optional): The git branch from which to download; the latest commit in the branch will be used. If specified, will override --tag.
  • --commit (Optional): The SHA of a git commit to download. If specified, will override --branch and --tag.
  • --source-path (Optional): The source path to download from the repo (e.g. --source-path=/folder will download the /folder path and all files below it). By default, all files are downloaded from the repo unless --source-path or --release-asset is specified. This option can be specified more than once.
  • --release-asset (Optional): A regular expression matching release assets--these are binary files uploaded to a GitHub Release--to download. It only works with the --tag option.
  • --release-asset-checksum (Optional): The checksum that a release asset should have. Fetch will fail if this value is non-empty and does not match the checksum computed by Fetch, or if more than 1 assets are matched by the release-asset regular expression.
  • --release-asset-checksum-algo (Optional): The algorithm fetch will use to compute a checksum of the release asset. Supported values are sha256 and sha512.
  • --github-oauth-token (Optional): A GitHub Personal Access Token. Required if you're downloading from private GitHub repos. NOTE: fetch will also look for this token using the GITHUB_OAUTH_TOKEN environment variable, which we recommend using instead of the command line option to ensure the token doesn't get saved in bash history.
  • --github-api-version (Optional): Used when fetching an artifact from a GitHub Enterprise instance. Defaults to v3. This is ignored when fetching from GitHub.com.
  • --progress (Optional): Used when fetching a big file and want to see progress on the fetch.

The supported arguments are:

  • <local-download-path> (Required): The local path where all files should be downloaded (e.g. /tmp).

Run fetch --help to see more information about the flags.

Tag Constraint Expressions

The value of --tag can be expressed using any operators defined in hashicorp/go-version.

Specifically, this includes:

Tag Constraint Pattern Meaning
1.0.7 Exactly version 1.0.7
=1.0.7 Exactly version 1.0.7
!=1.0.7 The latest version as long as that version is not 1.0.7
>1.0.7 The latest version greater than 1.0.7
<1.0.7 The latest version that's less than 1.0.7
>=1.0.7 The latest version greater than or equal to 1.0.7
<=1.0.7 The latest version that's less than or equal to 1.0.7
~>1.0.7 The latest version that is greater than 1.0.7 and less than 1.1.0
~>1.0 The latest version that is greater than 1.0 and less than 2.0

Examples

Usage Example 1

Download /modules/foo/bar.sh from a GitHub release where the tag is the latest version of 0.1.x but at least 0.1.5, and save it to /tmp/bar:

fetch --repo="https://github.com/foo/bar" --tag="~>0.1.5" --source-path="/modules/foo/bar.sh" /tmp/bar

Usage Example 2

Download all files in /modules/foo from a GitHub release where the tag is exactly 0.1.5, and save them to /tmp:

fetch --repo="https://github.com/foo/bar" --ref="0.1.5" --source-path="/modules/foo" /tmp

Usage Example 3

Download all files from a private GitHub repo using the GitHUb oAuth Token 123. Get the release whose tag is exactly 0.1.5, and save the files to /tmp:

GITHUB_OAUTH_TOKEN=123

fetch --repo="https://github.com/foo/bar" --ref="0.1.5" /tmp

Usage Example 4

Download all files from the latest commit on the sample-branch branch, and save them to /tmp:

fetch --repo="https://github.com/foo/bar" --ref="sample-branch" /tmp/josh1

Usage Example 5

Download all files from the git commit f32a08313e30f116a1f5617b8b68c11f1c1dbb61, and save them to /tmp:

fetch --repo="https://github.com/foo/bar" --ref="f32a08313e30f116a1f5617b8b68c11f1c1dbb61" /tmp

Usage Example 6

Download the release asset foo.exe from a GitHub release where the tag is exactly 0.1.5, and save it to /tmp:

fetch --repo="https://github.com/foo/bar" --ref="0.1.5" --release-asset="foo.exe" /tmp

Usage Example 7

Download the release asset foo.exe from a GitHub release hosted on a GitHub Enterprise instance running at ghe.mycompany.com where the tag is exactly 0.1.5, and save it to /tmp:

fetch --repo="https://ghe.mycompany.com/foo/bar" --ref="0.1.5" --release-asset="foo.exe" /tmp
Release Instructions

To release a new version of fetch, go to the Releases page and "Draft a new release". On the following page, bump the "Tag version" appropriately, and set the "Release title" to be the same. In the "Describe this release" section, log the changes of this release, linking back to issues that were addressed. Click the "Publish release" button. CircleCI will pick this up, generate the assets, and attach them to the release.

License

This code is released under the MIT License. See LICENSE.txt.

TODO

  • Introduce code verification using something like GPG signatures or published checksums
  • Explicitly test for exotic repo and org names
  • Apply stricter parsing for repo-filter command-line arg

More Repositories

1

terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
Go
7,998
star
2

terratest

Terratest is a Go library that makes it easier to write automated tests for your infrastructure code.
Go
7,425
star
3

cloud-nuke

A tool for cleaning up your cloud accounts by nuking (deleting) all resources within it
Go
2,722
star
4

git-xargs

git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.
Go
928
star
5

terragrunt-infrastructure-live-example

A repo used to show examples file/folder structures you can use with Terragrunt and Terraform
HCL
748
star
6

bash-commons

A collection of reusable Bash functions for handling common tasks such as logging, assertions, string manipulation, and more
Shell
747
star
7

intro-to-terraform

Sample code for the blog post series "A Comprehensive Guide to Terraform."
HCL
732
star
8

kubergrunt

Kubergrunt is a standalone go binary with a collection of commands to fill in the gaps between Terraform, Helm, and Kubectl. https://www.gruntwork.io
Go
510
star
9

pre-commit

A collection of pre-commit hooks used by Gruntwork tools
Shell
476
star
10

terraform-google-gke

Terraform code and scripts for deploying a Google Kubernetes Engine (GKE) cluster.
HCL
357
star
11

infrastructure-as-code-training

Materials for learning how to use infrastructure-as-code
Ruby
351
star
12

terragrunt-infrastructure-modules-example

A repo used to show examples file/folder structures you can use with Terragrunt and Terraform
HCL
298
star
13

terraform-aws-utilities

A collection of useful Terraform utilities
HCL
214
star
14

helm-kubernetes-services

Helm charts that can be used to package your applications into production ready deployments for Kubernetes. https://www.gruntwork.io
Go
192
star
15

infrastructure-as-code-testing-talk

Sample code for the talk "How to test your infrastructure code: automated testing for Terraform, Docker, Packer, Kubernetes, and more" by Yevgeniy Brikman
Go
186
star
16

boilerplate

A tool for generating files and folders ("boilerplate") from a set of templates
Go
166
star
17

toc

A Table of Contents of all Gruntwork Code
Shell
117
star
18

terraform-google-network

Terraform code and scripts for deploying a GCP Virtual Private Cloud (VPC).
HCL
107
star
19

health-checker

A simple HTTP server that will return 200 OK if all configured health checks pass.
Go
98
star
20

terraform-google-load-balancer

Terraform modules for deploying Load Balancers in GCP
HCL
93
star
21

terraform-google-sql

Terraform modules for deploying Google Cloud SQL (e.g. MySQL, PostgreSQL) in GCP
Go
92
star
22

terraform-aws-couchbase

Reusable infrastructure modules for running Couchbase on AWS
HCL
92
star
23

gruntwork-installer

A script to make it easy to install Gruntwork Modules
Shell
92
star
24

terragrunt-action

A GitHub Action for installing and running Terragrunt
Shell
91
star
25

terraform-training-solutions

The solutions for the exercises in the Infrastructure as Code with Terraform Workshop
HCL
81
star
26

terraform-kubernetes-helm

Terraform code and scripts for deploying Helm Server (Helm v2) on a Kubernetes cluster. https://www.gruntwork.io
HCL
65
star
27

terraform-fake-modules

HCL
45
star
28

private-tls-cert

A simple Terraform module to generate self-signed TLS certificates for private use
HCL
43
star
29

terratest-helm-testing-example

Example Helm Chart and corresponding test code using terratest.
Go
42
star
30

gruntwork-io.github.io

The gruntwork.io website
HTML
41
star
31

terraform-google-static-assets

Modules for managing static assets (CSS, JS, images) in GCP
HCL
36
star
32

go-commons

A standard library to use in all Gruntwork CLI tools
Go
34
star
33

knowledge-base

Gruntwork Knowledge Base. You are more than welcomed to create questions and share knowledge with our community.
34
star
34

docs

Gruntwork docs files plus a set of tools to auto-generate a docs website from package markdown files.
JavaScript
26
star
35

terraform-google-ci

Terraform code and scripts for deploying automated CI/CD pipelines on GCP.
HCL
19
star
36

patcher-action

A GitHub Action for running Patcher, including setting up promotion workflows.
TypeScript
17
star
37

terraform-kubernetes-namespace

This repo contains a Module for managing Kubernetes Namespaces with Terraform.
HCL
17
star
38

tflint-ruleset-aws-cis

Tflint rules for CIS AWS Foundations Benchmark compliance checks. These rules work in addition to the recommendations from Gruntwork's CIS Service Catalog.
Go
11
star
39

helmcharts

Holds Gruntwork's public helm chart repository
6
star
40

sample-app-docker

Sample app for use with Google Cloud Build
JavaScript
6
star
41

terragrunt-engine-opentofu

Go
5
star
42

terraform-hiera-like-example

A repo that shows an example of how to deploy services dynamically from Hiera-like YAML files using Terraform/Terragrunt
HCL
2
star
43

module-ci-update-terraform-variable-test

This repo is used as part of the automated tests for the terraform-update-tests script in module-ci
HCL
2
star
44

pipelines-orchestrate

Shell
2
star
45

terragrunt-engine-go

Go
2
star
46

terraform-module-in-root-for-terragrunt-test

This repo is used during automated tests for Terragrunt. It is not meant for any production usage.
HCL
1
star
47

pipelines-dispatch

Shell
1
star
48

terraform-null-terragrunt-registry-test

HCL
1
star
49

legal

1
star
50

pipelines-aws-execute

1
star
51

pipelines-workflows

1
star
52

pipelines-baseline-account-action

1
star
53

website-comments

This repository captures all comments written in the guides
1
star
54

pipelines-provision-repo-action

1
star
55

fetch-test-public

A public repo meant solely for testing with gruntwork-io/fetch
1
star
56

pipelines-execute

Shell
1
star
57

pipelines-status-update

Shell
1
star
58

pipelines-provision-access-control-action

1
star
59

pipelines-baseline-child-account-action

1
star
60

pipelines-bootstrap

1
star
61

pipelines-preflight-action

1
star
62

pipelines-provision-account-action

1
star