Last active
November 15, 2016 04:59
-
-
Save akhy/1f3efcd32a8b207fa6ba300aa11a4558 to your computer and use it in GitHub Desktop.
rancher-compose wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Notes: | |
# - RANCHER_URL, RANCHER_ACCESS_KEY, RANCHER_SECRET_KEY must be set | |
# - jq is required (brew install jq) // TODO: remove this dependency | |
# - cache is located at $HOME/.rancher-compose/cache.txt | |
# - usage is the same as rancher-compose, it's just a wrapper | |
if [ `uname` == "Darwin" ]; then | |
ARCH="darwin-amd64" | |
elif [ `uname` == "Linux" ]; then | |
ARCH="linux-amd64" | |
fi | |
COMPOSE_HOME="${HOME}/.rancher-compose" | |
COMPOSE_CACHE="${COMPOSE_HOME}/cache.txt" | |
RANCHER_DOMAIN=`echo $RANCHER_URL | awk -F '/' '{print $3}'` | |
mkdir -p "$COMPOSE_HOME" | |
if [ "$VERSION" == "" ]; then | |
VERSION=`cat $COMPOSE_CACHE | grep "$RANCHER_DOMAIN" | awk '{print $2}'` | |
fi | |
if [ "$VERSION" == "" ]; then | |
VERSION=`curl --silent --user ${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY} \ | |
"${RANCHER_URL}/activesettings/1as!rancher.compose.version" \ | |
| jq -r ".value"` | |
echo "$RANCHER_DOMAIN $VERSION" >> $COMPOSE_CACHE | |
fi | |
if [ "$VERSION" == "" ]; then | |
echo "Cannot get rancher-compose version" | |
exit 1 | |
fi | |
COMPOSE_DIR="${COMPOSE_HOME}/${VERSION}" | |
COMPOSE_BIN="${COMPOSE_DIR}/rancher-compose" | |
URL="https://github.com/rancher/rancher-compose/releases/download/${VERSION}/rancher-compose-${ARCH}-${VERSION}.tar.gz" | |
mkdir -p $COMPOSE_DIR | |
if [ ! -f $COMPOSE_BIN ]; then | |
ARCHIVE="${COMPOSE_BIN}.tar.gz" | |
TEMP_DIR="$COMPOSE_DIR/rancher-compose-${VERSION}" | |
if [ ! -f $ARCHIVE ]; then | |
wget -O $ARCHIVE $URL | |
fi | |
tar -zxf $ARCHIVE -C $COMPOSE_DIR | |
mv "$TEMP_DIR/rancher-compose" "$COMPOSE_BIN" | |
rm -rf "$TEMP_DIR" | |
rm -rf "$ARCHIVE" | |
fi | |
$COMPOSE_BIN "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment