LoginSignup
5
3

More than 5 years have passed since last update.

DigdagでRubyのBundlerを使う

Last updated at Posted at 2016-07-15

JRubyじゃないよ

Digdagのコードを追っていくとRbOperatorFactory.RbOperator#runTask()でRubyスクリプトを実行しています.
具体的にはProcessBuilderを使っています.

システムの環境変数を見てrubyコマンドを実行しています.

Tokyo Ruby会議#11 ワークフローエンジンDigdagのまとめ - Qiitaのビデオを見たときRuby使えると聞いて勝手にJRubyだろうなとか思ってました. :astonished:

Digdagのワークフローの仕組み

  • digdag pushをすると
  • アーカイブが作成されてそれがDigdag serverに送られる
  • ワークフローを実行するとき
    • テンポラリディレクトリに展開される
    • ワークフロー実行されます

Bundlerを使う

では本題のBundlerを使う方法です.
Digdagの仕組みをある程度知った上でBundlerを使う方法は幾つかあると思います.

bundler/inlineを使用する :star2:

以下のような感じでスクリプト内にGemfile相当のものが書けます.
調べた限りではGemfile.lock相当はありませんでした.

#!/usr/bin/env ruby

require 'bundler/inline'

# 第1引数をtrueとするとbundle install相当をしてくれます.
gemfile(true) do
  source 'https://rubygems.org'
  gem 'json', require: false
  gem 'nap', require: 'rest'
  gem 'cocoapods', '~> 0.34.1'
end

pathオプションを使用する

  • Bundlerが入っている場合
    • プロジェクト内にライブラリを入れる
    • bundle install --path vendor/bundler

standaloneオプションを使用する

  • Bundlerが入っていない場合
    • スタンドアロンのオプションを有効にする.
    • bundle install --standalone
    • Rubyスクリプトにrequireを追記
      • require './bundle/bundler/setup'

pathstandaloneは、ワークフローのアーカイブに含まれるので色々依存しすぎると、アーカイブでディスクを圧迫したり、展開に時間がかかったりするのでほどほどにしましょう.

5
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3