Merge pull request #1153 from donny-dont/features/cache-docs

Documentation for caching
This commit is contained in:
Brad Rydzewski 2015-08-19 18:30:45 -07:00
commit f0cc7a211d
2 changed files with 66 additions and 0 deletions

9
doc/build/build.md vendored
View file

@ -24,6 +24,7 @@ The build configuration options:
* `volumes` - list of bind mounted volumes on the host machine [1]
* `net` - sets the container [network mode](https://docs.docker.com/articles/networking/#container-networking) [1]
* `commands` - list of build commands
* `cache` - list of directories within the workspace to cache
[1] Some build options are disabled for security reasons, including `volumes`, `privileged` and `net`. To enable these options, a system administrator must white-list your repository as trusted. This can be done via the repository settings screen.
@ -45,6 +46,14 @@ image: library/golang:1.4
image: index.docker.io/library/golang:1.4
```
## Caching
The `cache` attribute supports a list of directories to cache within the build directory. Internally Drone will treat these as volume containers that are shared between all builds within the repository built on the same host machine. Unlike the `volumes` option `cache` is available without the repository being marked as trusted by an administrator[2].
[2] If the repository is public and the build is triggered by a pull request then caching will be disabled for that build. For all other builds caching will be available.
For more information on how to use caching within a project view [caching in Drone](caching.md).
## Skipping builds
Skip a build by including the text `[CI SKIP]` in your commit message.

57
doc/build/caching.md vendored Normal file
View file

@ -0,0 +1,57 @@
# Caching
Drone allows the caching of directories within the workspace. This can be used to improve the performance of the builds. This document discusses how caching is implemented and provides some general advice for lowering the execution time of builds.
Remember that cached volumes are retained between builds and those volumes are accessible through plugins. They are also available through the host's file system. Any information that is sensitive should not be contained within the cache.
## Caching Implementation
Drone uses Docker volumes to handle caching. The volumes are mounted within the build container and are available immediately within the container and any plugins running within the environment.
Given the following configuration.
```yaml
build:
cache:
- foo
- fizz/buzz
```
Two volumes will be created with their paths resembling the following, with the path left of the : being the location on the host and to the right being the directory within the container. If a different path is specified in the [clone](clone.md) plugin then the paths on the right will be relative to the value in `path` rather than the default paths specified below.
```
/tmp/drone/cache/${origin}/${org}/${name}/foo:/drone/src/${origin}/${org}/${name}/foo
/tmp/drone/cache/${origin}/${org}/${name}/fizz/buzz:/drone/src/${origin}/${org}/${name}/fizz/buzz
```
If the drone repository used this caching then the volumes would look like.
```
/tmp/drone/cache/github.com/drone/drone/foo:/drone/src/github.com/drone/drone/foo
/tmp/drone/cache/github.com/drone/drone/fizz/buzz:/drone/src/github.com/drone/drone/fizz/buzz
```
### Sharing the Cache
Volumes in Docker are local to the host. When using multiple build machines there will be a copy of the cache on each of these machines. If its desireable to share the cached directories among all the build machines then a distributed file system could be mounted to `/tmp/drone/cache`. Setting up a distrubted file system is beyond the scope of this document but can potentially benifit build times and reduce the disk usage from caching.
### Deleting the Cache
The caching implementation uses the `/tmp/` directory which is typically cleared every boot unless explicitly changed. If the docker host is never rebooted then a cron job could be used to clear the `/tmp/drone/cache/` periodically. The amount of time to wait clear is dependent upon the number of builds being run, the amount of data being cached, and the size of the repositories. Because of this it is recommended to monitor the disk usage and then make a judgement call based on that data.
## Optimization Strategies
The following sections, arranged alphabetically, contain optimization strategies for various programming languages and version control systems using caching.
### C/C++
_Looking for additional input_
### Dart
_Looking for additional input_
### Git
When git is used as the version control system the .git directory is a good candidate for caching. Since the git plugin handles the checkout process the only thing needed is to add the .git directory to the cache section.
```yaml
build:
cache:
- .git
```
### Golang
_Looking for additional input_
### Java
_Looking for additional input_
### JavaScript
_Looking for additional input_
### PHP
_Looking for additional input_
### Python
_Looking for additional input_
### Ruby
_Looking for additional input_