Upgrade to Pro — share decks privately, control downloads, hide ads and more …

メジャーな Live Reloaderの違いをちゃんと調べて見た / Compare major live reloader of Go

yudppp
December 18, 2018

メジャーな Live Reloaderの違いをちゃんと調べて見た / Compare major live reloader of Go

メジャーな Live Reloader(gin/fresh/realize)の違いをちゃんと調べて見た 。
golang.tokyo #20 忘年LT大会!!の資料。

yudppp

December 18, 2018
Tweet

More Decks by yudppp

Other Decks in Technology

Transcript

  1. メジャーな
    Live Reloaderの違いを
    ちゃんと調べて⾒た
    golang.tokyo #20 忘年LT⼤会!!

    View Slide

  2. ⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved
    ⾃⼰紹介
    • yudppp - 株式会社HRBrain CTO
    • 好きな⾔葉: 冪等性
    • 好きなキーボード: HHKB
    • Corne Cherry配送待ち
    • Go歴 4年
    • ○△□ - https://blog.yudppp.com/

    View Slide

  3. ⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved
    HRBrainとは
    煩雑で不透明になりがちだった⽬標・評価管理のプロセスを
    ⼀気通貫で効率化・⾒える化するクラウド型ソフトウェア
    「⼈事評価を最もカンタン・シンプルに」

    View Slide

  4. ⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved
    HRBrainの開発環境について
    • サーバーサイドは全てGoで実装
    • docker-compose upでapp本体と関連サービスのモックを含めて全て⽴
    ち上がる。
    • 存在しないモックは⾃作する(yudppp/simple-sendgrid-mock-
    server)
    • Dockerのvolumeを使ってlocalのFileを更新したらコンテナ内のFileが更
    新される。

    その時に⾃動でサーバーを再起動させる。 ←今回はこの話

    View Slide

  5. ⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved
    Live Reloadとは
    • ファイルの変更を検知して、⾃動でなにかを再実⾏する。
    • Hot Reload/Auto Reloadなどは多分ほぼ同義。
    • GoにおけるLive Reloadとはファイルの変更を検知して、⾃動で再Buildを
    ⾏う

    View Slide

  6. ⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved
    特に有名なlibrary
    • codegangsta/gin - ★2,793
    • gravityblast/fresh - ★1,856
    • oxequa/realize - ★2,657
    • 他にも存在はしたが、Starが1,000を超えていたのはこれだけだったので
    これらの⽐較をしていく。

    View Slide

  7. ⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved
    codegangsta/gin
    • FirstCommit: Jul 21, 2013
    • ちなみによく紛らわしがられるgin-gonic/ginは Jun 15, 2014

    View Slide

  8. ⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved
    gravityblast/fresh
    • FirstCommit: Jan 12, 2014

    View Slide

  9. ⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved
    oxequa/realize
    • FirstCommit: Jul 10, 2016

    View Slide

  10. 正直この時点で
    最終更新が近くコミットの多い
    realize⼀択な気がしますが、
    詳細機能みてきます。

    View Slide

  11. ⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved
    codegangsta/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

    View Slide

  12. ⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved
    gravityblast/fresh
    • fresh -c runner.conf とrootDirectory以外に動かしたい場合はconfigファ
    イルが必要
    root: .
    tmp_path: ./tmp
    build_name: runner-build
    build_log: runner-build-errors.log
    valid_ext: .go, .tpl, .tmpl, .html
    no_rebuild_ext: .tpl, .tmpl, .html
    ignored: assets, tmp
    build_delay: 600
    colors: 1
    log_color_main: cyan
    log_color_build: yellow
    log_color_runner: green
    log_color_watcher: magenta
    log_color_app:

    View Slide

  13. ⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved
    oxequa/realize
    • 基本的には.realize.yaml のconfigファイルを使うが--no-config のオプ
    ションを渡すとある程度のことをcliでできる。
    settings:
    legacy:
    force: true // force polling watcher instead fsnotifiy
    interval: 100ms // polling interval
    resources: // files names
    outputs: outputs.log
    logs: logs.log
    errors: errors.log
    server:
    status: false // server status
    open: false // open browser at start
    host: localhost // server host
    port: 5001 // server port
    schema:
    - name: coin
    path: coin // project path
    env: // env variables available at startup
    test: test
    myvar: value
    commands: // go commands supported
    vet:
    status: true
    fmt:
    status: true
    args:
    - -s
    - -w
    test:
    status: true
    method: gb test // support different build tools
    generate:
    status: true
    install:
    status: true
    build:
    status: false
    method: gb build // support differents build tool
    args: // additional params for the command
    - -race
    run:
    status: true
    args: // arguments to pass at the project
    - --myarg
    watcher:
    paths: // watched paths
    - /
    ignore_paths: // ignored paths
    - vendor
    extensions: // watched extensions
    - go
    - html
    scripts:
    - type: before
    command: echo before global
    global: true
    output: true
    - type: before
    command: echo before change
    output: true
    - type: after
    command: echo after change
    output: true
    - type: after
    command: echo after global
    global: true
    output: true
    errorOutputPattern: mypattern //custom error pattern

    View Slide

  14. みるからに設定できる項⽬が多い

    View Slide

  15. ⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved
    realizeだけで実現できること
    • 複数のプロジェクトを⼀つのコマンドで実⾏できる
    • ファイル変更検知のPoling実⾏
    • reload時のbefore/afterにevent hookが仕掛けられる
    • Web上でログやstatusの表⽰
    • 環境変数の設定

    View Slide

  16. ⼈事評価を最もカンタン・シンプルに Copyright©HRBrain, Inc. All Rights Reserved
    ⾃分はこれからなにを使うか
    • Docker内で動かしたいならrealize
    • しっかりプロダクトの開発環境に取り込む場合はrealize
    • 簡単なツールでさっと⾏いたい場合はgin
    • 迷ったらrealize!

    View Slide

  17. View Slide