From 0d90ad05ecde8fdf12679057eb9d9e209f51c162 Mon Sep 17 00:00:00 2001 From: Michael Polidori Date: Wed, 2 Oct 2024 12:16:41 -0400 Subject: [PATCH] Fix migration script --- .docker-compose.vital-strategies-theme.yaml | 1 + Makefile | 8 ++++---- ckan/post_install_functions.sh | 10 ++++++---- db/migration/upgrade_databases.sh | 16 ++++++++++------ 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/.docker-compose.vital-strategies-theme.yaml b/.docker-compose.vital-strategies-theme.yaml index 6cfbadc..bb917fd 100644 --- a/.docker-compose.vital-strategies-theme.yaml +++ b/.docker-compose.vital-strategies-theme.yaml @@ -29,6 +29,7 @@ services: install_standard_ckan_extension_github -r ckan/ckanext-geoview && \ install_standard_ckan_extension_github -r datopian/ckanext-sentry -b 2.10 && \ install_standard_ckan_extension_github -r datopian/ckanext-gtm && \ + install_standard_ckan_extension_github -r ckan/ckanext-googleanalytics -b 0055c3e06347c8ed31b7abe47aa06e3e44e0bf63 &&\ install_standard_ckan_extension_github -r datopian/ckanext-s3filestore -b ckan-2.10 && \ cd ~/venv/src/ckanext-querytool && ~/venv/bin/python setup.py compile_catalog -l en -f && \ cd ~/venv/src/ckanext-querytool && ~/venv/bin/python setup.py compile_catalog -l es -f && \ diff --git a/Makefile b/Makefile index 078e5d7..923449c 100644 --- a/Makefile +++ b/Makefile @@ -65,10 +65,10 @@ clean-rebuild: docker-compose $(COMPOSE_FILES) up -d nginx && make cron backup-db: - docker-compose $(COMPOSE_FILES) exec -T db pg_dump -U postgres --format=custom -d ckan > ckan.dump - docker-compose ${COMPOSE_FILES} exec -T ckan sh -c "cd /var/lib/ckan && tar -czf /tmp/ckan_data.tar.gz data" - docker cp $$(docker-compose ${COMPOSE_FILES} ps -q ckan):/tmp/ckan_data.tar.gz ckan_data.tar.gz - docker-compose $(COMPOSE_FILES) exec -T datastore-db pg_dump -U postgres --format=custom -d datastore > datastore.dump + docker-compose $(COMPOSE_FILES) exec -T db pg_dump -U postgres --format=custom -d ckan > ckan_test.dump + docker-compose ${COMPOSE_FILES} exec -T ckan sh -c "cd /var/lib/ckan && tar -czf /tmp/ckan_data_test.tar.gz data" + docker cp $$(docker-compose ${COMPOSE_FILES} ps -q ckan):/tmp/ckan_data_test.tar.gz ckan_data_test.tar.gz + docker-compose $(COMPOSE_FILES) exec -T datastore-db pg_dump -U postgres --format=custom -d datastore > datastore_test.dump upgrade-db: ./db/migration/upgrade_databases.sh "$(COMPOSE_FILES)" "$(CKAN_DB_NAME)" "$(CKAN_DB_USERNAME)" "$(DB_USERNAME)" "$(DATASTORE_DB_NAME)" "$(DATASTORE_DB_USERNAME)" diff --git a/ckan/post_install_functions.sh b/ckan/post_install_functions.sh index 9cd2c7a..998052a 100644 --- a/ckan/post_install_functions.sh +++ b/ckan/post_install_functions.sh @@ -27,12 +27,14 @@ install_standard_ckan_extension_github() { echo "#### BRANCH: $BRANCH ####" echo "#### REPO URL: $GITHUB_URL/$REPO_NAME.git ####" - # Check if the branch exists by examining the output directly BRANCH_EXISTS=$(git ls-remote --heads ${GITHUB_URL}/${REPO_NAME}.git ${BRANCH}) - if [ ! -n "$BRANCH_EXISTS" ]; then - # It might be a commit instead of a branch - BRANCH_EXISTS=$(git ls-remote --heads ${GITHUB_URL}/${REPO_NAME}.git | grep -o $BRANCH) + if [ -z "$BRANCH_EXISTS" ]; then + BRANCH_EXISTS=$(git ls-remote --tags ${GITHUB_URL}/${REPO_NAME}.git ${BRANCH}) + + if [ -z "$BRANCH_EXISTS" ]; then + BRANCH_EXISTS=$(git ls-remote ${GITHUB_URL}/${REPO_NAME}.git | grep -o ${BRANCH}) + fi fi if [ -z "$BRANCH_EXISTS" ]; then diff --git a/db/migration/upgrade_databases.sh b/db/migration/upgrade_databases.sh index 74b1d59..9758c7b 100755 --- a/db/migration/upgrade_databases.sh +++ b/db/migration/upgrade_databases.sh @@ -14,8 +14,9 @@ CKAN_SERVICE="ckan" DB_SERVICE="db" DATASTORE_SERVICE="datastore-db" CKAN_CONFIG_PATH="/etc/ckan/ckan.ini" - - +DB_SERVICE_ID=$(docker-compose ${COMPOSE_FILES} ps -q ${DB_SERVICE}) +DATASTORE_SERVICE_ID=$(docker-compose ${COMPOSE_FILES} ps -q ${DATASTORE_SERVICE}) +CKAN_SERVICE_ID=$(docker-compose ${COMPOSE_FILES} ps -q ${CKAN_SERVICE}) if [ ! -f $CKAN_BACKUP_FILE ]; then echo "" @@ -60,7 +61,8 @@ echo "" echo "### Restoring the CKAN DB from backup..." echo "" -docker-compose ${COMPOSE_FILES} exec -T ${DB_SERVICE} pg_restore -U postgres --verbose --create --clean --if-exists -d postgres < ${CKAN_BACKUP_FILE} +docker cp ${CKAN_BACKUP_FILE} ${DB_SERVICE_ID}:/${CKAN_BACKUP_FILE} +docker-compose ${COMPOSE_FILES} exec -T ${DB_SERVICE} pg_restore -U postgres --verbose --create --clean --if-exists -d postgres /ckan.dump echo "" echo "### Restoring CKAN DB from backup completed." @@ -69,7 +71,8 @@ echo "" echo "### Restoring the Datastore DB from backup..." echo "" -docker-compose ${COMPOSE_FILES} exec -T ${DATASTORE_SERVICE} pg_restore -U postgres --verbose --create --clean --if-exists -d postgres < ${DATASTORE_BACKUP_FILE} +docker cp ${DATASTORE_BACKUP_FILE} ${DATASTORE_SERVICE_ID}:/${DATASTORE_BACKUP_FILE} +docker-compose ${COMPOSE_FILES} exec -T ${DATASTORE_SERVICE} pg_restore -U postgres --verbose --create --clean --if-exists -d postgres /datastore.dump echo "" echo "### Restoring Datastore DB from backup completed." @@ -85,8 +88,9 @@ echo "" echo "### Restoring data files to CKAN..." echo "" -docker cp ${CKAN_DATA_BACKUP_FILE} $(docker-compose ${COMPOSE_FILES} ps -q ckan):/tmp/ckan_data.tar.gz -docker-compose ${COMPOSE_FILES} exec -T ${CKAN_SERVICE} bash -c "tar -xzf /tmp/ckan_data.tar.gz -C /tmp/ && cp -r /tmp/data/* /var/lib/ckan/data/ && chown -R ckan:ckan /var/lib/ckan/data" +docker cp ${CKAN_DATA_BACKUP_FILE} ${CKAN_SERVICE_ID}:/${CKAN_DATA_BACKUP_FILE} + +docker-compose ${COMPOSE_FILES} exec -T ${CKAN_SERVICE} bash -c "tar -xzf /ckan_data.tar.gz -C /data && cp -r /data/* /var/lib/ckan/data/ && chown -R ckan:ckan /var/lib/ckan/data" echo "" echo "### Data files restored to CKAN."