Skip to content

Instantly share code, notes, and snippets.

@laceysanderson
Created April 15, 2024 20:33
Show Gist options
  • Save laceysanderson/f3277d166636ea455ae9d9fc8c672d73 to your computer and use it in GitHub Desktop.
Save laceysanderson/f3277d166636ea455ae9d9fc8c672d73 to your computer and use it in GitHub Desktop.
#! /bin/bash
## This script will create a docker image and then run it.
## Use the args to set the image/container name.
## Expects to run from the directory you want
## the image build from and to be mounted in the container
repoKey=$1
githubNum=$2
drupalVer=${3:-10.2.x-dev}
phpVer=${4:-8.3}
pgsqlVer=${5:-16}
green=$(tput setaf 2)
normal=$(tput sgr0)
case $repoKey in
tripal)
imageName="tripaldocker:tripal$githubNum"
containerName="tripal$githubNum"
dockerfile="tripaldocker/Dockerfile-php$phpVer"
buildCommand="docker build --tag=$imageName --build-arg drupalversion=$drupalVer --build-arg postgresqlversion=$pgsqlVer --file $dockerfile ./"
runCommand="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd):/var/www/drupal/web/modules/contrib/tripal $imageName"
phpunitCommand="docker exec --workdir=/var/www/drupal/web/modules/contrib/tripal $containerName phpunit"
;;
blast)
imageName="trpblast:$githubNum"
containerName="blast$githubNum"
buildCommand="docker build --build-arg drupalversion=$drupalVer --build-arg phpversion=$phpVer --build-arg postgresqlversion=$pgsqlVer --tag=$imageName ./"
runCommand="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd):/var/www/drupal/web/modules/contrib/tripal_blast $imageName"
phpunitCommand="docker exec $containerName phpunit"
;;
base)
imageName="trpcultivate-base:$githubNum"
containerName="base$githubNum"
buildCommand="docker build --build-arg drupalversion=$drupalVer --build-arg phpversion=$phpVer --tag=$imageName ./"
runCommand="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd):/var/www/drupal/web/modules/contrib/TripalCultivate $imageName"
phpunitCommand="docker exec $containerName phpunit"
;;
pheno)
imageName="trpcultivate-pheno:$githubNum"
containerName="pheno$githubNum"
buildCommand="docker build --build-arg drupalversion=$drupalVer --build-arg phpversion=$phpVer --tag=$imageName ./"
runCommand="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd):/var/www/drupal/web/modules/contrib/TripalCultivate-Phenotypes $imageName"
phpunitCommand="docker exec $containerName phpunit"
;;
geno)
imageName="trpcultivate-geno:$githubNum"
containerName="geno$githubNum"
buildCommand="docker build --build-arg drupalversion=$drupalVer --build-arg phpversion=$phpVer --tag=$imageName ./"
runCommand="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd):/var/www/drupal/web/modules/contrib/TripalCultivate-Genetics $imageName"
phpunitCommand="docker exec $containerName phpunit"
;;
germ)
imageName="trpcultivate-germ:$githubNum"
containerName="germ$githubNum"
buildCommand="docker build --build-arg drupalversion=$drupalVer --build-arg phpversion=$phpVer --tag=$imageName ./"
runCommand="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd):/var/www/drupal/web/modules/contrib/TripalCultivate-Germplasm $imageName"
phpunitCommand="docker exec $containerName phpunit"
;;
theme)
imageName="trpcultivate-theme:$githubNum"
containerName="theme$githubNum"
buildCommand="docker build --build-arg drupalversion=$drupalVer --build-arg phpversion=$phpVer --tag=$imageName ./"
runCommand="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"
phpunitCommand="Do Not Run tests via phpunit"
;;
*)
echo ""
echo "${green}build_testing_tripalDocker.sh [repoKey] [githubNum] [drupalVersion]${normal}"
echo -e "\twhere [repoKey] is one of 'tripal', 'base', 'pheno', 'geno', 'germ', 'theme"
echo -e "\t [githubNum] can either be the issue or PR number on github or g#.##"
echo -e "\t [drupalVersion] is optional but if provided should match the format 10.0.x-dev"
exit 0
esac
## Build the image
echo "Executing..."
echo "${green}$buildCommand${normal}"
echo ""
$buildCommand
echo ""
## Run the container
echo "Executing..."
echo "${green}$runCommand${normal}"
echo ""
$runCommand
echo ""
## Start the database
dbCommand="docker exec $containerName service postgresql restart"
echo "Executing..."
echo "${green}$dbCommand${normal}"
echo ""
$dbCommand
echo ""
echo "To run automated testing in this container:"
echo "${green}$phpunitCommand${normal}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment