From b5c8dd7436d9a938c188b10be17e9f2fd9d35933 Mon Sep 17 00:00:00 2001 From: Paul Lietar Date: Mon, 28 Oct 2013 00:30:10 +0000 Subject: [PATCH] Use DOKKU_ROOT instead of HOME. HOME is not consistent if dokku is ran e.g. as root (for setup). The DOKKU_ROOT variable will also make it possible to have the repositories stored in an arbitrary location (works-ish right now) --- dokku | 22 ++++++++++++---------- plugins/00_dokku-standard/commands | 14 +++++++------- plugins/00_dokku-standard/install | 2 +- plugins/00_dokku-standard/post-delete | 2 +- plugins/config/commands | 8 ++++---- plugins/git/commands | 4 ++-- plugins/nginx-vhosts/install | 4 ++-- plugins/nginx-vhosts/post-deploy | 16 ++++++++-------- 8 files changed, 37 insertions(+), 35 deletions(-) diff --git a/dokku b/dokku index 623b3e89d..65db0ea52 100755 --- a/dokku +++ b/dokku @@ -2,6 +2,8 @@ set -e set -o pipefail 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" @@ -38,8 +40,8 @@ case "$1" in release) APP="$2"; IMAGE="$3" pluginhook pre-release $APP $IMAGE - if [[ -f "$HOME/$APP/ENV" ]]; then - id=$(cat "$HOME/$APP/ENV" | docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/app-env.sh") + 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 @@ -49,20 +51,20 @@ case "$1" in deploy) APP="$2"; IMAGE="$3" pluginhook pre-deploy $APP $IMAGE - if [[ ! -f "$HOME/$APP/PORT" ]]; then + 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 > "$HOME/$APP/CONTAINER" + echo $id > "$DOKKU_ROOT/$APP/CONTAINER" port=$(docker port $id 5000) - echo $port > "$HOME/$APP/PORT" - echo "http://$(< "$HOME/HOSTNAME"):$port" > "$HOME/$APP/URL" + echo $port > "$DOKKU_ROOT/$APP/PORT" + echo "http://$(< "$DOKKU_ROOT/HOSTNAME"):$port" > "$DOKKU_ROOT/$APP/URL" else # Regular deploy - oldid=$(< "$HOME/$APP/CONTAINER") + oldid=$(< "$DOKKU_ROOT/$APP/CONTAINER") docker kill $oldid > /dev/null - port=$(< "$HOME/$APP/PORT") + port=$(< "$DOKKU_ROOT/$APP/PORT") id=$(docker run -d -p ":$port" -e "PORT=$port" $IMAGE /bin/bash -c "/start web") - echo $id > "$HOME/$APP/CONTAINER" + echo $id > "$DOKKU_ROOT/$APP/CONTAINER" fi pluginhook post-deploy $APP $port ;; @@ -84,7 +86,7 @@ case "$1" in # temporary hack for https://github.com/progrium/dokku/issues/82 deploy:all) - for app in $(ls -d $HOME/*/); do + for app in $(ls -d $DOKKU_ROOT/*/); do APP=$(basename $app); IMAGE="app/$APP" dokku deploy $APP $IMAGE diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index 43dfdfa49..7493a57fe 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -6,13 +6,13 @@ set -e; case "$1" in exit 1 fi APP="$2"; IMAGE="app/$APP"; - if [[ ! -d "$HOME/$APP" ]]; then + if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then echo "App does not exist" exit 1 fi pluginhook pre-delete $APP - ID=$(< "$HOME/$APP/CONTAINER") + ID=$(< "$DOKKU_ROOT/$APP/CONTAINER") docker stop $ID > /dev/null docker images | grep $IMAGE | awk '{print $3}' | xargs docker rmi &> /dev/null & @@ -22,7 +22,7 @@ set -e; case "$1" in ;; logs) - CONTAINER=$(<$HOME/$2/CONTAINER) + CONTAINER=$(<$DOKKU_ROOT/$2/CONTAINER) docker logs $CONTAINER | tail -n 100 ;; @@ -32,7 +32,7 @@ set -e; case "$1" in exit 1 fi APP="$2"; IMAGE="app/$APP" - if [[ ! -d "$HOME/$APP" ]]; then + if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then echo "App $APP does not exist" exit 1 fi @@ -42,13 +42,13 @@ set -e; case "$1" in url) APP="$2"; - if [[ ! -d "$HOME/$APP" ]]; then + if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then echo "App $APP does not exist" exit 1 fi - if [[ -f "$HOME/$APP/URL" ]]; then - echo $(< "$HOME/$APP/URL") + if [[ -f "$DOKKU_ROOT/$APP/URL" ]]; then + echo $(< "$DOKKU_ROOT/$APP/URL") fi ;; diff --git a/plugins/00_dokku-standard/install b/plugins/00_dokku-standard/install index b5acc37f8..8e9da8bc0 100755 --- a/plugins/00_dokku-standard/install +++ b/plugins/00_dokku-standard/install @@ -2,7 +2,7 @@ sed -i 's/docker -d$/docker -d -r=true/' /etc/init/docker.conf -echo $HOSTNAME > $HOME/HOSTNAME +echo $HOSTNAME > $DOKKU_ROOT/HOSTNAME # temporary hack for https://github.com/progrium/dokku/issues/82 diff --git a/plugins/00_dokku-standard/post-delete b/plugins/00_dokku-standard/post-delete index 58365c0c1..4dfa73277 100755 --- a/plugins/00_dokku-standard/post-delete +++ b/plugins/00_dokku-standard/post-delete @@ -1,3 +1,3 @@ #!/bin/bash set -e -[[ -n $1 ]] && rm -r "/home/git/$1" > /dev/null +[[ -n $1 ]] && rm -r "$DOKKU_ROOT/$1" > /dev/null diff --git a/plugins/config/commands b/plugins/config/commands index e6e8a79d6..4da9d0c82 100755 --- a/plugins/config/commands +++ b/plugins/config/commands @@ -8,10 +8,10 @@ if [[ $1 == config ]] || [[ $1 == config:* ]]; then exit 1 else APP="$2" - ENV_FILE="$HOME/$APP/ENV" + ENV_FILE="$DOKKU_ROOT/$APP/ENV" # Check if app exists with the same name - if [ ! -d "$HOME/$APP" ]; then + if [ ! -d "$DOKKU_ROOT/$APP" ]; then echo "App $APP does not exist" exit 1 fi @@ -105,7 +105,7 @@ case "$1" in exit 1 fi - APP="$2"; APP_DIR="$HOME/$APP" + APP="$2"; APP_DIR="$DOKKU_ROOT/$APP" ENV_ADD="" ENV_TEMP=`cat "${ENV_FILE}"` ID=$(< "$APP_DIR/CONTAINER") @@ -149,7 +149,7 @@ case "$1" in exit 1 fi - APP="$2"; APP_DIR="$HOME/$APP" + APP="$2"; APP_DIR="$DOKKU_ROOT/$APP" ENV_TEMP=`cat "${ENV_FILE}"` ID=$(< "$APP_DIR/CONTAINER") VARS="${*:3}" diff --git a/plugins/git/commands b/plugins/git/commands index c128288f7..ecb4cf37d 100755 --- a/plugins/git/commands +++ b/plugins/git/commands @@ -18,14 +18,14 @@ case "$1" in git-*) APP="$(echo $2 | perl -pe 's/(? /dev/null PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive" cat > $PRERECEIVE_HOOK < /etc/nginx/conf.d/dokku.conf +echo "include $DOKKU_ROOT/*/nginx.conf;" > /etc/nginx/conf.d/dokku.conf sed -i 's/# server_names_hash_bucket_size/server_names_hash_bucket_size/' /etc/nginx/nginx.conf -[[ $(dig +short $HOSTNAME) ]] && echo $HOSTNAME > $HOME/VHOST +[[ $(dig +short $HOSTNAME) ]] && echo $HOSTNAME > $DOKKU_ROOT/VHOST /etc/init.d/nginx start diff --git a/plugins/nginx-vhosts/post-deploy b/plugins/nginx-vhosts/post-deploy index 1a02d7118..5ea998676 100755 --- a/plugins/nginx-vhosts/post-deploy +++ b/plugins/nginx-vhosts/post-deploy @@ -1,11 +1,11 @@ #!/bin/bash set -e APP="$1"; PORT="$2" -WILDCARD_SSL="$HOME/ssl" -SSL="$HOME/$APP/ssl" +WILDCARD_SSL="$DOKKU_ROOT/ssl" +SSL="$DOKKU_ROOT/$APP/ssl" -if [[ -f "$HOME/VHOST" ]]; then - VHOST=$(< "$HOME/VHOST") +if [[ -f "$DOKKU_ROOT/VHOST" ]]; then + VHOST=$(< "$DOKKU_ROOT/VHOST") SUBDOMAIN=${APP/%\.${VHOST}/} if [[ "$APP" == *.* ]] && [[ "$SUBDOMAIN" == "$APP" ]]; then hostname="${APP/\//-}" @@ -21,7 +21,7 @@ if [[ -f "$HOME/VHOST" ]]; then # ssl based nginx.conf if [[ -n "$SSL_INUSE" ]]; then - cat< $HOME/$APP/nginx.conf + cat< $DOKKU_ROOT/$APP/nginx.conf upstream $APP { server 127.0.0.1:$PORT; } server { listen 80; @@ -54,10 +54,10 @@ server { } EOF - echo "https://$hostname" > "$HOME/$APP/URL" + echo "https://$hostname" > "$DOKKU_ROOT/$APP/URL" else # default nginx.conf - cat< $HOME/$APP/nginx.conf + cat< $DOKKU_ROOT/$APP/nginx.conf upstream $APP { server 127.0.0.1:$PORT; } server { listen 80; @@ -76,7 +76,7 @@ server { } EOF - echo "http://$hostname" > "$HOME/$APP/URL" + echo "http://$hostname" > "$DOKKU_ROOT/$APP/URL" fi pluginhook nginx-pre-reload $APP sudo /etc/init.d/nginx reload