Created
November 24, 2016 02:55
-
-
Save fideloper/5f786553225fa1b5b28c6bd76a77f301 to your computer and use it in GitHub Desktop.
Helper for Laravel + Docker dev workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this assumes a
docker-compose.yml
file is present which expects / uses the defined environment variables found in this script.Notes:
sdnet
app
within thedocker-compose.yml
file