Skip to content

Instantly share code, notes, and snippets.

@rydurham
Last active April 20, 2023 16:07
Show Gist options
  • Save rydurham/c7d47263fa882fb5474e8bc873dcf123 to your computer and use it in GitHub Desktop.
Save rydurham/c7d47263fa882fb5474e8bc873dcf123 to your computer and use it in GitHub Desktop.
Local Docker Ops Helper Example
# Put this in your .bashrc file (or wherever you register aliases)
# Modify the path to point to your local dockerfile; you must use an absolute path
# The name of the function can be changed to suit your local setup
eoa_ops() {
cd /home/ryan/Workbench/firebrand/eoa
./ops.sh ${*:-ps}
cd $OLDPWD
}
alias eoa=eoa_ops
#!/usr/bin/env bash
# Heavily borrowed from Cris Fidao and the "Shipping Docker" course
# https://serversforhackers.com/shipping-docker
# Set environment variables for local development
COMPOSE="docker-compose"
# If we pass any arguments...
if [ $# -gt 0 ];then
# "console" will pass through to bin/console
if [ "$1" == "console" ]; then
shift 1
$COMPOSE exec \
cli \
php bin/console "$@"
# "follow" will tail the eoa var/logs/dev.log file
elif [ "$1" == "follow" ]; then
if [ -f "../../eoa/var/log/dev.log" ]; then
tail -f ../../eoa/var/log/dev.log
else
echo "Nothing to follow..."
fi
# "composer" will pass through to composer
elif [ "$1" == "composer" ]; then
shift 1
$COMPOSE exec \
cli \
composer "$@"
# "test" will run unit tests,
# passsing any extra arguments to php-unit
elif [ "$1" == "test" ]; then
shift 1
$COMPOSE exec \
cli \
./vendor/bin/simple-phpunit "$@"
# "scraper" will pass through to the scraper application container
elif [ "$1" == "scraper" ]; then
shift 1
$COMPOSE run --rm \
scraper "$@"
# "scrape" will run the scraper tool directly
elif [ "$1" == "scrape" ]; then
shift 1
$COMPOSE run --rm \
scraper \
node scraper.js "$@"
# "psql" will drop into the psql client
elif [ "$1" == "psql" ]; then
shift 1
$COMPOSE exec \
--user=postgres \
postgres \
psql "$@"
# "python" will execute scripts with python 3
elif [ "$1" == "python" ]; then
shift 1
$COMPOSE run --rm \
--user=www-data \
python python3 "$@"
# "aws" will run aws cli commands
elif [ "$1" == "aws" ]; then
shift 1
$COMPOSE run --rm \
--user=www-data \
python "$@"
# "format" will run the PHP code formatting tool
elif [ "$1" == "format" ]; then
shift 1
$COMPOSE exec \
cli \
vendor/bin/php-cs-fixer fix "$@"
# "npm" will run npm commands
elif [ "$1" == "npm" ]; then
shift 1
$COMPOSE run --rm \
node \
npm "$@"
# All other arguments will be sent through to docker-compose
else
$COMPOSE "$@"
fi
# If no argument is passed default to 'ps' to see the status of the containers
else
$COMPOSE ps
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment