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)
This commit is contained in:
Paul Lietar
2013-10-28 00:30:10 +00:00
parent e04f271d8e
commit b5c8dd7436
8 changed files with 37 additions and 35 deletions

22
dokku
View File

@@ -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

View File

@@ -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
;;

View File

@@ -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

View File

@@ -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

View File

@@ -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}"

View File

@@ -18,14 +18,14 @@ case "$1" in
git-*)
APP="$(echo $2 | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g')"
APP_PATH=$HOME/$APP
APP_PATH=$DOKKU_ROOT/$APP
if [[ $1 == "git-receive-pack" && ! -d $APP_PATH ]]; then
git init --bare $APP_PATH > /dev/null
PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive"
cat > $PRERECEIVE_HOOK <<EOF
#!/bin/bash
cat | dokku git-hook $APP
cat | DOKKU_ROOT="$DOKKU_ROOT" dokku git-hook $APP
EOF
chmod +x $PRERECEIVE_HOOK
fi

View File

@@ -13,10 +13,10 @@ if ! grep -q dokku-nginx-reload "/etc/sudoers"; then
rm /tmp/sudoers.new
fi
echo "include $HOME/*/nginx.conf;" > /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

View File

@@ -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<<EOF > $HOME/$APP/nginx.conf
cat<<EOF > $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<<EOF > $HOME/$APP/nginx.conf
cat<<EOF > $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