我有一个在Travis上的Rails代码库。它包含一个docker-compose.yml文件:
postgres:
image: postgres
ports:
- "5433:5432"
environment:
- POSTGRES_USER=calories
- POSTGRES_PASSWORD=secretpassword
(我不得不使用5433作为主机端口,因为5432给了我一个错误: 启动用户代理时出错: 监听tcp 0.0.0.0:5432: 绑定: 地址已经在使用中
)
还有一个travis.yml文件:
sudo: required
services:
- docker
language: ruby
cache: bundler
before_install:
# Install docker-compose
- curl -L https://github.com/docker/compose/releases/download/1.4.0/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
# TODO: Remove this temporary fix when it's safe to:
# https://github.com/travis-ci/travis-ci/issues/4778
- sudo iptables -N DOCKER || true
- sleep 10
- docker-compose up -d
before_script:
- bundle exec rake db:setup
script:
- bundle exec rspec spec
after_script:
- docker-compose stop
- docker-compose rm -f
我正在努力弄清楚在database.yml文件中应该填写什么,以便我的测试可以在Travis CI上运行。在其他环境中,我可以这样做:
adapter: postgresql
encoding: unicode
host: <%= `docker-machine ip default` %>
port: 5433
username: calories
password: secretpassword
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
但是不幸的是,在Travis上这并不起作用,因为Travis上没有docker-machine
。我收到一个错误:docker-machine: command not found
我怎样在Travis上获取Docker主机的IP地址呢?
.travis.yml
文件的script
中添加- docker ps
吗?这样应该会显示所有正在运行的容器 ;) - pplonski