Whether drone.io support creating docker during build process

670 views Asked by At

I am using maven-docker-plugin in my project. This plugin will create docker containers during integration tests. Since drone.io put the build process inside a docker container, whether I can still use maven-docker-plugin during maven build? How to control the docker containers during build time?

1

There are 1 answers

2
Brad Rydzewski On BEST ANSWER

If you want interact directly with the Docker daemon to create and start containers, you need to mount the host machines Docker socket into your build container.

Since you mentioned using the docker-maven-plugin you may want a configuration similar to the following:

pipeline:
  build:
    image: maven
    environment:
      - DOCKER_API_VERSION=1.20
      - DOCKER_HOST=/var/run/docker.sock
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    commands:
      - mvn clean package docker:build

Please note that exposing the Docker daemon to your build environment is essentially giving your build root access to your server. This approach is therefore not recommended for public repositories.

Please also note that volumes are restricted security reasons. To use volumes you need to have a Drone administrator mark your repository as trusted, in your repository settings screen.

So it is possible to launch containers from inside the build environment for the purpose of running your tests. The recommended approach, however, is to run your tests directly inside your build environment. This is the use case for which Drone is optimized, and it eliminates the security issues mentioned above.