【发布时间】:2018-07-22 21:25:17
【问题描述】:
我正在使用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 选项有关...如果您认为我们应该包含此行为,我可以提供帮助。
【问题讨论】:
-
我在节点项目和针对临时数据库的测试中遇到了这个问题。我无法在构建步骤中进行测试,不得不将其移至提供服务的外部无人机步骤。
-
我已经确认可以从管道步骤访问数据库 - 使用之前的“check-postgres”步骤 - 但在下一个(插件/docker)步骤中,找到服务的网络在构建过程中内部不可用...我确定构建网络未添加到 docker build 命令中。
-
我评论了drone ci的subreddit:reddit.com/r/droneci/comments/91a3fh/…