1
1
#! /usr/bin/env bash
2
2
# #
3
- # Seed image with a database from file.
3
+ # Seed image with a database from a file.
4
4
# @see https://github.com/drevops/mariadb-drupal-data/blob/main/seed.sh
5
5
#
6
- # The seeding process has 3- phases:
6
+ # The seeding process has 3 phases:
7
7
# 1. Create extracted DB files by starting a temporary container and importing the database.
8
8
# 2. Build a new image from the base image and extracted DB files.
9
9
# 3. Start a container from the new image and verify that the database was imported.
18
18
set -eu
19
19
[ -n " ${DEBUG:- } " ] && set -x
20
20
21
- # Database dump file as a first argument to the script.
21
+ # Database dump file as the first argument to the script.
22
22
DB_FILE=" ${DB_FILE:- $1 } "
23
23
24
- # Destination image as a second argument to the script.
24
+ # Destination image as the second argument to the script.
25
25
DST_IMAGE=" ${DST_IMAGE:- $2 } "
26
26
27
27
# Base image to start with.
@@ -30,7 +30,7 @@ DST_IMAGE="${DST_IMAGE:-$2}"
30
30
BASE_IMAGE=" ${BASE_IMAGE:- drevops/ mariadb-drupal-data: latest} "
31
31
32
32
# 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
34
34
# as `DOCKER_DEFAULT_PLATFORM=linux/amd64 ./seed.sh path/to/db.sql myorg/myimage:latest`
35
35
DOCKER_DEFAULT_PLATFORM=" ${DOCKER_DEFAULT_PLATFORM:- } "
36
36
@@ -56,8 +56,8 @@ fail() { [ -z "${TERM_NO_COLOR:-}" ] && tput colors >/dev/null 2>&1 && printf "\
56
56
note () { printf " %s\n" " $1 " ; }
57
57
# @formatter:on
58
58
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
61
61
[ ! -f " ${DB_FILE} " ] && fail " Specified database dump file ${DB_FILE} does not exist." && exit 1
62
62
[ " ${BASE_IMAGE##*/ } " = " $BASE_IMAGE " ] && fail " ${BASE_IMAGE} should be in a format myorg/myimage." && exit 1
63
63
[ " ${DST_IMAGE##*/ } " = " $DST_IMAGE " ] && fail " ${DST_IMAGE} should be in a format myorg/myimage." && exit 1
@@ -114,12 +114,12 @@ wait_for_db_service() {
114
114
115
115
echo -n " Waiting for the service to become ready."
116
116
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."
118
118
log_container " ${cid} "
119
119
return 1
120
120
fi
121
121
log_container " ${cid} "
122
- pass " MYSQL is running."
122
+ pass " MySQL is running."
123
123
}
124
124
125
125
assert_db_system_tables_present () {
@@ -191,7 +191,7 @@ if [ -n "${DOCKER_DEFAULT_PLATFORM}" ]; then
191
191
task " Source platform architecture: ${DOCKER_DEFAULT_PLATFORM} "
192
192
fi
193
193
194
- # Normalise image - add ":latest" if tag was not provided.
194
+ # Normalize image - add ":latest" if tag was not provided.
195
195
[ -n " ${DST_IMAGE##*:* } " ] && DST_IMAGE=" ${DST_IMAGE} :latest"
196
196
note " Destination image: ${DST_IMAGE} "
197
197
note " Destination platform(s): ${DESTINATION_PLATFORMS} "
@@ -234,7 +234,7 @@ pass "Updated permissions on the seeded database files."
234
234
task " Copy expanded database files to host"
235
235
mkdir -p " ${TMP_STRUCTURE_DIR} "
236
236
docker 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
238
238
pass " Copied expanded database files to host"
239
239
240
240
stop_container " ${cid} "
0 commit comments