mirror of
https://github.com/dokku/dokku.git
synced 2025-12-28 16:06:40 +01:00
As discussed in #313, dokku base commands such as build, release, and deploy require specifying both `$APP` and `$IMAGE` as arguments where `IMAGE="app/$APP"`. Thus, the `$IMAGE` parameter is currently redudant. This patch removes the need to specify `$IMAGE` for these base commands and is backwards compatible. If, in the future, the base commands expect and `$IMAGE` different than `app/$APP`, then the `$IMAGE` parameter will be re-added for those specific commands.
115 lines
3.1 KiB
Bash
Executable File
115 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail
|
|
export DOKKU_ROOT=${DOKKU_ROOT:="/home/dokku"}
|
|
export PLUGIN_PATH=${PLUGIN_PATH:="/var/lib/dokku/plugins"}
|
|
|
|
[[ -f $DOKKU_ROOT/dokkurc ]] && source $DOKKU_ROOT/dokkurc
|
|
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
|
|
if [[ $(id -un) != "dokku" && $1 != "plugins-install" ]]; then
|
|
sudo -u dokku -H $0 "$@"
|
|
exit
|
|
fi
|
|
|
|
case "$1" in
|
|
receive)
|
|
APP="$2"; IMAGE="app/$APP"
|
|
echo "-----> Cleaning up ..."
|
|
dokku cleanup
|
|
echo "-----> Building $APP ..."
|
|
cat | dokku build $APP
|
|
echo "-----> Releasing $APP ..."
|
|
dokku release $APP
|
|
echo "-----> Deploying $APP ..."
|
|
dokku deploy $APP
|
|
echo "=====> Application deployed:"
|
|
echo " $(dokku url $APP)"
|
|
echo
|
|
;;
|
|
|
|
build)
|
|
APP="$2"; IMAGE="app/$APP"; CACHE_DIR="$DOKKU_ROOT/$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
|
|
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
|
|
pluginhook post-build $APP
|
|
;;
|
|
|
|
release)
|
|
APP="$2"; IMAGE="app/$APP"
|
|
pluginhook pre-release $APP
|
|
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
|
|
;;
|
|
|
|
deploy)
|
|
APP="$2"; IMAGE="app/$APP"
|
|
pluginhook pre-deploy $APP
|
|
|
|
# kill the app when running
|
|
if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then
|
|
oldid=$(< "$DOKKU_ROOT/$APP/CONTAINER")
|
|
docker kill $oldid > /dev/null 2>&1 || true
|
|
fi
|
|
|
|
# start the app
|
|
DOCKER_ARGS=$(: | pluginhook docker-args $APP)
|
|
id=$(docker run -d -p 5000 -e PORT=5000 $DOCKER_ARGS $IMAGE /bin/bash -c "/start web")
|
|
echo $id > "$DOKKU_ROOT/$APP/CONTAINER"
|
|
port=$(docker port $id 5000 | sed 's/0.0.0.0://')
|
|
echo $port > "$DOKKU_ROOT/$APP/PORT"
|
|
echo "http://$(< "$DOKKU_ROOT/HOSTNAME"):$port" > "$DOKKU_ROOT/$APP/URL"
|
|
|
|
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);
|
|
dokku deploy $APP
|
|
done
|
|
;;
|
|
|
|
help)
|
|
cat<<EOF | pluginhook commands help | sort
|
|
help Print the list of commands
|
|
plugins Print active plugins
|
|
plugins-install Install active plugins
|
|
EOF
|
|
;;
|
|
|
|
*)
|
|
for script in $(ls -d /var/lib/dokku/plugins/*/commands); do
|
|
$script "$@"
|
|
done
|
|
;;
|
|
|
|
esac
|