Skip to content

Commit

Permalink
Added .env as environment file
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenBoersma committed Jul 30, 2018
1 parent 2834238 commit e61df92
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 18 deletions.
17 changes: 17 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ init() {
DEV_SUDO='sudo';
fi

dc env conf/mysql; # fallback
dc env .env;

dc yml 'docker-compose.yml';
dc yml_if 'build/dist/docker-compose-blackfire.yml' 'conf/blackfire';
dc yml_if 'docker-custom.yml' 'docker-custom.yml';
Expand Down Expand Up @@ -169,6 +172,20 @@ dc() {
return 1;
}

env() {
local envfile=${DEV_WORKDIR}/$1 a='' c='';
if [ ! -e ${envfile} ]; then
return 1;
fi
for a in `cat ${envfile}`; do
if [ "${a:0:1}" == "#" ]; then
continue;
fi
c='export '${a};
${c};
done
}

$*;
return $?
}
Expand Down
2 changes: 0 additions & 2 deletions bin/dev_command/myroot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
dc yml build/dist/docker-compose-dbclient.yml;
dc service dbclient;

. ${DEV_WORKDIR}/conf/mysql;

dc cmd mysql "-h db -uroot -p${MYSQL_ROOT_PASSWORD} $*";

46 changes: 34 additions & 12 deletions bin/dev_command/setup
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ setup() {
cd ${DEV_DIR};

mysql() {
if [ -e ${DEV_WORKDIR}/conf/mysql ]; then
echo 'Looks to me that this machine already has MySQL configuration';
return 1;
fi
if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
export MYSQL_ROOT_PASSWORD="`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;`";
echo 'MYSQL_ROOT_PASSWORD='${MYSQL_ROOT_PASSWORD} >> ${DEV_WORKDIR}/.env;
echo 'Created a random root password for MySQL stored in '${DEV_WORKDIR}'/.env, to login as root use `dev myroot`';
fi;

local randompass="`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;`";
sed 's/\[YOURPASSWORDGOESHERE\]/'${randompass}'/' ${DEV_WORKDIR}/conf/mysql.dist > ${DEV_WORKDIR}/conf/mysql;
echo 'Created a random root password for MySQL "'${randompass}'", to login as root use `dev myroot`';

if [ -z "`docker volume ls -q -f 'name=dockerdev-mysql-volume'`" ]; then
echo 'Create a persistant database volume';
Expand All @@ -23,13 +21,17 @@ setup() {

echo 'Starting regular database user, waiting for db to become ready';
./${DEV_SELF} up db;
./${DEV_SELF} logs -f db 2>&1 | grep -m1 'mysqld: ready for connections.' >/dev/null;
./${DEV_SELF} logs -f db 2>&1 | grep -m1 'ready for connections';

local user=${USER};

# Check if already exists
echo "select * from mysql.user where user='${user}';" | dev myroot | grep "${user}" >/dev/null && return 1;

echo 'Database user has access to databases "'${user}'_*"';
echo '';
echo "create user '${user}' | ./${DEV_SELF} myroot;
echo "grant all on ${user}.* to '${user}' | ./${DEV_SELF} myroot;
echo "create user '${user}'" | ./${DEV_SELF} myroot;
echo "grant all on ${user}.* to '${user}'" | ./${DEV_SELF} myroot;
echo "update mysql.db set db = '${user}\_%' where user = '${user}';" | ./${DEV_SELF} myroot;
echo 'flush privileges;' | ./${DEV_SELF} myroot;

Expand All @@ -45,14 +47,33 @@ setup() {
echo "- ${v}";
done

read -p'?' version;
read -p'? ' version;
[ -z "${version}" ] && return 1;

touch ${DEV_WORKDIR}/workspace/.${version};

return 0;
}

suffix() {
if [ -n "${DOMAINSUFFIX}" ]; then
echo 'Listening on "*'${DOMAINSUFFIX}'"';
return 1;
fi

local suffix='' default='.localhost';
echo 'Which domain suffix do you want to listen to - default: '${default}'';
read -p' ' suffix;
if [ -z "${suffix}" ]; then
suffix=${default};
fi

echo 'DOMAINSUFFIX='${suffix} >> ${DEV_WORKDIR}/.env;
export DOMAINSUFFIX=${suffix};

return 0;
}


start() {
./${DEV_SELF} up;
Expand All @@ -64,8 +85,9 @@ setup() {
./${DEV_SELF} profile;
}

mysql;
suffix;
php;
mysql;
start;
shell;
}
Expand Down
5 changes: 5 additions & 0 deletions bin/dev_command/up
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@


if [ -z "${DOMAINSUFFIX}" ]; then
dc yml build/dist/docker-compose-suffix.yml;
fi

dc mode 'up -d --no-recreate';
dc cmd "$*";

7 changes: 7 additions & 0 deletions build/dist/docker-compose-suffix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '2'

services:
web:
environment:
- DOMAINSUFFIX=.localhost

1 change: 0 additions & 1 deletion conf/mysql.dist

This file was deleted.

6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ services:
volumes:
- ./conf.d/mysql:/etc/mysql/conf.d:ro
- dockerdev-mysql-volume:/var/lib/mysql:rw
env_file:
- ./conf/mysql
environment:
- MYSQL_ROOT_PASSWORD
network_mode: bridge
ports:
- 127.0.0.1:3306:3306
Expand Down Expand Up @@ -61,7 +61,7 @@ services:
build:
context: build/dist/web
environment:
DOMAINSUFFIX: '.localhost'
- DOMAINSUFFIX
links:
- mailcatch
- php70:fpm
Expand Down

0 comments on commit e61df92

Please sign in to comment.