Last active
February 27, 2024 19:45
-
-
Save fiver-watson/e9565da19283d7554a40e324a7665c91 to your computer and use it in GitHub Desktop.
Load demo data script for AtoM docker env
This file contains hidden or 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
# AtoM bash script to load demo data into a docker environment | |
# Created by Dan Gillean, Artefactual Systems - [email protected] | |
# CC-BY-SA 4.0 | |
# v1 - created June 29, 2018 | |
# v2 - fix typos, June 29, 2018 | |
# v3 - update for AtoM 2.6 compatibility, March 31, 2020 | |
# v4 - introduce optional choice for regen derivs, July 29, 2020 | |
# v5 - simplify uploads/downloads replacement; add change log, July 30, 2020 | |
# v6 - modify for use in AtoM Docker Compose env, August 17, 2023 | |
# v7 - fix restart commands for docker env, October 05, 2023 | |
# v8 - parameterize filepaths; fix user permissions; clean up, Feb 27 2024 | |
# v9 - fix new param names for clarity, Feb 27, 2024 | |
# Requirements for this version: AtoM 2.6 or higher | |
# Usage: | |
# * create a copy of the atom database, named as atom2_demo.sql | |
# * create a copy of the uploads and downloads directories | |
# * place all of these, and this script, in the parent docker installation directory | |
# on your source computer, named atom-docker | |
# * Update the permissions for everything in the parent docker directory to be owned by your main user | |
# * Update the filepaths, local username and group, and user password values in lines 30-37 and save | |
# * To run: bash /path/to/load-demo-docker.sh | |
#!/usr/bin/env bash | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
# set -o xtrace --> FOR DEBUGGING! | |
__atom="/path/to/atom-docker/atom" | |
__atom_uploads="${__atom}/uploads" | |
__atom_downloads="${__atom}/downloads" | |
__uploads_source="/path/to/atom-docker/uploads/r" | |
__downloads_source="/path/to/atom-docker/downloads" | |
__db_source="/path/to/atom-docker/atom2_demo.sql" | |
__local_username="user:user" | |
__local_password="xxxxxxx" | |
clear_cache() | |
{ | |
echo "Clearing the cache" | |
docker compose exec atom php symfony cc | |
} | |
populate_index() | |
{ | |
echo "Populating the search index" | |
docker compose exec atom php -d memory_limit=-1 symfony search:populate | |
} | |
upgrade_sql() | |
{ | |
echo "Running the upgrade task" | |
docker compose exec atom php -d memory_limit=-1 symfony tools:upgrade-sql --no-confirmation | |
} | |
regen_derivs() | |
{ | |
echo "Regenerating the derivatives" | |
docker compose exec atom php symfony digitalobject:regen-derivatives --force | |
} | |
purge() | |
{ | |
echo "Purging the DB" | |
docker compose exec atom php -d memory_limit=-1 symfony tools:purge --demo | |
} | |
load_uploads() | |
{ | |
echo "Loading the uploads" | |
echo "${__local_password}" | sudo -S chown -R ${__local_username} ${__atom_uploads} | |
rsync -av --delete ${__uploads_source} ${__atom_uploads} | |
} | |
load_downloads() | |
{ | |
echo "Loading the downloads" | |
echo "${__local_password}" | sudo -S chown -R ${__local_username} ${__atom_downloads} | |
rsync -av --delete ${__downloads_source} ${__atom_downloads} | |
} | |
drop_db() | |
{ | |
echo "Dropping and recreating the DB" | |
docker compose exec percona mysql -h localhost -u atom -patom_12345 -e "DROP DATABASE IF EXISTS atom;" | |
docker compose exec percona mysql -h localhost -u atom -patom_12345 -e "CREATE DATABASE atom CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;" | |
} | |
load_db() | |
{ | |
echo "Loading the demo data" | |
docker cp ${__db_source} docker-percona-1:/atom.sql | |
docker compose exec percona bash -c "mysql -h localhost -u atom -patom_12345 atom < /atom.sql" | |
} | |
restart() | |
{ | |
echo "Restarting services" | |
docker compose restart atom | |
docker compose restart nginx | |
docker compose restart atom_worker | |
} | |
read -p "Do you want to regenerate the derivatives? Only needed if AtoM code changes introduce derivative size or format changes... (y/n)" yn | |
case $yn in | |
[Yy]* ) | |
purge | |
load_uploads | |
load_downloads | |
drop_db | |
load_db | |
upgrade_sql | |
regen_derivs | |
clear_cache | |
populate_index | |
restart | |
clear_cache | |
;; | |
[Nn]* ) | |
purge | |
load_uploads | |
load_downloads | |
drop_db | |
load_db | |
upgrade_sql | |
clear_cache | |
populate_index | |
restart | |
clear_cache | |
;; | |
esac | |
if [ $? -eq 0 ] | |
then | |
echo "Successfully loaded demo data" | |
exit 0 | |
else | |
echo "Data load failed" >&2 | |
exit 1 | |
fi | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment