1

We have a Ruby project where we are using Wercker as Continuous Integration.

We need to start an Elastic Search service in order to run some integration tests.

Locally, we added the Elastic configuration to the docker file and everything runs smoothly:

services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.5.1
    container_name: elasticsearch
    environment:
      - discovery.type=single-node
    ports:
      - "9200:9200"
      - "9300:9300"

In The Wercker.yml file, we tried several things, but we cannot reach the elastic service. Our wercker.yml contains:

services:
  - id: elasticsearch:6.5.1
    env:
      ports:
        - "9200:9200"
        - "9300:9300"

We have this king of error when trying to use Elastic in our tests:

Errno::EADDRNOTAVAIL: Failed to open TCP connection to localhost:9200 (Cannot assign requested address - connect(2) for "localhost" port 9200)

Do you have any idea of what we are missing?

4

1 回答 1

1

于是,我们找到了解决办法:

在 wercker.yml

services:
  - id: elasticsearch:6.5.1
    cmd: "/elasticsearch/bin/elasticsearch -Ediscovery.type=single-node"

我们添加了一个步骤来检查连接:

build:
  steps:
    - script:
        name: Test elasticsearch connection
        code: curl http://elasticsearch:9200
于 2018-12-05T09:05:16.347 回答