Last active
May 30, 2024 21:53
-
-
Save laceysanderson/e1bcc07b7d59c4d0e9624b8037e3723d to your computer and use it in GitHub Desktop.
Provides a number of docker commands for the repos I develop.
This file contains 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
## | |
## Helps with managing dockers for coding and review. | |
## | |
action=$1 | |
repoKey=$2 | |
suffix=$3 | |
drupalVer=${4:-10.2.x-dev} | |
phpVer=${5:-8.3} | |
pgsqlVer=${6:-16} | |
green=$(tput setaf 2) | |
normal=$(tput sgr0) | |
## Set Variables + commands based on repo key | |
case $repoKey in | |
tripal) | |
imageName="tripaldocker:tripal$suffix" | |
containerName="tripal$suffix" | |
dockerfile="tripaldocker/Dockerfile-php$phpVer" | |
cmdBuild="docker build --tag=$imageName --build-arg drupalversion=$drupalVer --build-arg postgresqlversion=$pgsqlVer --file $dockerfile ./" | |
cmdRun="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd):/var/www/drupal/web/modules/contrib/tripal $imageName" | |
cmdTest="docker exec --workdir=/var/www/drupal/web/modules/contrib/tripal $containerName phpunit" | |
cmdDrush="docker exec -it $containerName drush cr" | |
cmdContainerStop="docker container stop $containerName" | |
cmdContainerRm="docker container rm $containerName" | |
cmdImageRm="docker rmi $imageName" | |
;; | |
base) | |
imageName="trpcultivate-base:$suffix" | |
containerName="base$suffix" | |
dockerfile="Dockerfile" | |
cmdBuild="docker build --build-arg drupalversion=$drupalVer --build-arg phpversion=$phpVer --tag=$imageName ./" | |
cmdRun="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd):/var/www/drupal/web/modules/contrib/TripalCultivate $imageName" | |
cmdTest="docker exec $containerName phpunit" | |
cmdDrush="docker exec -it $containerName drush cr" | |
cmdContainerStop="docker container stop $containerName" | |
cmdContainerRm="docker container rm $containerName" | |
cmdImageRm="docker rmi $imageName" | |
;; | |
pheno) | |
imageName="trpcultivate-pheno:$suffix" | |
containerName="pheno$suffix" | |
dockerfile="Dockerfile" | |
cmdBuild="docker build --build-arg drupalversion=$drupalVer --build-arg phpversion=$phpVer --tag=$imageName ./" | |
cmdRun="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd):/var/www/drupal/web/modules/contrib/TripalCultivate-Phenotypes $imageName" | |
cmdTest="docker exec $containerName phpunit" | |
cmdDrush="docker exec -it $containerName drush cr" | |
cmdContainerStop="docker container stop $containerName" | |
cmdContainerRm="docker container rm $containerName" | |
cmdImageRm="docker rmi $imageName" | |
;; | |
geno) | |
imageName="trpcultivate-geno:$suffix" | |
containerName="geno$suffix" | |
dockerfile="Dockerfile" | |
cmdBuild="docker build --build-arg drupalversion=$drupalVer --build-arg phpversion=$phpVer --tag=$imageName ./" | |
cmdRun="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd):/var/www/drupal/web/modules/contrib/TripalCultivate-Genetics $imageName" | |
cmdTest="docker exec $containerName phpunit" | |
cmdDrush="docker exec -it $containerName drush cr" | |
cmdContainerStop="docker container stop $containerName" | |
cmdContainerRm="docker container rm $containerName" | |
cmdImageRm="docker rmi $imageName" | |
;; | |
germ) | |
imageName="trpcultivate-germ:$suffix" | |
containerName="germ$suffix" | |
dockerfile="Dockerfile" | |
cmdBuild="docker build --build-arg drupalversion=$drupalVer --build-arg phpversion=$phpVer --tag=$imageName ./" | |
cmdRun="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd):/var/www/drupal/web/modules/contrib/TripalCultivate-Germplasm $imageName" | |
cmdTest="docker exec $containerName phpunit" | |
cmdDrush="docker exec -it $containerName drush cr" | |
cmdContainerStop="docker container stop $containerName" | |
cmdContainerRm="docker container rm $containerName" | |
cmdImageRm="docker rmi $imageName" | |
;; | |
ecosystem) | |
imageName="trpcultivate-ecosystem:$suffix" | |
containerName="ecosystem$suffix" | |
dockerfile="Dockerfile" | |
cmdBuild="docker build --build-arg drupalversion=$drupalVer --build-arg phpversion=$phpVer --tag=$imageName ./" | |
cmdRun="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd):/var/www/drupal/web/modules/contrib/TripalCultivate-Ecosystem $imageName" | |
cmdTest="docker exec $containerName phpunit" | |
cmdDrush="docker exec -it $containerName drush cr" | |
cmdContainerStop="docker container stop $containerName" | |
cmdContainerRm="docker container rm $containerName" | |
cmdImageRm="docker rmi $imageName" | |
;; | |
theme) | |
imageName="trpcultivate-theme:$suffix" | |
containerName="theme$suffix" | |
dockerfile="Dockerfile" | |
cmdBuild="docker build --build-arg drupalversion=$drupalVer --build-arg phpversion=$phpVer --tag=$imageName ./" | |
cmdRun="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd)/trpcultivatetheme:/var/www/drupal/web/themes/trpcultivatetheme --volume=$(pwd)/trpcultivatetheme_companion:/var/www/drupal/web/modules/contrib/trpcultivatetheme_companion $imageName" | |
cmdTest="Do Not Run tests via phpunit" | |
cmdDrush="docker exec -it $containerName drush cr" | |
cmdContainerStop="docker container stop $containerName" | |
cmdContainerRm="docker container rm $containerName" | |
cmdImageRm="docker rmi $imageName" | |
;; | |
chado) | |
imageName="chado:$suffix" | |
containerName="chado$suffix" | |
dockerfile="Dockerfile" | |
cmdBuild="docker build --build-arg PGSQL_VERSION=$pgsqlVer --tag=$imageName --file docker/Dockerfile ./" | |
cmdRun="docker run -it --rm --name=$containerName --volume=$(pwd):/Chado $imageName" | |
cmdTest="docker exec -it $containerName flyway migrate" | |
cmdDrush="docker exec -it $containerName psql -U postgres -h localhost -d chado (password:chadotest)" | |
cmdContainerStop="docker container stop $containerName" | |
cmdContainerRm="docker container rm $containerName" | |
cmdImageRm="docker rmi $imageName" | |
;; | |
*) | |
imageName="$repoKey:$suffix" | |
containerName="$repoKey$suffix" | |
dockerfile="Dockerfile" | |
cmdBuild="docker build --build-arg drupalversion=$drupalVer --build-arg phpversion=$phpVer --build-arg postgresqlversion=$pgsqlVer --tag=$imageName ./" | |
cmdRun="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd):/var/www/drupal/web/modules/contrib/$repoKey $imageName" | |
cmdTest="docker exec $containerName phpunit" | |
cmdDrush="docker exec -it $containerName drush cr" | |
cmdContainerStop="docker container stop $containerName" | |
cmdContainerRm="docker container rm $containerName" | |
cmdImageRm="docker rmi $imageName" | |
;; | |
esac | |
## | |
## | |
## Now we need to actually do something ;-) | |
## | |
## | |
case $action in | |
build) | |
## Cleanup before we begin... | |
echo "" && echo "${green}$cmdContainerStop${normal}" && echo "" | |
$cmdContainerStop | |
echo "" && echo "${green}$cmdContainerRm${normal}" && echo "" | |
$cmdContainerRm | |
echo "" && echo "${green}$cmdImageRm${normal}" && echo "" | |
$cmdImageRm | |
## now build new image and then run the container... | |
echo "" && echo "${green}$cmdBuild${normal}" && echo "" | |
$cmdBuild | |
echo "" && echo "${green}$cmdRun${normal}" && echo "" | |
$cmdRun | |
## then give some helpful commands... | |
echo "" && echo "Here are some helpful commands:" | |
echo "${green}$cmdTest${normal}" | |
echo "${green}$cmdDrush${normal}" | |
echo "${green}docker exec $containerName service postgresql restart${normal}" | |
;; | |
clean) | |
## Just need to cleanup. | |
echo "" && echo "${green}$cmdContainerStop${normal}" && echo "" | |
$cmdContainerStop | |
echo "" && echo "${green}$cmdContainerRm${normal}" && echo "" | |
$cmdContainerRm | |
echo "" && echo "${green}$cmdImageRm${normal}" && echo "" | |
$cmdImageRm | |
;; | |
refresh) | |
## Cleanup before we begin... | |
echo "" && echo "${green}$cmdContainerStop${normal}" && echo "" | |
$cmdContainerStop | |
echo "" && echo "${green}$cmdContainerRm${normal}" && echo "" | |
$cmdContainerRm | |
## Just need to re-run the container from the existing image. | |
echo "" && echo "${green}$cmdRun${normal}" && echo "" | |
$cmdRun | |
## then give some helpful commands | |
echo "" && echo "Here are some helpful commands:" | |
echo "${green}$cmdTest${normal}" | |
echo "${green}$cmdDrush${normal}" | |
echo "${green}docker exec $containerName service postgresql restart${normal}" | |
;; | |
*) | |
echo "" | |
echo "${green}dockerBuddy.sh [action] [repoKey] [suffix] [drupalVersion] [phpVersion] [pgsqlVersion]${normal}" | |
echo -e "\twhere [action] is one of 'build','refresh','clean'" | |
echo -e "\t [repoKey] is one of 'tripal', 'base', 'pheno', 'geno', 'germ', 'ecosystem', 'theme' or the module machine name" | |
echo -e "\t [suffix] is used in the image and container names (e.g. PR###, Issue###)" | |
echo -e "\t [drupalVersion] is optional but if provided should match the format 10.2.x-dev" | |
echo -e "\t [phpVersion] is optional but if provided should match the format 8.3" | |
echo -e "\t [pgsqlVersion] is optional but if provided should match the format 16" | |
exit 0 | |
;; | |
esac | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment