Created
September 20, 2021 17:00
-
-
Save jnm/dd323e0ff5be0d79e12e76bb9dfb7aed to your computer and use it in GitHub Desktop.
Refresh KPI front-end files without rebuilding them
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
#!/bin/bash | |
# jnm 20210526 | |
set -e | |
test -e kpi && test -e kobo-install || ( | |
echo 'This script must be run from the directory where `kpi` and `kobo-install` reside.' | |
exit 1 | |
) | |
echo 'Hello! This script assumes you have recently rebuilt the KPI image' | |
echo 'using `./run.py -cf build kpi`, `./run.py -bkf`, or similar.' | |
echo 'Despite doing this, old static files are still being served(!) because' | |
echo 'the fresh static files inside the newly built Docker image are being' | |
echo 'shadowed upon container creation by the `../kpi:/srv/src/kpi`' | |
echo 'volume defined in `kobo-docker/docker-compose.frontend.override.yml`.' | |
echo | |
echo 'To make a long story short, this script fixes the problem :D' | |
echo "If you HAVE NOT yet rebuilt the KPI image, this won't help!" | |
echo | |
echo 'Press return to proceed, or CTRL+C to exit.' | |
read trash | |
echo 'Looking for KPI images…' | |
latest_kpi_image=$(kobo-install/run.py -cf images | grep _kpi_ | awk '{print $4}') | |
echo 'The latest KPI image found is:' | |
docker images | sed -n "1p;/$latest_kpi_image/p" | |
echo | |
echo 'Starting a temporary container using latest KPI image…' | |
container_id=$( | |
docker run --rm --detach "$latest_kpi_image" ping localhost | |
) | |
echo 'Copying files generated by `npm run build` from within image to `kpi/jsapp/compiled/`…' | |
rm -r kpi/jsapp/compiled | |
docker cp "$container_id:/srv/src/kpi/jsapp/compiled" kpi/jsapp/ | |
docker stop "$container_id" > /dev/null & | |
echo 'Updating static files served by NGINX…' | |
echo | |
kobo-install/run.py -cf run --rm kpi \ | |
bash -c 'python manage.py collectstatic --noinput && rsync -aq --delete --chown=www-data "${KPI_SRC_DIR}/staticfiles/" "${NGINX_STATIC_DIR}/"' \ | |
2>&1 | sed 's/^/\t/' | |
echo | |
kobo-install/run.py -cf ps | grep kpi > /dev/null && ( | |
echo 'Restarting KPI container…' | |
kobo-install/run.py -cf restart kpi | |
echo | |
) | |
echo 'Waiting for temporary container to stop…' | |
wait | |
echo 'Done?!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment