メジャーな Live Reloader(gin/fresh/realize)の違いをちゃんと調べて見た 。 golang.tokyo #20 忘年LT大会!!の資料。
メジャーなLive Reloaderの違いをちゃんと調べて⾒たgolang.tokyo #20 忘年LT⼤会!!
View Slide
⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved⾃⼰紹介• yudppp - 株式会社HRBrain CTO• 好きな⾔葉: 冪等性• 好きなキーボード: HHKB• Corne Cherry配送待ち• Go歴 4年• ○△□ - https://blog.yudppp.com/
⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights ReservedHRBrainとは煩雑で不透明になりがちだった⽬標・評価管理のプロセスを⼀気通貫で効率化・⾒える化するクラウド型ソフトウェア「⼈事評価を最もカンタン・シンプルに」
⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights ReservedHRBrainの開発環境について• サーバーサイドは全てGoで実装• docker-compose upでapp本体と関連サービスのモックを含めて全て⽴ち上がる。• 存在しないモックは⾃作する(yudppp/simple-sendgrid-mock-server)• Dockerのvolumeを使ってlocalのFileを更新したらコンテナ内のFileが更新される。 その時に⾃動でサーバーを再起動させる。 ←今回はこの話
⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights ReservedLive Reloadとは• ファイルの変更を検知して、⾃動でなにかを再実⾏する。• Hot Reload/Auto Reloadなどは多分ほぼ同義。• GoにおけるLive Reloadとはファイルの変更を検知して、⾃動で再Buildを⾏う
⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved特に有名なlibrary• codegangsta/gin - ★2,793• gravityblast/fresh - ★1,856• oxequa/realize - ★2,657• 他にも存在はしたが、Starが1,000を超えていたのはこれだけだったのでこれらの⽐較をしていく。
⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reservedcodegangsta/gin• FirstCommit: Jul 21, 2013• ちなみによく紛らわしがられるgin-gonic/ginは Jun 15, 2014
⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reservedgravityblast/fresh• FirstCommit: Jan 12, 2014
⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reservedoxequa/realize• FirstCommit: Jul 10, 2016
正直この時点で最終更新が近くコミットの多いrealize⼀択な気がしますが、詳細機能みてきます。
⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reservedcodegangsta/gin• go run main.go の代わりに gin run main.goを実⾏するとLive Reloadがすぐに使える。--laddr value, -l value listening address for the proxy server--port value, -p value port for the proxy server (default: 3000)--appPort value, -a value port for the Go web server (default: 3001)--bin value, -b value name of generated binary file (default: "gin-bin")--path value, -t value Path to watch files from (default: ".")--build value, -d value Path to build files from (defaults to same value as --path)--excludeDir value, -x value Relative directories to exclude--immediate, -i run the server immediately after it's built--all reloads whenever any file changes, as opposed to reloading only on .go file change--godep, -g use godep when building--buildArgs value Additional go build arguments--certFile value TLS Certificate--keyFile value TLS Certificate Key--logPrefix value Setup custom log prefix--notifications enable desktop notifications--help, -h show help--version, -v print the version
⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reservedgravityblast/fresh• fresh -c runner.conf とrootDirectory以外に動かしたい場合はconfigファイルが必要root: .tmp_path: ./tmpbuild_name: runner-buildbuild_log: runner-build-errors.logvalid_ext: .go, .tpl, .tmpl, .htmlno_rebuild_ext: .tpl, .tmpl, .htmlignored: assets, tmpbuild_delay: 600colors: 1log_color_main: cyanlog_color_build: yellowlog_color_runner: greenlog_color_watcher: magentalog_color_app:
⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reservedoxequa/realize• 基本的には.realize.yaml のconfigファイルを使うが--no-config のオプションを渡すとある程度のことをcliでできる。settings:legacy:force: true // force polling watcher instead fsnotifiyinterval: 100ms // polling intervalresources: // files namesoutputs: outputs.loglogs: logs.logerrors: errors.logserver:status: false // server statusopen: false // open browser at starthost: localhost // server hostport: 5001 // server portschema:- name: coinpath: coin // project pathenv: // env variables available at startuptest: testmyvar: valuecommands: // go commands supportedvet:status: truefmt:status: trueargs:- -s- -wtest:status: truemethod: gb test // support different build toolsgenerate:status: trueinstall:status: truebuild:status: falsemethod: gb build // support differents build toolargs: // additional params for the command- -racerun:status: trueargs: // arguments to pass at the project- --myargwatcher:paths: // watched paths- /ignore_paths: // ignored paths- vendorextensions: // watched extensions- go- htmlscripts:- type: beforecommand: echo before globalglobal: trueoutput: true- type: beforecommand: echo before changeoutput: true- type: aftercommand: echo after changeoutput: true- type: aftercommand: echo after globalglobal: trueoutput: trueerrorOutputPattern: mypattern //custom error pattern
みるからに設定できる項⽬が多い
⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reservedrealizeだけで実現できること• 複数のプロジェクトを⼀つのコマンドで実⾏できる• ファイル変更検知のPoling実⾏• reload時のbefore/afterにevent hookが仕掛けられる• Web上でログやstatusの表⽰• 環境変数の設定
⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved⾃分はこれからなにを使うか• Docker内で動かしたいならrealize• しっかりプロダクトの開発環境に取り込む場合はrealize• 簡単なツールでさっと⾏いたい場合はgin• 迷ったらrealize!