我将drone / drone:0.8和Docker插件一起使用,并且我对用于构建应用程序的Dockerfile有点困惑。
此Dockerfile作为其构建过程的一部分运行应用程序测试套件-显示了相关片段:
# ENV & ARG settings:
ENV RAILS_ENV=test RACK_ENV=test
ARG DATABASE_URL=postgres://postgres:3x4mpl3@postgres:5432/app_test
# Run the tests:
RUN rails db:setup && rspec
测试套件需要连接到数据库,为此我在.drone.yml文件中包括了postgres服务:
pipeline:
app:
image: plugins/docker
repo: vovimayhem/example-app
tags:
- ${DRONE_COMMIT_SHA}
- ${DRONE_COMMIT_BRANCH/master/latest}
compress: true
secrets: [ docker_username, docker_password ]
use_cache: true
build_args:
- DATABASE_URL=postgres://postgres:3x4mpl3@postgres:5432/app_test
services:
postgres:
image: postgres:9-alpine
environment:
- POSTGRES_PASSWORD=3x4mpl3
但是,似乎无法从构建过程中访问无人机文件中定义的服务:
Step 18/36 : RUN rails db:setup && rspec
---> Running in 141734ca8f12
could not translate host name "postgres" to address: Name does not resolve
Couldn't create database for {"encoding"=>"unicode", "schema_search_path"=>"partitioning,public", "pool"=>5, "min_messages"=>"log", "adapter"=>"postgresql", "username"=>"postgres", "password"=>"3x4mpl3", "port"=>5432, "database"=>"sibyl_test", "host"=>"postgres"}
rails aborted!
PG::ConnectionBad: could not translate host name "postgres" to address: Name does not resolve
我缺少任何配置吗?还是这是插件中当前不存在的功能?
我知道这可能与docker build命令中的--network和/或--add-host选项相关...如果您认为我们应该包含此行为,我可以提供帮助。
答案 0 :(得分:0)
所以有几件事让我感动(尽管我没有完整的背景信息,所以请理解您认为的意思)
- sleep 15
才能让数据库有时间启动http://docs.drone.io/postgres-example/提供了有关如何使用postgres的示例,但同样,它需要将构建部分与创建和发布docker镜像分开:)
这是我正在谈论的示例;)
pipeline:
tests-builds: //Should probably be separate :)
image: python:3.6-stretch
commands:
- sleep 15 //wait for postgrest to start
- pip install --upgrade -r requirements.txt
- pip install --upgrade -r requirements-dev.txt
- pytest --cov=sfs tests/unit
- pytest --cov=sfs tests/integration //This tests the db interactio0ns
publish:
image: plugins/docker
registry: quay.io
repo: somerepot
auto_tag: true
secrets: [ docker_username, docker_password ]
when:
event: [ tag, push ]
services:
database:
image: postgres