在CircleCI中设置Elasticsearch和Ruby on Rails
我想在我的Rails应用程序中用Elasticsearch设置CircleCI。我认为配置了映像,但我如何在CI中连接它?在CircleCI中设置Elasticsearch和Ruby on Rails
到目前为止,我已经试过......
https://github.com/elastic/elasticsearch/issues/23866
错误消息
Elasticsearch::Transport::Transport::Errors::Unauthorized: [401]
圈YAML配置
version: 2
jobs:
build:
working_directory: ~/gathrly-smartforms
docker:
- image: circleci/ruby:2.4.1-node
environment:
RAILS_ENV: continous_integration
PGHOST: 127.0.0.1
PGUSER: rails_test_user
- image: circleci/postgres:9.6.3-alpine
environment:
POSTGRES_USER: rails_test_user
POSTGRES_PASSWORD: ""
POSTGRES_DB: continous_integration
- image: redis:4.0.2
- image: docker.elastic.co/elasticsearch/elasticsearch:5.4.2
steps:
- checkout
- restore_cache:
keys:
- my-application-{{ checksum "Gemfile.lock" }}
- my-application-
- save_cache:
key: rails-demo-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- run:
name: Setup Bundler and Gems
command: |
gem install bundler
gem update bundler
gem install brakeman
gem install rubocop
gem install rubocop-rspec
gem install scss_lint
gem install eslint-rails
gem install execjs
bundle config without development:test
bundle check --path=vendor/bundle || bundle install --without development test --path=vendor/bundle --jobs 4 --retry 3
- run:
name: Setup Postgres
command: |
sudo apt-get install postgresql-client
- run:
name: Setup Rails Database
command: |
RAILS_ENV=continous_integration bundle exec rake db:drop
RAILS_ENV=continous_integration bundle exec rake db:setup
- run:
name: Run Rspec
command: |
RAILS_ENV=continous_integration bundle exec rspec --format RspecJunitFormatter -o /tmp/test-results/rspec.xml
- store_test_results:
path: /tmp/test-results
弹性搜索初始化程序
官方搬运工从弹性图像配有X-包预装。
https://www.elastic.co/guide/en/elasticsearch/reference/5.4/docker.html
这意味着,你的elasticsearch实例与安全运行启用,但您似乎没有被提供任何安全证书到你elasticsearch客户端,所以当您尝试得到一个未经授权的(401
)错误连接。
您应该通过将 xpack.security.enabled: false
添加到elasticsearch.yml
或在您的请求中提供有效凭据来关闭ES实例中的安全性。
非常感谢你,我真的很感激。 –
我刚刚发布了答案,再次感谢 –
(发布代表问题作者)。
从提供的其他答案:
development: &default
host: 'http://localhost:9200/'
transport_options:
request:
timeout: !!integer 300
test:
<<: *default
staging:
<<: *default
continous_integration:
<<: *default
xpack.security.enabled: false
嗨克里斯。如果您有答案材料,请务必在下面添加它作为自我回答,而不是将其与问题合并。有一个“回答你自己的问题”按钮的目的。 – halfer
另外,我注意到您的问题标题由小写标签列表组成。社区通常更喜欢标题是完全形成的英语句子,使用适当的案例规则进行可读性。我发现问题的题目工作得很好,但我不认为这是强制性的。 [请阅读我的社区答案](https://meta.stackoverflow.com/a/253076/472495)以获取更多信息。 – halfer