drone-plugins / drone-docker

Drone plugin for publishing Docker images
http://plugins.drone.io/drone-plugins/drone-docker
Apache License 2.0
319 stars 318 forks source link

Access drone services from within the Dockerfile build process #186

Closed vovimayhem closed 6 years ago

vovimayhem commented 6 years ago

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.

tboerger commented 6 years ago

Please use https://www.reddit.com/r/droneci/ or https://stackoverflow.com/questions/tagged/drone.io for questions like that. The issue tracker is reserved for bugs and concrete feature requests. Thank you!

di118 commented 4 years ago

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.

Hi! I am running into a similar issue. I am trying to use the requirements.txt files generated by a drone step in my next step that builds the docker image. Any idea if that is possible?