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

updates for dokku v0.2.1 #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
40 changes: 22 additions & 18 deletions commands
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e;
set -e;

# Check if name is specified
if [[ $1 == mysql:* ]]; then
Expand All @@ -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/pwd_$APP"
chown dokku: "$DOKKU_ROOT/.mysql/pwd_$APP"
fi
# Fork DB image
ID=$(docker run -d hughfletcher/mysql exit 0)
Expand All @@ -62,7 +62,11 @@ case "$1" in
# docker run mysql/create mysql -h $IP -u admin -p'newpass' -e "RENAME USER admin@'%' TO $DB_USER@'%';"

# Rename persistent volume
VOLUME_PATH=$(docker inspect $ID | grep "/var/lib/docker/volumes/" | awk '{print $2}' | sed -e"s/\/layer//" | sed -e's/"//g')
VOLUME_PATH=$(docker inspect $ID | grep "/var/lib/docker/vfs/dir/" | awk '{print $2}' | sed -e's/"//g')
if [[ -z $VOLUME_PATH ]]; then
echo "Your docker version is too old, please update it"
exit 1
fi
mv $VOLUME_PATH "/var/lib/docker/volumes/mysql-$APP"
sleep 1
fi
Expand Down Expand Up @@ -103,8 +107,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/pwd_$APP" ]]; then
echo " Password: '$(cat "$DOKKU_ROOT/.mysql/pwd_$APP")'"
fi
echo " Database: 'db'"
# echo " Public port: $PORT"
Expand All @@ -121,28 +125,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/pwd_$APP" ]]; then
echo "Database is already linked"
exit 1
fi
DB_PASSWORD=$(cat "/home/git/.mysql/pwd_$APP")
DB_PASSWORD=$(cat "$DOKKU_ROOT/.mysql/pwd_$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/pwd_$APP"
fi
;;

Expand Down
2 changes: 1 addition & 1 deletion pre-release
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

APP="$1"; IMAGE="app/$APP";
if [[ -f "/home/git/.mysql/pwd_$APP" ]]; then
if [[ -f "$DOKKU_ROOT/.mysql/pwd_$APP" ]]; then
dokku mysql:link $APP $APP
fi