From fa6f2e594e013c1f97bdb783ef13a6cdde865f01 Mon Sep 17 00:00:00 2001 From: deantchi <21262275+deantchi@users.noreply.github.com> Date: Thu, 8 Aug 2024 16:11:23 -0700 Subject: [PATCH] [stacks-blockchain-api]: fix postgres restore from archive file --- hirosystems/stacks-blockchain-api/Chart.yaml | 2 +- hirosystems/stacks-blockchain-api/values.yaml | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/hirosystems/stacks-blockchain-api/Chart.yaml b/hirosystems/stacks-blockchain-api/Chart.yaml index 45957bc..0240b15 100644 --- a/hirosystems/stacks-blockchain-api/Chart.yaml +++ b/hirosystems/stacks-blockchain-api/Chart.yaml @@ -41,4 +41,4 @@ sources: - https://github.com/hirosystems/stacks-blockchain-api - https://docs.hiro.so/api - https://docs.hiro.so/get-started/stacks-blockchain-api -version: 5.0.10 +version: 5.0.11 diff --git a/hirosystems/stacks-blockchain-api/values.yaml b/hirosystems/stacks-blockchain-api/values.yaml index 01cc799..c7c9caa 100644 --- a/hirosystems/stacks-blockchain-api/values.yaml +++ b/hirosystems/stacks-blockchain-api/values.yaml @@ -1589,11 +1589,9 @@ postgresql: # scripts: # 0_restore_archive.sh: | # #!/bin/sh - # install_packages curl - # curl https://archive.dev.hiro.so/mainnet/stacks-blockchain-api-pg/stacks-blockchain-api-pg-15-latest.dump -o /opt/stacks-blockchain-api-postgres.dump # export PGPASSWORD=${POSTGRES_PASSWORD} - # pg_restore --username postgres --verbose --jobs 4 --dbname stacks_blockchain_api /opt/stacks-blockchain-api-postgres.dump - # rm -f /opt/stacks-blockchain-api-postgres.dump + # pg_restore --username postgres --verbose --jobs 4 --dbname stacks_blockchain_api /bitnami/postgresql/stacks-blockchain-api-postgres.dump + # rm -f /bitnami/postgresql/stacks-blockchain-api-postgres.dump # 1_configure_schema.sql: | # REVOKE ALL ON DATABASE stacks_blockchain_api FROM public; # GRANT ALL PRIVILEGES ON DATABASE stacks_blockchain_api TO postgres; @@ -1605,5 +1603,26 @@ postgresql: # REVOKE ALL ON SCHEMA public FROM public; # REVOKE ALL ON SCHEMA stacks_blockchain_api FROM public; # GRANT ALL ON SCHEMA stacks_blockchain_api TO postgres; + initContainers: + - name: pg-init-helper + image: google/cloud-sdk:alpine + command: + - /bin/sh + - -c + - -- + - | + if [ -z "$(ls -A /bitnami/postgresql)" ]; then + echo "Postgres dir is empty, downloading archive file..." + curl https://archive.hiro.so/mainnet/stacks-blockchain-api-pg/stacks-blockchain-api-pg-15-latest.dump -o /bitnami/postgresql/stacks-blockchain-api-postgres.dump + else + echo "Postgres dir is not empty, exiting..." + fi + securityContext: + runAsGroup: 0 + runAsNonRoot: true + runAsUser: 1337 + volumeMounts: + - mountPath: /bitnami/postgresql + name: data persistence: size: 50Gi