Skip to content

Instantly share code, notes, and snippets.

@Neirda24
Created May 1, 2020 08:57
Show Gist options
  • Save Neirda24/e6367a029b3df99c9a8b15a38559d4c9 to your computer and use it in GitHub Desktop.
Save Neirda24/e6367a029b3df99c9a8b15a38559d4c9 to your computer and use it in GitHub Desktop.
Seemless use of docker

Usage

$ # Depending on your terminal (sh, bash, zsh) it may display errors or warning. But it will work ;)
$ source ./functions.sh
$ php --version # execute php inside the container and accept any arguments
$ dev # execute the symfony console on dev mode and accept any arguments
#!/usr/bin/env bash
CURRENT_BASH=$(ps -p $$ | awk '{ print $4 }' | tail -n 1)
case "${CURRENT_BASH}" in
-zsh|zsh)
CURRENT_DIR=$(cd "$(dirname "${0}")" && pwd)
;;
-bash|bash)
CURRENT_DIR=$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd)
;;
*)
echo 1>&2
echo -e "\033[0;31m\`${CURRENT_BASH}\` does not seems to be supported\033[0m" 1>&2
echo 1>&2
return 1
;;
esac
unalias php 2>/dev/null >/dev/null || true
php() {
docker exec -it symfony_php sh -c "php $*"
}
export -f php
unalias composer 2>/dev/null >/dev/null || true
composer() {
docker exec -it symfony_tools sh -c "COMPOSER_MEMORY_LIMIT=-1 composer $*"
}
export -f composer
unalias console 2>/dev/null >/dev/null || true
console() {
php bin/console "$@"
}
export -f console
unalias phpunit 2>/dev/null >/dev/null || true
phpunit() {
docker exec -it symfony_tools sh -c "php ./vendor/bin/phpunit $*"
}
export -f phpunit
unalias sf-check 2>/dev/null >/dev/null || true
sf-check() {
php vendor/bin/requirements-checker
}
export -f sf-check
unalias dev 2>/dev/null >/dev/null || true
dev() {
console --env=dev "$@"
}
export -f dev
unalias prod 2>/dev/null >/dev/null || true
prod() {
console --env=prod "$@"
}
export -f prod
unalias test 2>/dev/null >/dev/null || true
test() {
console --env=test "$@"
}
export -f test
unalias pgsql 2>/dev/null >/dev/null || true
pgsql() {
source "${CURRENT_DIR}/postgres.env"
docker exec -ti symfony_postgres sh -c "psql -U ${POSTGRES_USER} -d ${POSTGRES_DB} $*"
}
export -f pgsql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment