首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在CircleCI中建立弹性搜索和Rails

在CircleCI中建立弹性搜索和Rails
EN

Stack Overflow用户
提问于 2017-10-06 03:30:41
回答 2查看 2.5K关注 0票数 4

我试图在我的Rails应用程序中使用Elasticsearch设置CircleCI。我认为图像已经配置好了,但是如何在CI中连接到它呢?

到目前为止我已经试过..。

https://github.com/elastic/elasticsearch/issues/23866

错误消息

代码语言:javascript
复制
Elasticsearch::Transport::Transport::Errors::Unauthorized: [401]

圆YAML Config

代码语言:javascript
复制
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

弹性搜索初始化器

代码语言:javascript
复制
require 'faraday_middleware/aws_signers_v4'

if Rails.env.production? || Rails.env.staging?
  Elasticsearch::Model.client = Elasticsearch::Client.new(url: ENV["AWS_ELASTICSEARCH_HOST"]) do |f|
    f.request :aws_signers_v4,
      credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY'], ENV['AWS_ACCESS_SECRET_KEY']),
      service_name: 'es',
      region: ENV['AWS_REGION']

    f.adapter Faraday.default_adapter
  end
else
  config = {
    host: "http://127.0.0.1:9200",
    transport_options: {
      request: { timeout: 5 }
    }
  }
  if File.exists?("config/elasticsearch.yml")
    config.merge!(YAML.load_file("config/elasticsearch.yml"))
  end

  Elasticsearch::Model.client = Elasticsearch::Client.new(config)
end
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-10-06 04:28:38

正式的码头图片来自弹性与x包预装。

https://www.elastic.co/guide/en/elasticsearch/reference/5.4/docker.html

这意味着您的elasticsearch实例运行时启用了安全性,但您似乎没有向您的elasticsearch客户端提供任何安全凭据,因此当您试图连接时会得到一个未经授权的(401)错误。

您应该通过将xpack.security.enabled: false添加到elasticsearch.yml来关闭ES实例中的安全性,或者在请求中提供有效的凭据。

票数 2
EN

Stack Overflow用户

发布于 2017-10-07 10:52:23

(代表问题提交人发文)。

另一项答复是:

代码语言:javascript
复制
development: &default
  host: 'http://localhost:9200/'
  transport_options:
    request:
      timeout: !!integer 300

test:
  <<: *default

staging:
  <<: *default

continous_integration:
  <<: *default
  xpack.security.enabled: false
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46597848

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档