The Workflow™


We finish our helper script and make it running our application in Docker completely pain-free.

Let's expand on our helper script so we can remove as much boilerplate from our lives as possible.

Edit the develop script to the following:

#!/usr/bin/env bash

# Set environment variables for dev
export APP_ENV=${APP_ENV:-local}
export APP_PORT=${APP_PORT:-80}

COMPOSE="docker-compose"

# If we pass any arguments...
if [ $# -gt 0 ];then

    # If "art" is used, pass-thru to "artisan"
    # inside a new container
    if [ "$1" == "art" ]; then
        shift 1
        $COMPOSE run --rm \
            -w /var/www/html \
            app \
            php artisan "$@"

    # If "composer" is used, pass-thru to "composer"
    # inside a new container
    elif [ "$1" == "composer" ]; then
        shift 1
        $COMPOSE run --rm \
            -w /var/www/html \
            app \
            composer "$@"

    # If "test" is used, run unit tests,
    # pass-thru any extra arguments to php-unit
    elif [ "$1" == "test" ]; then
        shift 1
        $COMPOSE run --rm \
            -w /var/www/html \
            app \
            ./vendor/bin/phpunit "$@"

    # If "npm" is used, run npm
    # from our node container
    elif [ "$1" == "npm" ]; then
        shift 1
        $COMPOSE run --rm \
            -w /var/www/html \
            node \
            npm "$@"

    # If "gulp" is used, run gulp
    # from our node container
    elif [ "$1" == "gulp" ]; then
        shift 1
        $COMPOSE run --rm \
            -w /var/www/html \
            node \
            ./node_modules/.bin/gulp "$@"
    # Else, pass-thru args to docker-compose
    else
        $COMPOSE "$@"
    fi

else
    $COMPOSE ps
fi

We removed a ton of boilerplate for our most common commands!

Testing the develop Command

We can test the helpers out:

# Make sure we have our default command
./develop
# Make sure we pass-thru to docker-compose for
# un-defined helpers
./develop ps
./develop up -d

# Install composer deps
./develop composer install

# Run phpunit
./develop test

# Install node_modules dependencies
./develop npm install

# Run gulp tasks
./develop gulp

So, we have a script that makes our Docker lives much, much easier! We'll keep expanding on this a bit, however.