Whether drone.io support reusing docker container for build

3.5k views Asked by At

I have setup drone.io locally and created a .drone.yml for CI build. But I found drone removes the docker container after finishing the build. Whether it support reusing the docker container? I am working on gradle project and the initial build takes a long time to download java dependencies.

UPDATE1

I used below command to set the admin user on running drone-server container.

docker run -d \
  -e DRONE_GITHUB=true \
  -e DRONE_GITHUB_CLIENT="xxxx" \
  -e DRONE_GITHUB_SECRET="xxxx" \
  -e DRONE_SECRET="xxxx" \
  -e DRONE_OPEN=true  \
  -e DRONE_DATABASE_DRIVER=mysql \
  -e DRONE_DATABASE_DATASOURCE="root:root@tcp(mysql:3306)/drone?parseTime=true" \
  -e DRONE_ADMIN="joeyzhao0113" \
  --restart=always \
  --name=drone-server \
  --link=mysql \
  drone/drone:0.5

After doing this, I use the user joeyzhao0113 to login drone server but failed to enable the Trusted flag on the setting page. The popup message dialog shows setting successfully see below screenshot. But the flag keep showing disabled always.

enter image description here

1

There are 1 answers

11
Brad Rydzewski On BEST ANSWER

No, it is not possible to re-use a Docker container for your Drone build. Build containers are ephemeral and are destroyed at the end of every build.

That being said, it doesn't mean your problem cannot be solved.

I think a better way to phrase this question would be "how do I prevent my builds from having to re-download dependencies"? There are two solutions to this problem.

Option 1, Cache Plugin

The first, recommended solution, is to use a plugin to cache and restore your dependencies. Cache plugins such as the volume cache and s3 cache are community contributed plugins.

pipeline:
  # restores the cache from a local volume
  restore-cache:
    image: drillster/drone-volume-cache
    restore: true
    mount: [ /drone/.gradle, /drone/.m2 ]
    volumes: 
      - /tmp/cache:/cache

  build:
    image: maven
    environment:
      - M2_HOME=/drone/.m2
      - MAVEN_HOME=/drone/.m2
      - GRADLE_USER_HOME=/drone/.gradle
    commands:
      - mvn install
      - mvn package

  # rebuild the cache in case new dependencies were
  # downloaded during your build
  rebuild-cache:
    image: drillster/drone-volume-cache
    rebuild: true
    mount: [ /drone/.gradle, /drone/.m2 ]
    volumes: 
      - /tmp/cache:/cache

Option 2, Custom Image

The second solution is to create a Docker image with your dependencies, publish to DockerHub, and use this as your build image in your .drone.yml file.

pipeline:
  build:
    image: some-image-with-all-my-dependencies
    commands:
      - mvn package