Skip to content

Instantly share code, notes, and snippets.

@laceysanderson
Last active June 21, 2023 17:21
Show Gist options
  • Save laceysanderson/24f987c942242c2570a1f17f210e24ab to your computer and use it in GitHub Desktop.
Save laceysanderson/24f987c942242c2570a1f17f210e24ab to your computer and use it in GitHub Desktop.
Build TripalDocker images

How to use this script

Save a copy of this script somewhere on your computer. I suggest creating a Dockers directory in your home directory to keep everything organized.

cd ~/
mkdir Dockers
cd Dockers
wget https://gist.githubusercontent.com/laceysanderson/24f987c942242c2570a1f17f210e24ab/raw/5a1e1cfc3826922476b87656996fc6b6f50b3b78/build_testing_tripalDocker.sh

Next use git to download a copy of the tripal repository replacing the [tokens] in the command first.

git clone https://github.com/tripal/tripal.git tripal-[issue/PRnum]-[shortDescription]
cd tripal-[issue/PRnum]-[shortDescription]
git checkout [git branch name]

Then run this script from the tripal clone directory and supply the issue/PR number to be used in the image/container names.

../build_testing_tripalDocker.sh [issue/PRnum]

This will build an image from the code in the current branch, create a container using that immage that mounts the current directory and forwards port 80 => 80 and starts the postgresql database.

Note: This script also supports specifying the Drupal version you want to use as follows:

../build_testing_tripalDocker.sh [issue/PRnum] [drupal version]

Example usage

> cd ~/Dockers
> git clone https://github.com/tripal/tripal.git tripal-1547-notnull
Cloning into 'tripal-1547-notnull'...
remote: Enumerating objects: 70427, done.
remote: Counting objects: 100% (3151/3151), done.
remote: Compressing objects: 100% (1265/1265), done.
remote: Total 70427 (delta 1935), reused 2870 (delta 1737), pack-reused 67276
Receiving objects: 100% (70427/70427), 46.76 MiB | 29.18 MiB/s, done.
Resolving deltas: 100% (52189/52189), done.

> cd tripal-1547-notnull
> git checkout tv4g1-issue1544-organism-infraspecies-validation
branch 'tv4g1-issue1544-organism-infraspecies-validation' set up to track 'origin/tv4g1-issue1544-organism-infraspecies-validation'.
Switched to a new branch 'tv4g1-issue1544-organism-infraspecies-validation'

❯ ../build_testing_tripalDocker.sh 1544 10.0.x
Executing...
docker build --tag=tripaldocker:tripal1544 --build-arg drupalversion=10.0.x --file tripaldocker/Dockerfile-php8.1-pgsql13 ./

[+] Building 444.0s (32/32) FINISHED                                                                                                               
 => [internal] load build definition from Dockerfile-php8.1-pgsql13                                                                           0.3s
 => => transferring dockerfile: 8.99kB                                                                                                        0.0s
 => [internal] load .dockerignore                                                                                                             0.2s
 => => transferring context: 2B                                                                                                               0.1s
 => [internal] load metadata for docker.io/library/php:8.1-apache-bullseye                                                                    4.2s
 => [auth] library/php:pull token for registry-1.docker.io                                                                                    0.0s
 => [internal] load build context                                                                                                             1.0s
 => => transferring context: 46.39kB                                                                                                          0.6s
 => [ 1/26] FROM docker.io/library/php:8.1-apache-bullseye@sha256:17682c6dc70d644593130b8249b7460af12e944e07f02076add117d5ef725f5a            0.0s
 => CACHED [ 2/26] COPY . /app                                                                                                                0.2s
 => [ 3/26] RUN chmod -R +x /app && apt-get update 1> ~/aptget.update.log   && apt-get install git unzip zip wget gnupg2 supervisor vim --y  35.0s
 => [ 4/26] RUN mkdir -p /usr/share/man/man1 && mkdir -p /usr/share/man/man7                                                                  1.2s 
 => [ 5/26] RUN DEBIAN_FRONTEND=noninteractive apt-get update   && DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql-13 postgres  31.0s
 => [ 6/26] RUN    /etc/init.d/postgresql start &&    psql --command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';"      && created  10.2s
 => [ 7/26] RUN mv /app/tripaldocker/default_files/postgresql/pg_hba.conf /etc/postgresql/13/main/pg_hba.conf                                 4.0s 
 => [ 8/26] RUN echo "listen_addresses='*'" >> /etc/postgresql/13/main/postgresql.conf   && echo "max_locks_per_transaction = 1024" >> /etc/  7.5s 
 => [ 9/26] RUN mv "/usr/local/etc/php/php.ini-development" "/usr/local/etc/php/php.ini"                                                      7.3s 
 => [10/26] RUN pecl install xdebug-3.2.1     && docker-php-ext-enable xdebug     && cat /app/tripaldocker/default_files/xdebug/xdebug-cove  22.0s 
 => [11/26] RUN set -eux;     if command -v a2enmod; then     a2enmod rewrite;   fi;     savedAptMark="$(apt-mark showmanual)";     apt-get  72.6s 
 => [12/26] RUN {     echo 'opcache.memory_consumption=128';     echo 'opcache.interned_strings_buffer=8';     echo 'opcache.max_accelerated  0.3s 
 => [13/26] RUN echo 'memory_limit = 1028M' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini                                              0.3s 
 => [14/26] WORKDIR /var/www/html                                                                                                             0.1s 
 => [15/26] RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf                                                                      0.3s 
 => [16/26] WORKDIR /var/www                                                                                                                  0.0s 
 => [17/26] RUN chmod a+x /app/tripaldocker/init_scripts/composer-init.sh   && /app/tripaldocker/init_scripts/composer-init.sh                1.7s 
 => [18/26] WORKDIR /var/www                                                                                                                  0.1s
 => [19/26] RUN composer create-project drupal/recommended-project:10.0.x --stability dev --no-install drupal9   && cd drupal9   && compose  22.3s
 => [20/26] RUN mkdir /var/www/drupal9/web/sites/default/files   && mkdir /var/www/drupal9/web/sites/default/files/simpletest   && chown -R  32.4s
 => [21/26] RUN cd /var/www/drupal9   && service apache2 start   && service postgresql start   && sleep 30   && /var/www/drupal9/vendor/dru  54.9s 
 => [22/26] WORKDIR /var/www/drupal9                                                                                                          0.0s 
 => [23/26] RUN service apache2 start   && service postgresql start   && sleep 30   && mkdir -p /var/www/drupal9/web/modules/contrib   &&   116.5s 
 => [24/26] RUN mv /app/tripaldocker/init_scripts/supervisord.conf /etc/supervisord.conf   && mv /app/tripaldocker/default_files/000-default  0.3s 
 => [25/26] RUN ln -s /var/www/drupal9/vendor/phpunit/phpunit/phpunit /usr/local/bin/   && ln -s /var/www/drupal9/vendor/drush/drush/drush /  0.3s 
 => [26/26] WORKDIR /var/www/drupal9/web                                                                                                      0.0s 
 => exporting to image                                                                                                                       16.5s 
 => => exporting layers                                                                                                                      16.5s 
 => => writing image sha256:6ac3eafc8c9e359bde7fca75598e8d4ac4db13493e867bbd7879557e02503aa2                                                  0.0s 
 => => naming to docker.io/library/tripaldocker:tripal1544                                                                                    0.0s

Executing...
docker run --publish=80:80 -tid --name=tripal1544 --volume=/Users/laceysanderson/Dockers/tripal-1547-notnull:/var/www/drupal9/web/modules/contrib/tripal tripaldocker:tripal1544

b5951fd6333f98a7596ebad68fd189b031c05695960b6fd037658ad9c8a6e4bb

Executing...
docker exec tripal1544 service postgresql restart

Restarting PostgreSQL 13 database server: main.
#! /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
dir=`pwd`
githubNum=$1
drupalVer=${2:-10.0.x-dev}
imageName="tripaldocker:tripal$githubNum"
containerName="tripal$githubNum"
dockerfile="tripaldocker/Dockerfile-php8.1-pgsql13"
green=$(tput setaf 2)
normal=$(tput sgr0)
## Build the image
buildCommand="docker build --tag=$imageName --build-arg drupalversion=$drupalVer --file $dockerfile ./"
echo "Executing..."
echo "${green}$buildCommand${normal}"
echo ""
$buildCommand
echo ""
## Run the container
runCommand="docker run --publish=80:80 -tid --name=$containerName --volume=$(pwd):/var/www/drupal9/web/modules/contrib/tripal $imageName"
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 ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment