Helper for Laravel + Docker dev workflow
#!/usr/bin/env bash
# Set environment variables for dev
export APP_ENV=local
export APP_PORT=80
export DB_PORT=3306
export DB_ROOT_PASS=secret
export DB_NAME=homestead
export DB_USER=homestead
export DB_PASS=secret
# If we pass any arguments...
if [ $# -gt 0 ];then
# Get name of current network and docker-compose built image
NETWORK=$(docker network ls | grep sdnet | awk '{print $2}')
IMAGE=$(docker images | grep _app | awk '{print $1}')
# If "art" is used, pass-thru to "artisan"
# inside a new container
if [ "$1" == "art" ]; then
shift 1
docker run --rm -it \
-v $(pwd):/opt \
-w /opt \
--network=$NETWORK \
$IMAGE \
php artisan "$@"
# If "test" is used, run unit tests,
# pass-thru any extra arguments to php-unit
elif [ "$1" == "test" ]; then
shift 1
docker run --rm -it \
-v $(pwd):/opt \
-w /opt \
--network=$NETWORK \
$IMAGE \
./vendor/bin/phpunit
# Else, pass-thru args to docker-compose
else
docker-compose "$@"
fi
fi