Ship your CLI tool built by golang to your user #golangstudy

Ecb3acc2d246962361a4f8b3f7a6dd12?s=47 taichi nakashima
August 09, 2014
5.6k

Ship your CLI tool built by golang to your user #golangstudy

Ecb3acc2d246962361a4f8b3f7a6dd12?s=128

taichi nakashima

August 09, 2014
Tweet

Transcript

  1. Ship your CLI tool built by Golang: Compile, Release, Downloading

    http://wallbase.cc/wallpaper/1950578
  2. I’m Taichi Nakashima @deeeet tcnksm

  3. http://deeeet.com/writing

  4. YAPC::Asia Tokyo 2014 2014-08-29 14:10:00

  5. ghr dmux https://github.com/tcnksm/dmux https://github.com/tcnksm/ghr - docker + tmux = dmux

    ! - Easy to ship your project on Github to your user cli-init https://github.com/tcnksm/cli-init - TheThe easy way to start building Golang CLI docc https://github.com/tcnksm/docc - docc open your project document ⋆ 100 ⋆ 38 ⋆ 39 ⋆ 7
  6. TL;DR GoݴޠͰ࡞ͬͨCLIπʔϧΛΫʔϧʹship͠Α͏ʂ

  7. I built Cool CLI tool ! Make your life easy,

    Make you happy, Please use it !
  8. Before Golang When you create great tool, and want to

    ship it to user.
  9. Lightweight Language • Python -> pip • Ruby -> rubygems

    • Perl -> CPAN • Node -> npm
  10. Lightweight Language • pipͬͯԿʁ • CPANͬͯԿʁ • ݁ہԿΛΠϯετʔϧ͢Ε͹ྑ͍ͷʁ • Rubyݏ͍͔ͩΒ…

  11. After Golang When you create great tool, and want to

    ship it to user.
  12. Cross-Compile and Release it Download it and place it in

    your $PATH
  13. Super Easy, but • ޮ཰Α͘Cross-Compile͢Δʹ͸ʁ • ؆୯ʹϦϦʔε͢Δʹ͸ʁͲ͜ʹϗετ͢Ε͹͍͍ͷʁ • ؆୯ͳΠϯετʔϧํ๏Λఏڙ͢Δʹ͸ʁ

  14. Cross-Compiling generate binaries for multiple platform 

  15. Tools • davecheney/golang-crosscompile • bash࣮૷ • laher/goxc • ߴػೳ (ύοέʔδϯά,

    bintray΁ͷΞοϓϩʔυ…) • mitchellh/gox • γϯϓϧ, ฒྻ࣮ߦ
  16. $ GOOS=linux GOARCH=amd64 go build awesome-tool.go

  17. $ gox ! --> darwin/386: github.com/tcnksm/awesome --> darwin/amd64: github.com/tcnksm/awesome -->

    linux/386: github.com/tcnksm/awesome --> linux/amd64: github.com/tcnksm/awesome --> linux/arm: github.com/tcnksm/awesome --> freebsd/386: github.com/tcnksm/awesome --> freebsd/amd64: github.com/tcnksm/awesome --> openbsd/386: github.com/tcnksm/awesome
  18. $ gox \ -os="darwin linux windows" \ -arch="386 amd64" \

    -output "pkg/{{.OS}}_{{.Arch}}/{{.Dir}} " !
  19. Releasing Upload artifacts on Github bintray.com, Drone.io

  20. Hosting Services

  21. $ echo “Releasing bintray with API” ! $ curl -T

    ${FILE.EXT} \ -u${USER}:${API_KEY} \ https://api.bintray.com/content/${USER}/${NAME}/${FILE}
  22. https://bintray.com/tcnksm/dmux/dmux/0.1.0/view/files

  23. $ echo “Releasing Github with API” ! $ curl -X

    POST -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token ${GITHUB_TOKEN}" \ -H "Content-Type: ${CONTENT_TYPE}" \ --data-binary @“${ARCHIVE}" \ https://uploads.github.com/repos/${OWNER}/${REPO}/ releases/${RELEASE_ID}/assets?name=${ARCHIVE_NAME} \
  24. https://github.com/tcnksm/ghr/releases

  25. ghr https://github.com/tcnksm/ghr - Easy to ship your project on Github

    to your user
  26. $ ghr v0.1.0 pkg/ ! --> Uploading: pkg/0.1.0_SHASUMS --> Uploading:

    pkg/ghr_0.1.0_darwin_386.zip --> Uploading: pkg/ghr_0.1.0_darwin_amd64.zip --> Uploading: pkg/ghr_0.1.0_linux_386.zip --> Uploading: pkg/ghr_0.1.0_linux_amd64.zip --> Uploading: pkg/ghr_0.1.0_windows_386.zip --> Uploading: pkg/ghr_0.1.0_windows_amd64.zip
  27. Release with CI-as-a-Service CI-as-a-ServiceͰςετͷ௨ͬͨ΋ͷΛίϯύΠϧͯ͠ Github΍bintray, Drone.ioʹϦϦʔε͢Δ

  28. developer Wercker Ͱ Go ͷϓϩδΣΫτΛΫϩείϯύΠϧ͠ɺGitHub ʹϦϦʔε͢Δ http://motemen.hatenablog.com/entry/2014/06/27/xcompile-go-and-release-to-github-with-wercker

  29. developer Wercker Ͱ Go ͷϓϩδΣΫτΛΫϩείϯύΠϧ͠ɺGitHub ʹϦϦʔε͢Δ http://motemen.hatenablog.com/entry/2014/06/27/xcompile-go-and-release-to-github-with-wercker git push

  30. developer Wercker Ͱ Go ͷϓϩδΣΫτΛΫϩείϯύΠϧ͠ɺGitHub ʹϦϦʔε͢Δ http://motemen.hatenablog.com/entry/2014/06/27/xcompile-go-and-release-to-github-with-wercker git push hook

  31. developer Wercker Ͱ Go ͷϓϩδΣΫτΛΫϩείϯύΠϧ͠ɺGitHub ʹϦϦʔε͢Δ http://motemen.hatenablog.com/entry/2014/06/27/xcompile-go-and-release-to-github-with-wercker git push hook

    Test & Cross-Compile
  32. developer Wercker Ͱ Go ͷϓϩδΣΫτΛΫϩείϯύΠϧ͠ɺGitHub ʹϦϦʔε͢Δ http://motemen.hatenablog.com/entry/2014/06/27/xcompile-go-and-release-to-github-with-wercker git push hook

    Release ! Test & Cross-Compile
  33. Downloading Give more easy way to install your tool

  34. Download and place it in $PATH ! े෼͕ͩϢʔβʹͱͬͯ͸ΊΜͲ͍͘͞ɽ ΋ͬͱ؆୯ʹπʔϧΛΠϯετʔϧ͢ΔͨΊͷखஈΛఏڙ͍ͨ͠ɽ Ϣʔβ͕πʔϧΛ࢖͍࢝ΊΔ·ͰͷোนΛԼ͛Α͏ʂ

  35. Package manager? • OSX → Homebrew • Debian→ Deb package

    • RedHat → RPM package
  36. Redirect distribution pattern • heroku/hk • flynn/flynn-cli

  37. $ L=/usr/local/bin/hk && curl -sL -A "`uname -sp`" https:// hk.heroku.com/hk.gz

    | zcat >$L && chmod +x $L
  38. user HerokuͱGithubΛ࢖ͬͨ౷Ұతͳπʔϧ഑෍ http://deeeet.com/writing/2014/08/07/github-heroku-dist/

  39. user • darwin_386.zip • darwin_amd64.zip • linux_386.zip • linux_amd64.zip …

    HerokuͱGithubΛ࢖ͬͨ౷Ұతͳπʔϧ഑෍ http://deeeet.com/writing/2014/08/07/github-heroku-dist/
  40. user curl -sL -A `uname -sp` HerokuͱGithubΛ࢖ͬͨ౷Ұతͳπʔϧ഑෍ http://deeeet.com/writing/2014/08/07/github-heroku-dist/ • darwin_386.zip

    • darwin_amd64.zip • linux_386.zip • linux_amd64.zip …
  41. user curl -sL -A `uname -sp` Detect platform HerokuͱGithubΛ࢖ͬͨ౷Ұతͳπʔϧ഑෍ http://deeeet.com/writing/2014/08/07/github-heroku-dist/

    • darwin_386.zip • darwin_amd64.zip • linux_386.zip • linux_amd64.zip …
  42. user curl -sL -A `uname -sp` redirect Detect platform HerokuͱGithubΛ࢖ͬͨ౷Ұతͳπʔϧ഑෍

    http://deeeet.com/writing/2014/08/07/github-heroku-dist/ • darwin_386.zip • darwin_amd64.zip • linux_386.zip • linux_amd64.zip …
  43. user curl -sL -A `uname -sp` redirect package Detect platform

    HerokuͱGithubΛ࢖ͬͨ౷Ұతͳπʔϧ഑෍ http://deeeet.com/writing/2014/08/07/github-heroku-dist/ • darwin_386.zip • darwin_amd64.zip • linux_386.zip • linux_amd64.zip …
  44. re-dist-ghr https://github.com/tcnksm/re-dist-ghr - Redirect installation for ghr

  45. require "formula" ! class Ghr < Formula homepage "https://github.com/tcnksm/ghr" version

    'v0.1.1' url "https://github.com/tcnksm/ghr/releases/download/v0.1.1/ghr_v0.1.1_darwin_amd64.zip" sha1 “e5c793001f004b670df77cb57bc033c89201b485" ! depends_on :arch => :intel ! def install bin.install 'ghr' end end $ cat homebrew-ghr/ghr.rb
  46. $ brew tap tcnksm/ghr $ brew install ghr

  47. Demo