実践Go - ツールの作成から配布まで

実践Go - ツールの作成から配布まで

Fukuoka.go#2の資料です
http://connpass.com/event/7559/

Cd3d2cb2dadf5488935fe0ddaea7938a?s=128

monochromegane

August 22, 2014
Tweet

Transcript

  1. πʔϧͷ࡞੒͔Β഑෍·Ͱ Fukuoka.go#2 @monochromegane ࣮ફ Go!

  2. MIYAKE Yusuke (@monochromegane)

  3. GMO Pepabo, Inc.

  4. pt The Platinum Searcher

  5. ෺ൢ͸͡Ί·ͨ͠

  6. πʔϧͷ࡞੒͔Β഑෍·Ͱ

  7. πʔϧͷ࡞੒͔Β഑෍·Ͱ

  8. ͭͬͯ͘ΈΔ

  9. ʕ◔ϖ◔ʔ < Go! $ go run xxx.go # ίϯύΠϧ&࣮ߦ(mainؔ਺ΛؚΉgoϑΝΠϧΛࢦఆ) $

    go test ./... # ͢΂ͯͷύοέʔδͷςετΛ࣮ߦ $ go build # ίϯύΠϧ
  10. github.com/user/ src/ cmd/go-ls/ main.go # mainύοέʔδ go-ls.go # ࣗ࡞ύοέʔδ •

    go get ͞Εͨ৔߹ͷߏ੒ͱͳΔ$GOPATH/ϦϙδτϦ/Ϣʔ β/srcͷߏ੒ʹ͋Θ͓ͤͯ͘ͱimportͰͭ·͔ͮͳ͍ • mainύοέʔδ͸CLIͷΤϯτϦϙΠϯτͱͯ͠ίϚϯυϥ ΠϯҾ਺ͷղੳͱࣗ࡞ύοέʔδͷݺͼग़͠Λߦ͏ • ͜ΕʹΑΓɺࣗ࡞ύοέʔδͷػೳ͕֎෦ύοέʔδ͔Βར ༻͠΍͘͢ͳΔ ʕ◔ϖ◔ʔ < Go!
  11. πʔϧͷ࡞੒͔Β഑෍·Ͱ

  12. Local

  13. OR $ go build -o $PATH/xxx $ go install packge_name

  14. bin/ go-ls # ࣮ߦίϚϯυ (mainύοέʔδ) pkg/ darwin_amd64/ # ΞʔΩςΫνϟ github.com/user/

    go-ls.a # ύοέʔδΦϒδΣΫτ (ࣗ࡞ύοέʔδ) • go install͸src഑Լ͔ΒύοέʔδΛ୳ͯ͠ίϯύΠϧ͢Δ ʕ◔ϖ◔ʔ < Go!
  15. ͞Έ͠͞…

  16. ΈΜͳʹ ࢖ͬͯ΋Β͓͏ Have a try !

  17. go get

  18. $ go get \ github.com/user/package_name • go get ͸ src഑ԼʹϦϙδτϦ͔ΒιʔεΛऔಘޙɺίϯύ

    ΠϧΛߦ͏
  19. Go։ൃ؀ڥ͕ ͳ͍ͻͱʹ΋ ࢖ͬͯ΋Β͓͏

  20. Homebrew

  21. $ brew tap user/formula $ brew install formula • ಠࣗformulaΛͭͬͯ͘ɺtapͰ௥Ճ͢Δ

    • ґଘؔ܎ʹ`go`ΛೖΕ͓͚ͯ͹ɺGoͷ։ൃ؀ڥ΋Ұॹʹߏங ͯ͘͠ΕΔ
  22. require 'formula' ! HOMEBREW_PT_VERSION='1.7.1' class Pt < Formula # FormulaΫϥεΛܧঝ

    homepage 'https://github.com/monochromegane/the_platinum_searcher' url ‘https://github.com/monochromegane/the_platinum_searcher.git',\ :tag => "v#{HOMEBREW_PT_VERSION}" version HOMEBREW_PT_VERSION ! depends_on 'go' => :build # Ϗϧυ࣌ͷΈGoΛΠϯετʔϧ depends_on 'hg' => :build # ֎෦ύοέʔδ͕code.google.comͷ৔߹Mercurial͕ඞཁ ! def install ENV['GOPATH'] = buildpath system 'go', 'get', ‘github.com/jessevdk/go-flags' mkdir_p buildpath/'src/github.com/monochromegane' ln_s buildpath, buildpath/'src/github.com/monochromegane/the_platinum_searcher' system 'go', 'build', '-o', 'pt', 'cmd/pt/main.go' bin.install 'pt' end end formula
  23. MacOSXҎ֎Ͱ΋ ࢖ͬͯ΋Β͓͏

  24. Cross Compile

  25. $ cd go/src $ GOOS=linux GOARCH=amd64 \ ./make.bash $ GOOS=linux

    GOARCH=amd64 \ go build • Homebrewͷ৔߹ɺ/usr/local/Cellar/go/1.3/libexec Basic
  26. ศརͳύοέʔδ ͋Γ㽂

  27. $ gox $ gox Number of parallel builds: 4 !

    --> darwin/386: go-ls --> darwin/amd64: go-ls --> linux/386: go-ls • ฒߦίϯύΠϧ • ΦϓγϣϯͰର৅OS/ARCHࢦఆՄೳ -osarch=“linux/amd64" mitchellh/gox
  28. $ goxc $ goxc ... ! [goxc:archive-tar-gz] 2014/08/10 21:35:38 Artifact(s)

    archived to /Users/miyakey/bin/go-ls- xc/snapshot/go-ls_linux_amd64.tar.gz • ίϯύΠϧ݁ՌΛѹॖͰ͖ΔͷͰɺಉ࣮͡ߦϑΝΠϧ໊ʹͰ͖Δ • ΦϓγϣϯͰର৅OS/ARCHࢦఆՄೳ -bc="linux,!arm darwin" laher/goxc
  29. μ΢ϯϩʔυͯ͠ ࢖ͬͯ΋Β͓͏

  30. Drone.io

  31. http://icons8.com/ push configure hook Docker Images build & test Docker

    Container deploy download heroku, Dotcloud, GAE, S3, SSH C, C++, Dart, Go, Haskell, Groovy, Java, Node.js, PHP, Python, Ruby, Scala
  32. • Drone.ioͰ͸Ϗϧυ੒Ռ෺Λμ΢ϯϩʔυͯ͠΋Β ͏ͨΊɺArtifactsͱ͍͏ػೳ͕͋Δ • Artifactsʹࢦఆͨ͠σΟϨΫτϦʹϏϧυ੒Ռ෺Λ ίϐʔ͢Δ͚ͩ • ੈ୅؅ཧ͸ߦ͑ͳ͍ Artifacts

  33. Wercker

  34. http://icons8.com/ push configure hook Boxes build & test Box deploy

    download heroku, OpenShift, Amazon, RackSpace, DigitalOcean Node.js, Ruby, Python, PHP, Go, Java/Android GitHub releases
  35. • Werckerʹ͸ɺGitHubͷϦϦʔε࡞੒ͱϦϦʔε΁ ͷࢿ࢈ΞοϓϩʔυΛߦ͏Step͕͋ΔͷͰ͜ΕΛར ༻͢Δ • GitHubͷTokenͳͲ͸WerckerଆʹVariableͱͯ͠ ఆٛ͢Δ GitHub releases

  36. ͓·͚

  37. require 'formula' ! HOMEBREW_PT_VERSION='1.7.1' class Pt < Formula homepage 'https://github.com/monochromegane/the_platinum_searcher'

    url "https://github.com/monochromegane/the_platinum_searcher/ releases/download/v#{HOMEBREW_PT_VERSION}/pt_darwin_amd64.zip" sha1 '00844c339ca864bdae77fe4481a103456760181e' ! version HOMEBREW_PT_VERSION def install bin.install 'pt' end end formula • URLࢦఆͰzipϑΝΠϧΛࢦఆ͢ΔͱίϯύΠϧࡁΈͷϑΝΠ ϧ͔ΒΠϯετʔϧͰ͖ͯΠϯετʔϧ࣌ؒΛ୹ॖͰ͖Δ
  38. એ఻ ϖύϘͰ͸ΤϯδχΞΛืू͍ͯ͠·͢ɻ ڞʹαʔϏεΛੜΈग़͠ҭͯͯ͘ΕΔ৽͍͠஥ؒ Λ଴͍ͬͯ·͢ɻ ! http://pepabo.com/recruit/career/engineer/

  39. ͓ΘΓ