Skip to content

Instantly share code, notes, and snippets.

@brianpattison
Last active December 25, 2015 15:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save brianpattison/7002558 to your computer and use it in GitHub Desktop.
Save brianpattison/7002558 to your computer and use it in GitHub Desktop.
Dokku command line tool
[core]
...
[remote "dokku"]
url = git@remote:appname
fetch = +refs/heads/*:refs/remotes/dokku/*
# Looks for the git remote "dokku" and runs dokku command via SSH
# Assumes user is root and no password is needed
# Example:
# dokku logs --> ssh root@remote 'dokku logs appname'
dokku() {
if [ -f ".git/config" ]; then
config=$(cat .git/config)
if [[ "$config" == *'[remote "dokku"]'* ]]; then
host=$(echo $config | sed 's/.*\[remote "dokku"\][[:space:]]*url[[:space:]]*=[[:space:]]git@\([a-z.0-9\-]*\):\([a-z.0-9\-\_]*\).*/\1/')
app=$(echo $config | sed 's/.*\[remote "dokku"\][[:space:]]*url[[:space:]]*=[[:space:]]git@\([a-z.0-9\-]*\):\([a-z.0-9\-\_]*\).*/\2/')
dokku_command="$1"
if [ "$dokku_command" == "logs" ]; then
eval "ssh root@$host 'dokku logs $app'"
elif [ "$dokku_command" == "run" ]; then
shift 1
eval "ssh root@$host 'dokku run $app $@'"
elif [ "$dokku_command" == "url" ]; then
eval "ssh root@$host 'dokku url $app'"
else
echo " Host: $host App: $app"
echo "Usage:"
echo " dokku logs Show the last logs for the application"
echo " dokku run <cmd> Run a command in the environment of the application"
echo " dokku url Show the URL for the application"
fi
else
echo 'Could not find a git remote named "dokku".'
fi
else
echo "Not a git repository."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment