vendoring versioning with go vendoring versioning with go
play

Vendoring & Versioning with Go Vendoring & Versioning with - PowerPoint PPT Presentation

Vendoring & Versioning with Go Vendoring & Versioning with Go 4 November 2016 4 November 2016 Chris Roche Chris Roche Software Engineer, Lyft Software Engineer, Lyft Go's Vendoring History Go's Vendoring History In the beginning,


  1. Vendoring & Versioning with Go Vendoring & Versioning with Go 4 November 2016 4 November 2016 Chris Roche Chris Roche Software Engineer, Lyft Software Engineer, Lyft

  2. Go's Vendoring History Go's Vendoring History

  3. In the beginning, there was the mono-repo In the beginning, there was the mono-repo Project lived in Google's mono-repo Project lived in Google's mono-repo Mercurial(ish) system Mercurial(ish) system Vendoring not an issue in this world Vendoring not an issue in this world Using internal tooling (Bazel) in any case Using internal tooling (Bazel) in any case Each directory considered distinct package regardless of hierarchy Each directory considered distinct package regardless of hierarchy go tools built out to support mutliple repos and VCS go tools built out to support mutliple repos and VCS

  4. Go 1.0 - 1.4 : WYSIWYG Go 1.0 - 1.4 : WYSIWYG All non-stdlib dependencies must live under All non-stdlib dependencies must live under $GOPATH/src $GOPATH/src Works perfectly fine for subpackages in the same repo Works perfectly fine for subpackages in the same repo External dependency versions completely neglected External dependency versions completely neglected Tools built to change refs before running build/tests, etc. Tools built to change refs before running build/tests, etc. Workaround: use a project-specific $GOPATH Workaround: use a project-specific $GOPATH

  5. Path to ./vendor Path to ./vendor Go 1.5 Go 1.5 (Aug 2015) (Aug 2015) - Enabled use of the - Enabled use of the ./vendor ./vendor directory directory - Disabled by default - Disabled by default - Enable: GO15VENDOREXPERIMENT=1 - Enable: GO15VENDOREXPERIMENT=1 Go 1.6 (Feb 2016) (Feb 2016) Go 1.6 - Enabled by default - Enabled by default - Disable: GO15VENDOREXPERIMENT=0 - Disable: GO15VENDOREXPERIMENT=0 Go 1.7 (Aug 2017) (Aug 2017) Go 1.7 - Cannot disable - Cannot disable

  6. How does it work? How does it work? First: ./vendor First: ./vendor - From: - From: "github.com/foo/bar" "github.com/foo/bar" - To: - To: "github.com/fizz/buzz/vendor/github.com/foo/bar" "github.com/fizz/buzz/vendor/github.com/foo/bar" - Never import vendor (compilation will fail or behave strangely) - Never import vendor (compilation will fail or behave strangely) - Commit or not to commit? (up to preference) - Commit or not to commit? (up to preference) Second: $GOPATH/src Second: $GOPATH/src - This is how subpackages of a project are loaded - This is how subpackages of a project are loaded - Useful for testing/debugging libraries in dependent's context - Useful for testing/debugging libraries in dependent's context Finally: $GOROOT/src Finally: $GOROOT/src - Standard Library exclusively - Standard Library exclusively - Never ever ever touch/add to these - Never ever ever touch/add to these

  7. Sidebar: Versioning Go with Gimme Sidebar: Versioning Go with Gimme github.com/travis-ci/gimme github.com/travis-ci/gimme (https://github.com/travis-ci/gimme) (https://github.com/travis-ci/gimme) brew install gimme # other ways (it's just a shell script) brew install gimme # other ways (it's just a shell script) gimme 1.7.3 gimme 1.7.3 go version go version go version go1.7.3 darwin/amd64 go version go1.7.3 darwin/amd64 Configure in your bash/zsh profile: Configure in your bash/zsh profile: source $HOME/.gimme/envs/latest.env source $HOME/.gimme/envs/latest.env Configure in IntelliJ (per project): Configure in IntelliJ (per project): Module settings ( ⌘ ↓ ) Module settings ( ⌘ ↓ ) Platform Settings / SDKs Platform Settings / SDKs + in top left / Go SDK + in top left / Go SDK (turn on hidden) (turn on hidden) "/Users/gopher/.gimme/versions/go.1.7.3.darwin.amd64" "/Users/gopher/.gimme/versions/go.1.7.3.darwin.amd64"

  8. Vendoring/Versioning Tools Vendoring/Versioning Tools No blessed Go tool ( No blessed Go tool (working on it working on it (https://docs.google.com/document/d/18tNd8r5DV0yluCR7tPvkMTsWD_lYcRO7NhpNSDymRr8) (https://docs.google.com/document/d/18tNd8r5DV0yluCR7tPvkMTsWD_lYcRO7NhpNSDymRr8) , though) , though) GoDep: one of the first, JSON based, scrubs vendored code GoDep: one of the first, JSON based, scrubs vendored code gpm: no support for ./vendor gpm: no support for ./vendor , just update VCS refs in , just update VCS refs in $GOPATH $GOPATH gvp: change $GOPATH to a localized ./.godeps , works with gpm gvp: change $GOPATH to a localized ./.godeps , works with gpm gb: replaces go toolchain, does not use gb: replaces go toolchain, does not use ./vendor ./vendor (correctly) (correctly)

  9. Glide Glide

  10. Features Features Correctly uses Correctly uses ./vendor ./vendor Leaves $GOPATH alone Leaves $GOPATH alone YAML based configuration file YAML based configuration file Locking system similar to Composer (PHP), Bundler (Ruby), and Cargo (Rust) Locking system similar to Composer (PHP), Bundler (Ruby), and Cargo (Rust) Aware of Godep config files Aware of Godep config files Respects configuration of transient dependencies Respects configuration of transient dependencies Useful CLI, but certainly not perfect Useful CLI, but certainly not perfect

  11. Ecosystem: $HOME/.glide Ecosystem: $HOME/.glide The VCS cache The VCS cache Independent of $GOPATH and ./vendor Independent of $GOPATH and ./vendor Don't touch! Don't touch!

  12. Ecosystem: ./glide.yaml Ecosystem: ./glide.yaml Human's Configuration Human's Configuration YAML-based YAML-based Override VCS behavior Override VCS behavior Commit / Branch / Tag / SemVer aware Commit / Branch / Tag / SemVer aware Only include your direct dependencies Only include your direct dependencies package: github.com/example/pkg package: github.com/example/pkg import: import: - package: github.com/external/dep - package: github.com/external/dep version: unstable-branch version: unstable-branch - package: github.com/example/other-pkg - package: github.com/example/other-pkg version: ^1.2.3 version: ^1.2.3 repo: git@github.com:example/other-pkg repo: git@github.com:example/other-pkg testImport: testImport: - package: github.com/stretchr/testify - package: github.com/stretchr/testify subpackages: subpackages: - assert - assert

  13. Ecosystem: ./glide.lock Ecosystem: ./glide.lock Computer's Configuration Computer's Configuration Snapshot of what the crazy human wants Snapshot of what the crazy human wants Look Don't Touch! Look Don't Touch! Always pinned to a SHA (or equivalent) Always pinned to a SHA (or equivalent) Includes hash of glide.yaml Includes hash of glide.yaml All explicit and transient dependencies All explicit and transient dependencies Must be committed Must be committed hash: d8dc02f36d3bd58163dfc37dfd022a8539e31258d8f2c2ad417ef8f3d6d76d2a hash: d8dc02f36d3bd58163dfc37dfd022a8539e31258d8f2c2ad417ef8f3d6d76d2a updated: 2016-10-06T17:33:31.683461401-04:00 updated: 2016-10-06T17:33:31.683461401-04:00 imports: imports: - name: github.com/external/dep - name: github.com/external/dep version: 74a703abb31ea9faf7622930e5daba1559b01b37 version: 74a703abb31ea9faf7622930e5daba1559b01b37

  14. glide init: Starting a New Project glide init: Starting a New Project walks any existing code and creates a glide.yaml walks any existing code and creates a glide.yaml will prompt about versioning if semver is detected will prompt about versioning if semver is detected nothing is installed! nothing is installed! allows modification of glide.yaml before install allows modification of glide.yaml before install glide init glide init [INFO] Generating a YAML configuration file and guessing the dependencies [INFO] Generating a YAML configuration file and guessing the dependencies [INFO] Attempting to import from other package managers (use --skip-import to skip) [INFO] Attempting to import from other package managers (use --skip-import to skip) [INFO] Scanning code to look for dependencies [INFO] Scanning code to look for dependencies [INFO] --> Found reference to github.com/fizz/buzz [INFO] --> Found reference to github.com/fizz/buzz [INFO] --> Found reference to github.com/foo/bar [INFO] --> Found reference to github.com/foo/bar [INFO] Writing configuration file (glide.yaml) [INFO] Writing configuration file (glide.yaml)

Recommend


More recommend