Files
dokku/dokku
2013-10-29 17:44:36 -05:00

104 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
export PLUGIN_PATH=${PLUGIN_PATH:="/var/lib/dokku/plugins"}
export DOKKU_ROOT=${DOKKU_ROOT:="/home/dokku"}
case "$1" in
receive)
APP="$2"; IMAGE="app/$APP"
echo "-----> Building $APP ..."
cat | dokku build $APP $IMAGE
echo "-----> Releasing $APP ..."
dokku release $APP $IMAGE
echo "-----> Deploying $APP ..."
dokku deploy $APP $IMAGE
echo "-----> Cleaning up ..."
dokku cleanup
echo "=====> Application deployed:"
echo " $(dokku url $APP)"
echo
;;
build)
APP="$2"; IMAGE="$3"; CACHE_DIR="$HOME/$APP/cache"
id=$(cat | docker run -i -a stdin progrium/buildstep /bin/bash -c "mkdir -p /app && tar -xC /app")
test $(docker wait $id) -eq 0
docker commit $id $IMAGE > /dev/null
[[ -d $CACHE_DIR ]] || mkdir $CACHE_DIR
pluginhook pre-build $APP $IMAGE
id=$(docker run -d -v $CACHE_DIR:/cache $IMAGE /build/builder)
docker attach $id
test $(docker wait $id) -eq 0
docker commit $id $IMAGE > /dev/null
;;
release)
APP="$2"; IMAGE="$3"
pluginhook pre-release $APP $IMAGE
if [[ -f "$DOKKU_ROOT/$APP/ENV" ]]; then
id=$(cat "$DOKKU_ROOT/$APP/ENV" | docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/app-env.sh")
test $(docker wait $id) -eq 0
docker commit $id $IMAGE > /dev/null
fi
pluginhook post-release $APP $IMAGE
;;
deploy)
APP="$2"; IMAGE="$3"
pluginhook pre-deploy $APP $IMAGE
if [[ ! -f "$DOKKU_ROOT/$APP/PORT" ]]; then
# First deploy
id=$(docker run -d -p 5000 -e PORT=5000 $IMAGE /bin/bash -c "/start web")
echo $id > "$DOKKU_ROOT/$APP/CONTAINER"
port=$(docker port $id 5000)
echo $port > "$DOKKU_ROOT/$APP/PORT"
echo "http://$(< "$DOKKU_ROOT/HOSTNAME"):$port" > "$DOKKU_ROOT/$APP/URL"
else
# Regular deploy
oldid=$(< "$DOKKU_ROOT/$APP/CONTAINER")
docker kill $oldid > /dev/null
port=$(< "$DOKKU_ROOT/$APP/PORT")
id=$(docker run -d -p ":$port" -e "PORT=$port" $IMAGE /bin/bash -c "/start web")
echo $id > "$DOKKU_ROOT/$APP/CONTAINER"
fi
pluginhook post-deploy $APP $port
;;
cleanup)
# delete all non-running container
docker ps -a | grep 'Exit' | awk '{print $1}' | xargs docker rm &> /dev/null &
# delete unused images
docker images | grep '<none>' | awk '{print $3}' | xargs docker rmi &> /dev/null &
;;
plugins)
ls -1 -d $PLUGIN_PATH/*/
;;
plugins-install)
pluginhook install
;;
# temporary hack for https://github.com/progrium/dokku/issues/82
deploy:all)
for app in $(ls -d $DOKKU_ROOT/*/); do
APP=$(basename $app);
IMAGE="app/$APP"
dokku deploy $APP $IMAGE
done
;;
help)
cat<<EOF | pluginhook commands help | sort
help Print the list of commands
plugins Print active plugins
plugins-install Install active plugins
EOF
;;
*)
pluginhook commands "$@"
;;
esac