1 他人が作ったEmbulkプラグインを動かしたい。
こんなプラグインを動かしたくなった時(主にRubyプラグインの場合)
- 他の人が作ったEmbulkプラグインを動かしたい。
- rubygems.orgにはアップロードされていない社内用のプラグインでgemになっていたい。
そんなお話がありました。いつか他の人に使うかもしれないので、
https://twitter.com/m_norii/status/1235816900094865410?s=20
2 理解までのステップ
2.1 お試し実行の仕組みを知る
- embulk のプラグイン開発時にお試し実行するには を読みましょう
2.2 ライブラリに依存しないRubyプラグインを動かしてみる
以下を実行してみましょう
git clone https://github.com/kumagi/embulk-input-random
config.yml
in:
type: random
rows: 100
threads: 2
schema:
myid: primary_key
name: string
score: integer
out:
type: stdout
embulk run -I embulk-input-random/lib config.yml
2.3 Rubyの依存ライブラリがあるプラグインを動かしてみる
cd /tmp
embulk mkbundle sisimai_bundle
cd sisimai_bundle
Gemfileにgem 'sisimai', '~> 4.16'
を追加
source 'https://rubygems.org/'
# No versions are specified for 'embulk' to use the gem embedded in embulk.jar.
# Note that prerelease versions (e.g. "0.9.0.beta") do not match the statement.
# Specify the exact prerelease version (like '= 0.9.0.beta') for prereleases.
gem 'embulk'
gem 'sisimai', '~> 4.16'
#
# 1. Use following syntax to specify versions of plugins
# to install this bundle directory:
#
# gem 'embulk-output-mysql' # the latest version
# gem 'embulk-input-baz', '= 0.2.0' # specific version
# gem 'embulk-input-xyz', '~> 0.3.0' # latest major version
# gem 'embulk-output-postgresql', '>= 0.1.0' # newer than specific version
#
# gem 'embulk-output-awesome', git: 'https://github.com/you/embulk-output-awesome.git', branch: 'master'
#
#
# 2. When you modify this file, run following command to
# install plugins:
#
# $ cd this_directory
# $ embulk bundle
#
#
# 3. Then you can use plugins with -b, --bundle BUNDLE_PATH command:
#
# $ embulk guess -b path/to/this/directory ...
# $ embulk run -b path/to/this/directory ...
# $ embulk preview -b path/to/this/directory ...
#
embulk bundle
cd /tmp
git clone https://github.com/hiroyuki-sato/embulk-parser-sisimai.git
cd embulk-parser-sisimai
embulk run -I lib -b /tmp/sisimai_bundle example/conf_json.yml
2.3.1 -bをつけた場合
embulk run -I lib -b /tmp/sisimai_bundle example/conf_json.yml
{"catch":"","token":"1e86ae85ee6075211a5cb514c312c5a89193268d","lhost":"192.0.2.31","rhost":"mfsmax.docomo.ne.jp","alias":"","listid":"","reason":"userunknown","action":"failed","subject":"キジトラ","messageid":"E9E9449A-4918-4B8B-8589-435230D67AC7@example.jp","replycode":"550","smtpagent":"Email::Sendmail","softbounce":0,"smtpcommand":"DATA","destination":"docomo.ne.jp","senderdomain":"example.jp","feedbacktype":"","diagnosticcode":"550 Unknown user recipient-address-does-not-exist@docomo.ne.jp 503 Bad sequence of commands","diagnostictype":"SMTP","deliverystatus":"5.1.1","timezoneoffset":"+0900","addresser":"user2@example.jp","recipient":"recipient-address-does-not-exist@docomo.ne.jp","timestamp":1240874268}
{"catch":"","token":"d059e55e074333fe59001b1d30d27da85a1a9c1d","lhost":"192.0.2.97","rhost":"example.gov","alias":"","listid":"","reason":"hostunknown","action":"failed","subject":"キジトラ","messageid":"AA406E7E18714AB2927DAACC24B47C4A@USER-PC97","replycode":"550","smtpagent":"Email::Sendmail","softbounce":0,"smtpcommand":"","destination":"example.gov","senderdomain":"example.jp","feedbacktype":"","diagnosticcode":"550 Host unknown","diagnostictype":"SMTP","deliverystatus":"5.1.2","timezoneoffset":"+0900","addresser":"user1@example.jp","recipient":"domain-does-not-exist@example.gov","timestamp":1221728044}
2.3.2 -bをつけない場合
embulk run -I lib example/conf_json.yml
LoadError: no such file to load -- sisimai
require at org/jruby/RubyKernel.java:955
require at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:120
2.3.3 補足
Gemspecの中に以下のようにadd_dependencyが書かれている場合は、関連するライブラリの導入が必要
spec.add_dependency 'sisimai', ['~> 4.16']
導入方法は次のとおりです
- embulk gemであらかじめインストールをしておく
- embulk mkbundleをして、関連するライブラリを入れておく
2.3.4 補足2
embulk-parser-sisimaiの場合以下のようにすると、上記のembulk gemであらかじめインストールする方法と同じ作業を行うことができる
その場合-bをつけなくても実行ができるようになる
cd /tmp/embulk-parser-sisimai
embulk bundle
embulk gem list
...
sisimai (4.25.5 java)
embulk run -I lib example/conf_json.yml
2.4 bundlerの実行に失敗する
LoadError: no such file to load -- bundler/dep_proxy
こんなエラーが出た時は
embulk gem install bundler
を実行してみましょう