Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Update stuff #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions commands
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [[ $1 == mysql:* ]]; then
else
APP="$2"
# Check if app exists with the same name
if [[ -d "/home/git/$APP" ]]; then
if [[ -d " $DOKKU_ROOT/$APP" ]]; then
APP_EXISTS=true
else
APP_EXISTS=false
Expand Down Expand Up @@ -39,12 +39,12 @@ case "$1" in
# DB_NAME=$(echo "www.atomic24.com" | sed -e 's/\.//g')
# DB_USER='user'$RANDOM
# Temporarily store it to a file
if [[ ! -d /home/git/.mysql ]]; then
mkdir -p /home/git/.mysql
chown -R git: /home/git/.mysql
if [[ ! -d $DOKKU_ROOT/.mysql ]]; then
mkdir -p $DOKKU_ROOT/.mysql
chown -R dokku: $DOKKU_ROOT/.mysql
fi
echo $DB_PASS > "/home/git/.mysql/pwd_$APP"
chown git: "/home/git/.mysql/pwd_$APP"
echo $DB_PASS > "$DOKKU_ROOT/.mysql/pass_$APP"
chown dokku: "$DOKKU_ROOT/.mysql/pass_$APP"
fi
# Fork DB image
ID=$(docker run -d hughfletcher/mysql exit 0)
Expand Down Expand Up @@ -103,8 +103,8 @@ case "$1" in
echo
echo " Host: $IP"
echo " User: 'admin'"
if [[ -f "/home/git/.mysql/pwd_$APP" ]]; then
echo " Password: '$(cat "/home/git/.mysql/pwd_$APP")'"
if [[ -f " $DOKKU_ROOT/.mysql/pass_$APP" ]]; then
echo " Password: '$(cat " $DOKKU_ROOT/.mysql/pass_$APP")'"
fi
echo " Database: 'db'"
# echo " Public port: $PORT"
Expand All @@ -121,28 +121,28 @@ case "$1" in
fi
DB_IMAGE="mysql/$3"
# Check temporarily file
if [[ ! -f "/home/git/.mysql/pwd_$APP" ]]; then
if [[ ! -f " $DOKKU_ROOT/.mysql/pass_$APP" ]]; then
echo "Database is already linked"
exit 1
fi
DB_PASSWORD=$(cat "/home/git/.mysql/pwd_$APP")
DB_PASSWORD=$(cat " $DOKKU_ROOT/.mysql/pass_$APP")
ID=$(docker ps -a | grep "$DB_IMAGE":latest | awk '{print $1}')
IP=$(docker inspect $ID | grep IPAddress | awk '{ print $2 }' | tr -d ',"')
# Write database connection vars to app's ENV file
# I know there has to be a more eloquent method of doing this...
HOST="DB_HOST=$IP"
cat "/home/git/$APP/ENV" | grep "$HOST" || echo "export $HOST" >> "/home/git/$APP/ENV"
cat " $DOKKU_ROOT/$APP/ENV" | grep "$HOST" || echo "export $HOST" >> " $DOKKU_ROOT/$APP/ENV"
USER="DB_USER=admin"
cat "/home/git/$APP/ENV" | grep "$USER" || echo "export $USER" >> "/home/git/$APP/ENV"
cat " $DOKKU_ROOT/$APP/ENV" | grep "$USER" || echo "export $USER" >> " $DOKKU_ROOT/$APP/ENV"
PASS="DB_PASS=$DB_PASSWORD"
cat "/home/git/$APP/ENV" | grep "$PASS" || echo "export $PASS" >> "/home/git/$APP/ENV"
cat " $DOKKU_ROOT/$APP/ENV" | grep "$PASS" || echo "export $PASS" >> " $DOKKU_ROOT/$APP/ENV"
NAME="DB_NAME=db"
cat "/home/git/$APP/ENV" | grep "$NAME" || echo "export $NAME" >> "/home/git/$APP/ENV"
cat " $DOKKU_ROOT/$APP/ENV" | grep "$NAME" || echo "export $NAME" >> " $DOKKU_ROOT/$APP/ENV"
PORT="DB_PORT=3306"
cat "/home/git/$APP/ENV" | grep "$PORT" || echo "export $PORT" >> "/home/git/$APP/ENV"
cat " $DOKKU_ROOT/$APP/ENV" | grep "$PORT" || echo "export $PORT" >> " $DOKKU_ROOT/$APP/ENV"
echo
echo "-----> $APP linked to $DB_IMAGE database"
rm "/home/git/.mysql/pwd_$APP"
rm " $DOKKU_ROOT/.mysql/pass_$APP"
fi
;;

Expand Down