Slide 1

Slide 1 text

Ship your CLI tool built by Golang: Compile, Release, Downloading http://wallbase.cc/wallpaper/1950578

Slide 2

Slide 2 text

I’m Taichi Nakashima @deeeet tcnksm

Slide 3

Slide 3 text

http://deeeet.com/writing

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

TL;DR GoݴޠͰ࡞ͬͨCLIπʔϧΛΫʔϧʹship͠Α͏ʂ

Slide 7

Slide 7 text

I built Cool CLI tool ! Make your life easy, Make you happy, Please use it !

Slide 8

Slide 8 text

Before Golang When you create great tool, and want to ship it to user.

Slide 9

Slide 9 text

Lightweight Language • Python -> pip • Ruby -> rubygems • Perl -> CPAN • Node -> npm

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

After Golang When you create great tool, and want to ship it to user.

Slide 12

Slide 12 text

Cross-Compile and Release it Download it and place it in your $PATH

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Cross-Compiling generate binaries for multiple platform 

Slide 15

Slide 15 text

Tools • davecheney/golang-crosscompile • bash࣮૷ • laher/goxc • ߴػೳ (ύοέʔδϯά, bintray΁ͷΞοϓϩʔυ…) • mitchellh/gox • γϯϓϧ, ฒྻ࣮ߦ

Slide 16

Slide 16 text

$ GOOS=linux GOARCH=amd64 go build awesome-tool.go

Slide 17

Slide 17 text

$ 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

Slide 18

Slide 18 text

$ gox \ -os="darwin linux windows" \ -arch="386 amd64" \ -output "pkg/{{.OS}}_{{.Arch}}/{{.Dir}} " !

Slide 19

Slide 19 text

Releasing Upload artifacts on Github bintray.com, Drone.io

Slide 20

Slide 20 text

Hosting Services

Slide 21

Slide 21 text

$ echo “Releasing bintray with API” ! $ curl -T ${FILE.EXT} \ -u${USER}:${API_KEY} \ https://api.bintray.com/content/${USER}/${NAME}/${FILE}

Slide 22

Slide 22 text

https://bintray.com/tcnksm/dmux/dmux/0.1.0/view/files

Slide 23

Slide 23 text

$ 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} \

Slide 24

Slide 24 text

https://github.com/tcnksm/ghr/releases

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

$ 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

Slide 27

Slide 27 text

Release with CI-as-a-Service CI-as-a-ServiceͰςετͷ௨ͬͨ΋ͷΛίϯύΠϧͯ͠ Github΍bintray, Drone.ioʹϦϦʔε͢Δ

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

Downloading Give more easy way to install your tool

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

Package manager? • OSX → Homebrew • Debian→ Deb package • RedHat → RPM package

Slide 36

Slide 36 text

Redirect distribution pattern • heroku/hk • flynn/flynn-cli

Slide 37

Slide 37 text

$ L=/usr/local/bin/hk && curl -sL -A "`uname -sp`" https:// hk.heroku.com/hk.gz | zcat >$L && chmod +x $L

Slide 38

Slide 38 text

user HerokuͱGithubΛ࢖ͬͨ౷Ұతͳπʔϧ഑෍ http://deeeet.com/writing/2014/08/07/github-heroku-dist/

Slide 39

Slide 39 text

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/

Slide 40

Slide 40 text

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 …

Slide 41

Slide 41 text

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 …

Slide 42

Slide 42 text

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 …

Slide 43

Slide 43 text

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 …

Slide 44

Slide 44 text

re-dist-ghr https://github.com/tcnksm/re-dist-ghr - Redirect installation for ghr

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

$ brew tap tcnksm/ghr $ brew install ghr

Slide 47

Slide 47 text

Demo