LoginSignup
1
1

More than 5 years have passed since last update.

Elasticsearch::Extensionsを用いたテスト on CircleCI

Last updated at Posted at 2016-07-17

やりたいこと

CI上のデフォルトバージョンのESでテストする

スクリーンショット 2016-07-17 23.39.52.png

まさにこれ。
CI上のデフォルトバージョンのESでテストをする。※理由は割愛
少し手こずったので備忘録として掲載。

特定のバージョンのESのテストは

だいたいググると、
Install a custom version of Elasticsearch とかCircleCI上でElasticsearchを設定するとか見つかるがいずれも、

いずれも、用途が

If you need a custom version, you can download and start it from your build

で今回のスコープからは外れるため、割愛。

手こずった点

で、いくらcircle.ymlに上記の設定をしても、CIでのrspec実行で

spec/support/elacticsearch.rb
RSpec.configure do |config|
  config.before(:all, :elasticsearch) do 
    WebMock.disable_net_connect!(allow_localhost: true)
    Elasticsearch::Extensions::Test::Cluster.start port: 9250 unless Elasticsearch::Extensions::Test::Cluster.running?(on: 9250)↲# ここで起動するはずだが。。。
  end

  config.after(:all, :elasticsearch) do 
    Elasticsearch::Extensions::Test::Cluster.stop port: 9250 if Elasticsearch::Extensions::Test::Cluster.running?(on: 9250)
  end
end

 。。。TEST::Clusterの起動ができない

CIでは、
スクリーンショット 2016-07-17 23.50.45.png

となる。ローカルでは動くのに。。。

という状態。

原因

ESの実行ファイルをつかめていないことが原因でした。
言い換えると、ローカル環境では、任意でインストーるしたESの実行ファイルに パスを通していたため、実行ができていた。

local
$ ll /usr/local/bin/elasticsearch 
/usr/local/bin/elasticsearch -> /usr/local/src/elasticsearch-2.3.4/bin/elasticsearch

circle ci でのESの実行ファイルはどこ?

ローカルとか 任意バージョンのダウンロード だと、インストーる場所がわかるため、 
TEST_CLUSTER_COMMANDに実行ファイルパスを指定することが可能。

だが、今回のようにCIのデフォのESの場合はその所在がわからなかったため、
CIのコンテナにSSHで入って、検索して発見。
/usr/share/elasticsearch/bin/elasticsearch

にありました。
ので、これを、 circle.ymlに設定して、無事に動きました。

スクリーンショット 2016-07-18 07.52.04.png

所感

ciって...
ubuntu使ってたんすね。
そして、自分はもっぱらcentosだったので、実行ファイルの検討がつきませんでしたが、まぁそこはgrep でなんとか。

ref

1
1
0

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
1
1