【发布时间】:2019-05-13 15:50:51
【问题描述】:
当我运行 CircleCI 时,前几个测试由于 Elasticsearch 尚未完全设置而失败。
通常我会使用 dockerize 库来等待 Elasticsearch 完成,但这似乎无法检测到 Elasticsearch。任何想法为什么? dockerize 命令只是超时。但是,Elasticsearch 容器似乎正在运行,因为如果我不等待,最终 Elasticsearch 会开始处理测试。
这是我的 docker 文件
version: 2
jobs:
build:
parallelism: 3
working_directory: ~/export-opportunities
docker:
- image: circleci/ruby:2.5.5-node
environment:
BUNDLE_JOBS: 3
BUNDLE_RETRY: 3
BUNDLE_PATH: vendor/bundle
PGHOST: localhost
PGUSER: user
RAILS_ENV: test
- image: circleci/postgres:latest
environment:
POSTGRES_USER: user
POSTGRES_DB: circle_test
POSTGRES_PASSWORD: $POSTGRES_PASSWORD
- image: circleci/redis:4.0.9
environment:
REDIS_URL: "redis://localhost:6379/"
- image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
environment:
cluster.name: elasticsearch
xpack.security.enabled: false
transport.host: localhost
network.host: 127.0.0.1
http.port: 9200
discovery.type: single-node
branches:
only: chore/XOT-597-circleci
steps:
- checkout # check out the code in the project directory
# restore bundle cache
- restore_cache:
keys:
- exops-{{ checksum "Gemfile.lock" }}
- run:
name: Bundle Install
command: bundle check || bundle install
# store bundle cache
- save_cache:
key: exops-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
# Database setup
- run:
name: install dockerize
command: wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
environment:
DOCKERIZE_VERSION: v0.3.0
- run:
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Database setup
command: |
bundle exec rake db:create
bundle exec rake db:migrate
# Redis setup
- run:
name: Wait for Redis
command: dockerize -wait tcp://localhost:6379 -timeout 1m
# DOES NOT WORK:
- run:
name: Wait for Elasticsearch
command: dockerize -wait http://localhost:9200 -timeout 2m
# Run rspec in parallel
- run: |
echo Running test ...
bundle exec rspec --profile 10 \
--format RspecJunitFormatter \
--out test_results/rspec.xml \
--format progress \
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
# Save test results for timing analysis
- store_test_results:
path: test_results
注意我也试过dockerize -wait tcp://localhost:9200 -timeout 2m、dockerize -wait http://127.0.0.1:9200 -timeout 2m和dockerize -wait tcp://127.0.0.1:9200 -timeout 2m,但没有效果。
【问题讨论】:
-
嗯,奇怪。为了让您继续前进,请使用
sleep 10代替不工作的dockerize。然后,当您有时间时,我想知道是否值得尝试任何类似的工具,例如waitforit脚本。 -
Elasticsearch 需要多长时间才能做好准备?我想知道你是否有一个需要超过 2m 才能启动的极端情况。
标签: docker elasticsearch circleci circleci-2.0