Hi.
I’m working on migrating to Circle CI 2.0. I have a Ruby on Rails project setup with elastic search that has been working fine with 1.0 configuration.
On trying to configure CI to 2.0, I’m having a problem with setting elasticsearch port for Test Environment in Circle CI.
My config.yml
file:
version: 2
defaults: &defaults
working_directory: ~/repo
docker:
- image: circleci/ruby:2.4.1-node
environment:
- BUNDLE_JOBS: 4
- BUNDLE_RETRY: 3
- BUNDLE_PATH: vendor/bundle
- PGHOST: 127.0.0.1
- PGUSER: postgres
- RAILS_ENV: test
- image: mdillon/postgis:9.5
environment:
- POSTGRES_USER: postgres
- POSTGRES_DB: a_test
- POSTGRES_PASSWORD:
- RACK_ENV: test
- image: circleci/redis:4.0.9
environment:
- REDIS_URL: "redis://localhost:6379/"
- image: docker.elastic.co/elasticsearch/elasticsearch:6.2.2
environment:
- cluster.name: elasticsearch
- xpack.security.enabled: false
- transport.host: localhost
- network.host: 127.0.0.1
- http.port: 9250
- discovery.type: single-node
jobs:
build:
<<: *defaults
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- bundle-{{ arch }}-{{ checksum "Gemfile.lock" }}
- run: bundle install
- save_cache:
paths:
- ./vendor/bundle
key: bundle-{{ arch }}-{{ checksum "Gemfile.lock" }}
- persist_to_workspace:
root: .
paths:
- vendor/bundle
- run:
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Wait for Redis
command: dockerize -wait tcp://localhost:6379 -timeout 1m
- run:
name: Database setup
command: |
bundle exec rake db:schema:load --trace
bundle exec rake db:migrate
- run:
name: Run tests
command: |
mkdir -p ~/repo/tmp/test-results/rspec
bundle exec rspec --color --require spec_helper spec --format progress --out ~/repo/tmp/test-results/rspec/results.xml --format progress
- store_artifacts:
path: ~/repo/tmp/screenshots
destination: test-screenshots
- store_test_results:
path: ~/repo/tmp/test-results
When I reach the Run tests
command Circle CI throws following Error:
Since I’m running the CI in test Env, my specs need to run on port 9250. I’ve configured them in spec_helper.rb
like this:
config.before :each, elasticsearch: true do
Elasticsearch::Extensions::Test::Cluster.start(port: 9250) unless Elasticsearch::Extensions::Test::Cluster.running?
end
config.after :each, elasticsearch: true do
Elasticsearch::Model.client.indices.delete index: '_all'
end
config.after :suite do
Elasticsearch::Extensions::Test::Cluster.stop(port: 9250) if Elasticsearch::Extensions::Test::Cluster.running?
end
end
And elastic search is initialized by my project for Test Env as:
if Rails.env.test?
Elasticsearch::Model.client = Elasticsearch::Client.new host: 'localhost:9250',
logger: Logger.new(STDOUT),
log: true
end
Anyone else who has had this problem. ?