11#! /usr/bin/env bash
22# #
3- # Seed image with a database from file.
3+ # Seed image with a database from a file.
44# @see https://github.com/drevops/mariadb-drupal-data/blob/main/seed.sh
55#
6- # The seeding process has 3- phases:
6+ # The seeding process has 3 phases:
77# 1. Create extracted DB files by starting a temporary container and importing the database.
88# 2. Build a new image from the base image and extracted DB files.
99# 3. Start a container from the new image and verify that the database was imported.
1818set -eu
1919[ -n " ${DEBUG:- } " ] && set -x
2020
21- # Database dump file as a first argument to the script.
21+ # Database dump file as the first argument to the script.
2222DB_FILE=" ${DB_FILE:- $1 } "
2323
24- # Destination image as a second argument to the script.
24+ # Destination image as the second argument to the script.
2525DST_IMAGE=" ${DST_IMAGE:- $2 } "
2626
2727# Base image to start with.
@@ -30,7 +30,7 @@ DST_IMAGE="${DST_IMAGE:-$2}"
3030BASE_IMAGE=" ${BASE_IMAGE:- drevops/ mariadb-drupal-data: latest} "
3131
3232# Docker target platform architecture.
33- # Note that some shells report platform incorrectly. In such cases, run
33+ # Note that some shells report the platform incorrectly. In such cases, run
3434# as `DOCKER_DEFAULT_PLATFORM=linux/amd64 ./seed.sh path/to/db.sql myorg/myimage:latest`
3535DOCKER_DEFAULT_PLATFORM=" ${DOCKER_DEFAULT_PLATFORM:- } "
3636
@@ -56,8 +56,8 @@ fail() { [ -z "${TERM_NO_COLOR:-}" ] && tput colors >/dev/null 2>&1 && printf "\
5656note () { printf " %s\n" " $1 " ; }
5757# @formatter:on
5858
59- [ -z " ${DB_FILE} " ] && fail " Path to the database dump file must be provided as a first argument." && exit 1
60- [ -z " ${DST_IMAGE} " ] && fail " Destination docker image name must be provided as a second argument." && exit 1
59+ [ -z " ${DB_FILE} " ] && fail " Path to the database dump file must be provided as the first argument." && exit 1
60+ [ -z " ${DST_IMAGE} " ] && fail " Destination Docker image name must be provided as the second argument." && exit 1
6161[ ! -f " ${DB_FILE} " ] && fail " Specified database dump file ${DB_FILE} does not exist." && exit 1
6262[ " ${BASE_IMAGE##*/ } " = " $BASE_IMAGE " ] && fail " ${BASE_IMAGE} should be in a format myorg/myimage." && exit 1
6363[ " ${DST_IMAGE##*/ } " = " $DST_IMAGE " ] && fail " ${DST_IMAGE} should be in a format myorg/myimage." && exit 1
@@ -114,12 +114,12 @@ wait_for_db_service() {
114114
115115 echo -n " Waiting for the service to become ready."
116116 if ! docker exec " ${user[@]} " -i " ${cid} " sh -c " until nc -z localhost 3306; do sleep 1; echo -n .; done; echo" ; then
117- fail " MYSQL service did not start successfully."
117+ fail " MySQL service did not start successfully."
118118 log_container " ${cid} "
119119 return 1
120120 fi
121121 log_container " ${cid} "
122- pass " MYSQL is running."
122+ pass " MySQL is running."
123123}
124124
125125assert_db_system_tables_present () {
@@ -191,7 +191,7 @@ if [ -n "${DOCKER_DEFAULT_PLATFORM}" ]; then
191191 task " Source platform architecture: ${DOCKER_DEFAULT_PLATFORM} "
192192fi
193193
194- # Normalise image - add ":latest" if tag was not provided.
194+ # Normalize image - add ":latest" if tag was not provided.
195195[ -n " ${DST_IMAGE##*:* } " ] && DST_IMAGE=" ${DST_IMAGE} :latest"
196196note " Destination image: ${DST_IMAGE} "
197197note " Destination platform(s): ${DESTINATION_PLATFORMS} "
@@ -234,7 +234,7 @@ pass "Updated permissions on the seeded database files."
234234task " Copy expanded database files to host"
235235mkdir -p " ${TMP_STRUCTURE_DIR} "
236236docker cp " ${cid} " :/home/db-data/. " ${TMP_STRUCTURE_DIR} /" > /dev/null
237- [ ! -d " ${TMP_STRUCTURE_DIR} /mysql" ] && fail " Unable to copy expanded database files to host " && ls -al " ${TMP_STRUCTURE_DIR} " && exit 1
237+ [ ! -d " ${TMP_STRUCTURE_DIR} /mysql" ] && fail " Unable to copy expanded database files to host" && ls -al " ${TMP_STRUCTURE_DIR} " && exit 1
238238pass " Copied expanded database files to host"
239239
240240stop_container " ${cid} "
0 commit comments