【问题标题】:Testing a dockerized Ruby on Rails app with MySQL on CircleCI在 CircleCI 上使用 MySQL 测试 dockerized Ruby on Rails 应用程序
【发布时间】:2016-08-25 09:43:30
【问题描述】:

我正在尝试将 CircleCI 与我的 Dockerized Ruby on Rails 应用程序一起使用。 该应用程序设置为使用 MySQL。 在本地,一切正常; RSpec 通过,一切都很好。 在 CircleCI 中进行测试时,我什至无法到达服务器正在运行并运行测试的点。

CircleCI 输出

curl --retry 10 --retry-delay 5 -v http://0.0.0.0:3000
* Rebuilt URL to: http://0.0.0.0:3000/
* Hostname was NOT found in DNS cache
*   Trying 0.0.0.0...
* connect to 0.0.0.0 port 3000 failed: Connection refused
* Failed to connect to 0.0.0.0 port 3000: Connection refused
* Closing connection 0 curl: (7) Failed to connect to 0.0.0.0 port 3000: Connection refused

curl --retry 10 --retry-delay 5 -v http://0.0.0.0:3000 returned exit code 7

circleci.yml

machine:
  ruby:
    version: ruby-2.3.1
  services:
    - docker

database:
  override:
    - mv config/database.ci.yml config/database.yml
    - bundle exec rake db:create db:schema:load --trace

dependencies:
  override:
    - bundle install:
            timeout: 240
    - docker info
    - docker build -t <myimage> .

test:
  override:
    - docker run -d -p 3000:3000 <myimage>; sleep 10
    - curl --retry 10 --retry-delay 5 -v http://0.0.0.0:3000

deployment:
  docker-hub:
    branch: master
    commands:
      - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
      - docker push <myimage>

database.ci.yml

test:
  adapter: mysql2
  encoding: utf8
  port: 3306
  pool: 5
  host: localhost
  database: <db_test>
  username: ubuntu

development:
  adapter: mysql2
  encoding: utf8
  port: 3306
  pool: 5
  host: localhost
  database: <db>
  username: ubuntu

Dockerfile

FROM ruby:2.3.1

MAINTAINER <me>

# Install dependencies:
# - build-essential: To ensure certain gems can be compiled

RUN apt-get update && apt-get install -qq -y \
build-essential g++ flex bison gperf chrpath python python-setuptools python-dev perl \
libpq-dev libssl-dev libxft-dev libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev  libsqlite3-dev \
libicu-dev libfreetype6 libpng-dev libjpeg-dev  libx11-dev libxext-dev \
--fix-missing --no-install-recommends

# Set an environment variable to store where the app is installed to inside
# of the Docker image.
ENV INSTALL_PATH /usr/src/core

RUN mkdir -p $INSTALL_PATH $INSTALL_PATH/tmp/pids/ && touch $INSTALL_PATH/tmp/pids/sidekiq.pid

WORKDIR $INSTALL_PATH

# throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1

# Ensure gems are cached and only get updated when they change. This will
# drastically increase build times when your gems do not change.

COPY Gemfile Gemfile.lock $INSTALL_PATH/
RUN gem install bundler && bundle install --jobs 20 --retry 5 --deployment

# Copy in the application code from your work station at the current directory
# over to the working directory.
COPY . $INSTALL_PATH

EXPOSE 3000
ENV LANG C.UTF-8

CMD rails server -p 3000 -b 0.0.0.0

注意在 rails 服务器启动时绑定到 0.0.0.0:3000(必需且不能更改)。

知道我做错了什么吗?

【问题讨论】:

    标签: mysql ruby-on-rails docker dockerfile circleci


    【解决方案1】:

    问题是你 circleci.yml 中的这一行

        - curl --retry 10 --retry-delay 5 -v http://0.0.0.0:3000
    

    应该是

        - curl --retry 10 --retry-delay 5 -v http://127.0.0.1:3000
    

    【讨论】:

      猜你喜欢
      • 2018-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-03
      相关资源
      最近更新 更多