Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Ship your CLI tool built by golang to your user...
Search
taichi nakashima
August 09, 2014
7k
11
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ship your CLI tool built by golang to your user #golangstudy
http://connpass.com/event/7814/
taichi nakashima
August 09, 2014
Transcript
47 slides
Ship your CLI tool built by Golang: Compile, Release, Downloading
http://wallbase.cc/wallpaper/1950578
I’m Taichi Nakashima @deeeet tcnksm
http://deeeet.com/writing
YAPC::Asia Tokyo 2014 2014-08-29 14:10:00
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
TL;DR GoݴޠͰ࡞ͬͨCLIπʔϧΛΫʔϧʹship͠Α͏ʂ
I built Cool CLI tool ! Make your life easy,
Make you happy, Please use it !
Before Golang When you create great tool, and want to
ship it to user.
Lightweight Language • Python -> pip • Ruby -> rubygems
• Perl -> CPAN • Node -> npm
Lightweight Language • pipͬͯԿʁ • CPANͬͯԿʁ • ݁ہԿΛΠϯετʔϧ͢Εྑ͍ͷʁ • Rubyݏ͍͔ͩΒ…
After Golang When you create great tool, and want to
ship it to user.
Cross-Compile and Release it Download it and place it in
your $PATH
Super Easy, but • ޮΑ͘Cross-Compile͢Δʹʁ • ؆୯ʹϦϦʔε͢ΔʹʁͲ͜ʹϗετ͢Ε͍͍ͷʁ • ؆୯ͳΠϯετʔϧํ๏Λఏڙ͢Δʹʁ
Cross-Compiling generate binaries for multiple platform
Tools • davecheney/golang-crosscompile • bash࣮ • laher/goxc • ߴػೳ (ύοέʔδϯά,
bintrayͷΞοϓϩʔυ…) • mitchellh/gox • γϯϓϧ, ฒྻ࣮ߦ
$ GOOS=linux GOARCH=amd64 go build awesome-tool.go
$ 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
$ gox \ -os="darwin linux windows" \ -arch="386 amd64" \
-output "pkg/{{.OS}}_{{.Arch}}/{{.Dir}} " !
Releasing Upload artifacts on Github bintray.com, Drone.io
Hosting Services
$ echo “Releasing bintray with API” ! $ curl -T
${FILE.EXT} \ -u${USER}:${API_KEY} \ https://api.bintray.com/content/${USER}/${NAME}/${FILE}
https://bintray.com/tcnksm/dmux/dmux/0.1.0/view/files
$ 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} \
https://github.com/tcnksm/ghr/releases
ghr https://github.com/tcnksm/ghr - Easy to ship your project on Github
to your user
$ 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
Release with CI-as-a-Service CI-as-a-ServiceͰςετͷ௨ͬͨͷΛίϯύΠϧͯ͠ Githubbintray, Drone.ioʹϦϦʔε͢Δ
developer Wercker Ͱ Go ͷϓϩδΣΫτΛΫϩείϯύΠϧ͠ɺGitHub ʹϦϦʔε͢Δ http://motemen.hatenablog.com/entry/2014/06/27/xcompile-go-and-release-to-github-with-wercker
developer Wercker Ͱ Go ͷϓϩδΣΫτΛΫϩείϯύΠϧ͠ɺGitHub ʹϦϦʔε͢Δ http://motemen.hatenablog.com/entry/2014/06/27/xcompile-go-and-release-to-github-with-wercker git push
developer Wercker Ͱ Go ͷϓϩδΣΫτΛΫϩείϯύΠϧ͠ɺGitHub ʹϦϦʔε͢Δ http://motemen.hatenablog.com/entry/2014/06/27/xcompile-go-and-release-to-github-with-wercker git push hook
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
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
Downloading Give more easy way to install your tool
Download and place it in $PATH ! े͕ͩϢʔβʹͱͬͯΊΜͲ͍͘͞ɽ ͬͱ؆୯ʹπʔϧΛΠϯετʔϧ͢ΔͨΊͷखஈΛఏڙ͍ͨ͠ɽ Ϣʔβ͕πʔϧΛ͍࢝ΊΔ·ͰͷোนΛԼ͛Α͏ʂ
Package manager? • OSX → Homebrew • Debian→ Deb package
• RedHat → RPM package
Redirect distribution pattern • heroku/hk • flynn/flynn-cli
$ L=/usr/local/bin/hk && curl -sL -A "`uname -sp`" https:// hk.heroku.com/hk.gz
| zcat >$L && chmod +x $L
user HerokuͱGithubΛͬͨ౷Ұతͳπʔϧ http://deeeet.com/writing/2014/08/07/github-heroku-dist/
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/
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 …
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 …
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 …
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 …
re-dist-ghr https://github.com/tcnksm/re-dist-ghr - Redirect installation for ghr
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
$ brew tap tcnksm/ghr $ brew install ghr
Demo
More Decks by taichi nakashima
See All by taichi nakashima
Platform Engineering at Mercari (Platform Engineering Kaigi 2024)
tcnksm
6
5.9k
Platform Engineering at Mercari
tcnksm
8
6.1k
Embedded SRE at Mercari
tcnksm
0
1.6k
How We Harden Platform Security at Mercari
tcnksm
2
2k
SRE Practices in Mercari Microservices
tcnksm
11
15k
開発者向けの基盤をつくる
tcnksm
38
12k
How We Structure Our Work At Mercari Microservices Platform Team
tcnksm
11
24k
Microservices Platform on Kubernetes at Mercari
tcnksm
16
17k
Introduction to Mercari Micorservices Platform Team
tcnksm
5
3.8k
Featured
See All Featured
Building an army of robots
kneath
307
47k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
Ethics towards AI in product and experience design
skipperchong
2
470
RailsConf 2023
tenderlove
30
1.6k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.2k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
290
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
2
530
SEO for Brand Visibility & Recognition
aleyda
0
4.9k
Making Projects Easy
brettharned
120
6.9k