mirror of
https://github.com/drillster/drone-volume-cache.git
synced 2026-06-04 18:24:02 +08:00
add project
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
Use the Volume-cache plugin to preserve files and directories between builds.
|
||||
Because it uses a mounted volume, it requires repositories using it to enable the *"Trusted"* flag.
|
||||
|
||||
## Config
|
||||
The following parameters are used to configure the plugin:
|
||||
- **restore** - instruct plugin to restore cache, can be `true` or `false`
|
||||
- **rebuild** - instruct plugin to rebuild cache, can be `true` or `false`
|
||||
- **mount** - list of folders to cache
|
||||
|
||||
## Examples
|
||||
```yaml
|
||||
pipeline:
|
||||
restore-cache:
|
||||
image: drillster/drone-cache
|
||||
restore: true
|
||||
mount:
|
||||
- ./node_modules
|
||||
# Mount the cache volume, needs "Trusted"
|
||||
volumes:
|
||||
- /tmp/cache:/cache
|
||||
|
||||
build:
|
||||
image: node
|
||||
commands:
|
||||
- npm install
|
||||
|
||||
rebuild-cache:
|
||||
image: drillster/drone-cache
|
||||
rebuild: true
|
||||
mount:
|
||||
- ./node_modules
|
||||
# Mount the cache volume, needs "Trusted"
|
||||
volumes:
|
||||
- /tmp/cache:/cache
|
||||
```
|
||||
|
||||
The example above illustrates a typical Node.js project Drone configuration. It caches the `./node_modules` directory to a mounted volume on the host system: `/tmp/cache`. This prevents `npm` from downloading and installing the dependencies for every build.
|
||||
@@ -0,0 +1,8 @@
|
||||
FROM alpine:3.4
|
||||
MAINTAINER Michael de Wit <michael@drillster.com>
|
||||
|
||||
RUN mkdir /cache && apk add --no-cache bash rsync
|
||||
COPY cacher.sh /usr/local/
|
||||
VOLUME /cache
|
||||
|
||||
ENTRYPOINT ["/usr/local/cacher.sh"]
|
||||
@@ -0,0 +1,24 @@
|
||||
# drone-volume-cache
|
||||
This is a pure Bash [Drone](https://github.com/drone/drone) 0.5 plugin to cache files and/or folders to a locally mounted volume.
|
||||
|
||||
## Docker
|
||||
Build the docker image by running:
|
||||
|
||||
```bash
|
||||
docker build --rm=true -t drillster/drone-volume-cache .
|
||||
```
|
||||
|
||||
## Usage
|
||||
Execute from the working directory:
|
||||
|
||||
```bash
|
||||
docker run --rm \
|
||||
-e PLUGIN_REBUILD=true \
|
||||
-e PLUGIN_MOUNT="./node_modules" \
|
||||
-e DRONE_REPO_OWNER="foo" \
|
||||
-e DRONE_REPO_NAME="bar" \
|
||||
-v $(pwd):$(pwd) \
|
||||
-v /tmp/cache:/cache \
|
||||
-w $(pwd) \
|
||||
drillster/drone-volume-cache
|
||||
```
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -z "$PLUGIN_MOUNT" ]; then
|
||||
echo "Specify folders to cache in the mount property! Plugin won't do anything!"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
IFS=','; read -ra SOURCES <<< "$PLUGIN_MOUNT"
|
||||
if [ -n "$PLUGIN_REBUILD" ]; then
|
||||
# Create cache
|
||||
for source in "${SOURCES[@]}"; do
|
||||
echo "Rebuilding cache for $source..."
|
||||
mkdir -p "/cache/$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$source" && rsync -aHAX "$source/" "/cache/$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$source"
|
||||
done
|
||||
elif [ -n "$PLUGIN_RESTORE" ]; then
|
||||
# Restore from cache
|
||||
for source in "${SOURCES[@]}"; do
|
||||
if [ -d "/cache/$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$source" ]; then
|
||||
echo "Restoring cache for $source..."
|
||||
mkdir -p "$source" && rsync -aHAX "/cache/$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$source/" "$source"
|
||||
else
|
||||
echo "No cache for $source"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "No restore or rebuild flag specified, plugin won't do anything!"
|
||||
fi
|
||||
Reference in New Issue
Block a user