#!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x case "$1" in trace) [[ -d $DOKKU_ROOT/.dokkurc ]] || mkdir -p $DOKKU_ROOT/.dokkurc [[ "$2" == "on" ]] || [[ "$2" == "off" ]] || { echo "Valid trace options are [on/off]" exit 1 } if [[ "$2" == "on" ]]; then echo "Enabling dokku trace" echo "export DOKKU_TRACE=1" > $DOKKU_ROOT/.dokkurc/DOKKU_TRACE fi if [[ "$2" == "off" ]]; then echo "Disabling dokku trace" rm -f $DOKKU_ROOT/.dokkurc/DOKKU_TRACE fi ;; delete) dokku apps:destroy $2 ;; logs) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2"; if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then CONTAINER=$(<$DOKKU_ROOT/$APP/CONTAINER) if [[ $3 == "-t" ]]; then docker logs --follow $CONTAINER else docker logs $CONTAINER | tail -n 100 fi else echo "Application's container not found" fi ;; run) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2"; IMAGE="dokku/$APP" shift 2 DOCKER_ARGS=$(: | pluginhook docker-args $APP run) # if we have a prompt, then we have a tty according to the LDP (http://www.tldp.org/LDP/abs/html/intandnonint.html) [[ ! -z "$PS1" ]] && DOKKU_RUN_OPTS="-i -t" docker run $DOKKU_RUN_OPTS $DOCKER_ARGS $IMAGE /exec "$@" ;; url | urls) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2"; SCHEME="http"; SSL="$DOKKU_ROOT/$APP/tls"; WILDCARD_SSL="$DOKKU_ROOT/tls" if [[ -e "$SSL/server.crt" && -e "$SSL/server.key" ]] || [[ -e "$WILDCARD_SSL/server.crt" && -e "$WILDCARD_SSL/server.key" ]]; then SCHEME="https" fi if [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then case "$1" in url) echo "$SCHEME://$(head -n1 "$DOKKU_ROOT/$APP/VHOST")" ;; urls) for vhost in $(< "$DOKKU_ROOT/$APP/VHOST"); do echo "$SCHEME://$vhost" done ;; esac elif [[ -f "$DOKKU_ROOT/VHOST" ]]; then echo "$SCHEME://$(< "$DOKKU_ROOT/VHOST")" else echo "$SCHEME://$(< "$DOKKU_ROOT/HOSTNAME"):$(< "$DOKKU_ROOT/$APP/PORT")" fi ;; version) cat "$DOKKU_ROOT/VERSION" || { echo "Unable to determine dokku's version" 2>&1 exit 1 } ;; help) cat && cat< [-t] Show the last logs for an application (-t follows) run Run a command in the environment of an application url Show the first URL for an application (compatibility) urls Show all URLs for an application version Print dokku's version EOF ;; *) exit $DOKKU_NOT_IMPLEMENTED_EXIT ;; esac