Skip to content

Instantly share code, notes, and snippets.

@cab404
Created February 1, 2018 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cab404/3a055f1534132ec0adbe5da79eb56cf1 to your computer and use it in GitHub Desktop.
Save cab404/3a055f1534132ec0adbe5da79eb56cf1 to your computer and use it in GitHub Desktop.
caching script for drone.io Volume Cache
#!/bin/bash
# drone.io cache simplifier by cab404, for using with Volume Cache plugin
# allows you to cache practically anything from anywhere, specifying only '.drone-cache' in mounts
# to pack something do "cache in (smthn)"
# to unpack all do "cache out"
#
# e.g you want to cache /root/.gradle/cache and /root/.gradle/wrapper (typical for android), you do
# get-cache:
# image: drillster/drone-volume-cache
# restore: true
# mount:
# - .drone-cache
# volumes:
# - /tmp/${DRONE_REPO}/cache:/cache
#
# build:
# commands:
# - ./cache out
# - somebuildcommand
# - ./cache in .gradle/cache
# - ./cache in .gradle/wrapper
#
# save-cache:
# image: drillster/drone-volume-cache
# rebuild: true
# mount:
# - .drone-cache
# volumes:
# - /tmp/${DRONE_REPO}/cache:/cache
CACHEDIR=.drone-cache
mkdir -p $CACHEDIR
if [ $1 == "in" ]; then
TARGET=$(readlink -f $2)
TARGETDIR=$(dirname $TARGET)
echo caching $TARGET
mkdir -p "$CACHEDIR$TARGETDIR"
cp -Tr "$TARGET" "$CACHEDIR$TARGET"
fi
if [ $1 == "out" ]; then
cp -Tr $CACHEDIR/ /
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment