drone支持缓存
Volume Cache | Plugins | Drone
https://stackoverflow.com/questions/41412481/whether-drone-io-support-reusing-docker-container-for-build
matrix:
include:
- REPO_URL: "git.yimengapp.com"
LOCAL_VOLUME: "/var/www/yimeng"
#
pipeline:
clone:
image: plugins/git
volumes:
- ${LOCAL_VOLUME}/master:/drone/src/${REPO_URL}/${DRONE_REPO}
when:
branch: master
clone:
image: plugins/git
volumes:
- ${LOCAL_VOLUME}/release:/drone/src/${REPO_URL}/${DRONE_REPO}
when:
branch: release
clone:
image: plugins/git
volumes:
- ${LOCAL_VOLUME}/develop:/drone/src/${REPO_URL}/${DRONE_REPO}
when:
branch: [ dev, develop ]
busybox:
image: busybox
volumes:
- ${LOCAL_VOLUME}/:${LOCAL_VOLUME}
commands:
- if [ ${DRONE_BRANCH} == master ]; then chown -R 33:33 ${LOCAL_VOLUME}/master ; fi
- if [ ${DRONE_BRANCH} == release ]; then chown -R 33:33 ${LOCAL_VOLUME}/release ; fi
- if [ ${DRONE_BRANCH} == develop ]; then chown -R 33:33 ${LOCAL_VOLUME}/develop ; fi
# drone secret add --image=plugins/ssh yimeng/php-yimeng SSH_KEY @/home/ubuntu/.ssh/id_rsa
# drone sign yimeng/php-yimeng
pipeline:
restore-cache:
image: drillster/drone-volume-cache
restore: true
mount:
- .git
volumes:
- /tmp/cache:/cache
clone:
image: plugins/git
# PUT YOUR BUILD STEPS HERE #
ssh-master:
image: plugins/ssh
host: [ qubuluo.com ]
user: root
port: 22
script:
- echo master >master.txt
- echo master
when:
branch: master
ssh-dev:
image: plugins/ssh
host: [ qubuluo.com ]
user: root
port: 22
script:
- echo dev >dev.txt
- echo dev
when:
branch: dev
rebuild-cache:
image: drillster/drone-volume-cache
rebuild: true
mount:
- .git
volumes:
- /tmp/cache:/cache
# drone secret add --image=plugins/ssh yimeng/php-yimeng SSH_KEY @/home/ubuntu/.ssh/id_rsa
# drone sign yimeng/php-yimeng
pipeline:
restore-cache:
image: drillster/drone-volume-cache
restore: true
mount:
- .git
volumes:
- /tmp/cache:/cache
clone:
image: plugins/git
# PUT YOUR BUILD STEPS HERE #
rebuild-cache:
image: drillster/drone-volume-cache
rebuild: true
mount:
- .git
volumes:
- /tmp/cache:/cache
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.
0
down vote
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
the default workspace base is /drone assuming you didn't override the default base value. This means you can set GRADLE_USER_HOME=/drone/.gradle to instruct gradle to store the dependencies in your workspace, making accessible to the cache plugin. I've updated the example in my answer to show how this could work. – Brad Rydzewski