0

I'm using drone/drone:0.8 along with the Docker plugin, and I'm kinda stuck with a Dockerfile I use to build the app.

This Dockerfile runs the app test suite as part of it's build process - relevant fragment shown:

# 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

The test suite requires a connection to the database, for which I'm including the postgres service in the .drone.yml file:

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

But it looks like the services defined in the drone file are not accessible from within the build process:

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

Is there any configuration I'm missing out? Or this is a feature not currently present in the plugin?

I know this could be related somehow with the --network and/or --add-host options from docker build command... I could help in case you think we should include this behavior.

  • I've run into this issue with node projects and testing against ephemeral databases. I wasn't able to get testing to happen during the build step and had to move it out to an external drone step where the service was available. – mhumesf Jul 23 '18 at 16:53
  • I've confirmed having access to the database from the pipeline steps - using a previous 'check-postgres' step - but in the next (plugin/docker) step, the network where the services are found is not available *inside* the build process... I'm sure the build network is not added to the docker build command. – vovimayhem Jul 23 '18 at 21:39
  • I commented on drone ci's subreddit: https://www.reddit.com/r/droneci/comments/91a3fh/docker_plugin_feature_request_access_to_services/ – vovimayhem Jul 23 '18 at 21:49

1 Answers1

0

So a couple things jump out to me (although I don't have the full context so take what you think makes sense)

  1. I would probably separate out the build/testing piece of the code into a different step, and then use the docker plugin to publish the artifacts ones the've passed
  2. I think the docker plugin is really to publish the image (I don't believe its container is going to be able to reach the service containers due to dind)
  3. if you do separate it out you'll probably need - sleep 15 in the commands section of the build to give the db time to startup

http://docs.drone.io/postgres-example/ has examples of how to use postgres but again, it would required separating the build pieces from creating and publishing the docker image :)

here's a sample I'm talking about ;)

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

Joachim
  • 2,761
  • 1
  • 15
  • 7