Skip to content

Commit bce75d5

Browse files
authored
feat(mirror-node): Enhance mirror-node external database feature (#1230)
Signed-off-by: instamenta <[email protected]>
1 parent 3ae7d7f commit bce75d5

File tree

14 files changed

+397
-245
lines changed

14 files changed

+397
-245
lines changed

.github/workflows/flow-task-test.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575

7676
- name: Run Example Task File Test with type ${{ matrix.type }}
7777
run: |
78+
cd examples/external-database-test
7879
export CONSENSUS_NODE_VERSION=v0.58.3
79-
SOLO_CLUSTER_NAME=solo-task-test-${{ matrix.type }}-${{ github.run_id }}-${{ github.run_attempt }} task default
80-
.github/workflows/script/solo_smoke_test.sh ${{ matrix.type }}
81-
task clean
80+
SOLO_CLUSTER_NAME=solo-task-test-${{ matrix.type }}-${{ github.run_id }}-${{ github.run_attempt }} task install
81+
task destroy

.github/workflows/script/helper.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ function create_test_account ()
77
cd solo
88

99
# create new account and extract account id
10-
npm run solo-test -- account create --deployment solo-deployment --hbar-amount 100 --generate-ecdsa-key --set-alias > test.log
10+
npm run solo-test -- account create --deployment solo-e2e --hbar-amount 100 --generate-ecdsa-key --set-alias > test.log
1111
export OPERATOR_ID=$(grep "accountId" test.log | awk '{print $2}' | sed 's/"//g'| sed 's/,//g')
1212
echo "OPERATOR_ID=${OPERATOR_ID}"
1313
rm test.log
1414

1515
# get private key of the account
16-
npm run solo-test -- account get --deployment solo-deployment --account-id ${OPERATOR_ID} --private-key > test.log
16+
npm run solo-test -- account get --deployment solo-e2e --account-id ${OPERATOR_ID} --private-key > test.log
1717

1818
# retrieve the field privateKey but not privateKeyRaw
1919
export OPERATOR_KEY=$(grep "privateKey" test.log | grep -v "privateKeyRaw" | awk '{print $2}' | sed 's/"//g'| sed 's/,//g')
2020
export CONTRACT_TEST_KEY_ONE=0x$(grep "privateKeyRaw" test.log | awk '{print $2}' | sed 's/"//g'| sed 's/,//g')
2121
echo "CONTRACT_TEST_KEY_ONE=${CONTRACT_TEST_KEY_ONE}"
2222
rm test.log
2323

24-
npm run solo-test -- account create --deployment solo-deployment --hbar-amount 100 --generate-ecdsa-key --set-alias > test.log
24+
npm run solo-test -- account create --deployment solo-e2e --hbar-amount 100 --generate-ecdsa-key --set-alias > test.log
2525
export SECOND_KEY=$(grep "accountId" test.log | awk '{print $2}' | sed 's/"//g'| sed 's/,//g')
26-
npm run solo-test -- account get --deployment solo-deployment --account-id ${SECOND_KEY} --private-key > test.log
26+
npm run solo-test -- account get --deployment solo-e2e --account-id ${SECOND_KEY} --private-key > test.log
2727
export CONTRACT_TEST_KEY_TWO=0x$(grep "privateKeyRaw" test.log | awk '{print $2}' | sed 's/"//g'| sed 's/,//g')
2828
echo "CONTRACT_TEST_KEY_TWO=${CONTRACT_TEST_KEY_TWO}"
2929
rm test.log

.github/workflows/script/solo_smoke_test.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function start_background_transactions ()
5959
# generate accounts as background traffic for two minutes
6060
# so record stream files can be kept pushing to mirror node
6161
cd solo
62-
npm run solo-test -- account create --deployment solo-deployment --create-amount 15 > /dev/null 2>&1 &
62+
npm run solo-test -- account create --deployment solo-e2e --create-amount 15 > /dev/null 2>&1 &
6363
cd -
6464
}
6565

@@ -120,12 +120,9 @@ function check_importer_log()
120120
# then call solo account init before deploy mirror and relay node
121121
if [ "$1" == "account-init" ]; then
122122
echo "Call solo account init"
123-
npm run solo-test -- account init --deployment solo-deployment
123+
npm run solo-test -- account init --deployment solo-e2e
124124
fi
125125

126-
task solo:mirror-node
127-
task solo:relay
128-
129126
echo "Change to parent directory"
130127

131128
cd ../

Taskfile.helper.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,3 +478,32 @@ tasks:
478478
cmds:
479479
- echo "Cleaning up temporary files..."
480480
- rm -f /tmp/solo-${USER}-* || true
481+
482+
solo:external-database:
483+
silent: false
484+
desc: setup external database PostgreSQL with helm
485+
cmds:
486+
- |
487+
{{.solo_bin_dir}}/helm install {{.postgres_name}} https://charts.bitnami.com/bitnami/postgresql-12.1.2.tgz \
488+
--set image.tag=16.4.0 \
489+
--namespace {{.postgres_database_namespace}} --create-namespace \
490+
--set global.postgresql.auth.postgresPassword={{.postgres_password}} \
491+
--set primary.persistence.enabled=false --set secondary.enabled=false
492+
- name: "Wait for PostgreSQL pod to be ready"
493+
cmd: |
494+
kubectl wait --for=condition=ready pod/{{.postgres_container_name}} \
495+
-n {{.postgres_database_namespace}} --timeout=160s
496+
- name: "Copy init.sql inside the database pod"
497+
cmd: |
498+
kubectl cp ../external-database-test/scripts/init.sh \
499+
{{.postgres_container_name}}:/tmp/init.sh \
500+
-n {{.postgres_database_namespace}}
501+
- name: "Make init.sh executable"
502+
cmd: |
503+
kubectl exec -it {{.postgres_container_name}} \
504+
-n {{.postgres_database_namespace}} -- chmod +x /tmp/init.sh
505+
- name: "Execute init.sh inside the database pod"
506+
cmd: |
507+
kubectl exec -it {{.postgres_container_name}} \
508+
-n {{.postgres_database_namespace}} \
509+
-- /bin/bash /tmp/init.sh "{{.postgres_username}}" "{{.postgres_password}}"

examples/custom-mirror-node-database/scripts/init.sh

Lines changed: 0 additions & 144 deletions
This file was deleted.

examples/custom-mirror-node-database/values.yaml

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
version: 3
2+
includes:
3+
main:
4+
taskfile: ../../Taskfile.helper.yml
5+
flatten: true
6+
vars:
7+
use_port_forwards: "true"
8+
postgres_username: "postgres"
9+
postgres_password: "XXXXXXXXX"
10+
postgres_name: "my-postgresql"
11+
postgres_container_name: "{{.postgres_name}}-0"
12+
postgres_host_fqdn: "{{.postgres_name}}.database.svc.cluster.local"
13+
postgres_container_fdqn: "{{.postgres_container_name}}.database.svc.cluster.local"
14+
postgres_mirror_node_database_name: "mirror_node"
15+
postgres_database_namespace: "database"
16+
env:
17+
SOLO_NETWORK_SIZE: "1"
18+
SOLO_DEPLOYMENT: "solo-e2e"
19+
SOLO_NAMESPACE: "solo-e2e"
20+
SOLO_CLUSTER_NAME: "solo-e2e"
21+
MIRROR_NODE_DEPLOY_EXTRA_FLAGS: "--use-external-database --external-database-host {{.postgres_host_fqdn}} --external-database-owner-username {{.postgres_username}} --external-database-owner-password {{.postgres_password}}"
22+
tasks:
23+
default:
24+
silent: true
25+
desc: install Solo, create a kind cluster, deploy the network, set it up, and start it
26+
deps:
27+
- task: "init"
28+
cmds:
29+
- echo "This command is meant to deploy a Solo network to a Kind cluster on your local machine, "
30+
- echo "ctrl-c if this is not what you want to do."
31+
- sleep 5
32+
33+
install:
34+
desc: create the cluster, solo init, solo cluster create, solo node keys, solo network deploy
35+
deps:
36+
- task: "init"
37+
cmds:
38+
- task: "cluster:create"
39+
- task: "solo:init"
40+
- task: "solo:cluster:setup"
41+
- task: "solo:deployment:create"
42+
- task: "solo:keys"
43+
- task: "solo:network:deploy"
44+
- task: "solo:node:setup"
45+
- task: "solo:node:start"
46+
- task: "solo:external-database"
47+
- task: "solo:mirror-node"
48+
- name: "Copy database-seeding-query.sql inside the database pod"
49+
cmd: |
50+
kubectl cp {{.HOME}}/.solo/cache/database-seeding-query.sql {{.postgres_container_name}}:/tmp/database-seeding-query.sql \
51+
-n {{.postgres_database_namespace}}
52+
- name: "Execute the database-seeding–query.sql against the database"
53+
cmd: |
54+
kubectl exec -it {{.postgres_container_name}} -n {{.postgres_database_namespace}} -- env PGPASSWORD={{.postgres_password}} psql -U {{.postgres_username}} \
55+
-f /tmp/database-seeding-query.sql \
56+
-d {{.postgres_mirror_node_database_name}}
57+
- task: "solo:relay"
58+
- name: "Run smoke test"
59+
cmd: (cd ../../ && ./.github/workflows/script/solo_smoke_test.sh)
60+
destroy:
61+
desc: destroy relay, mirror-node, and network
62+
deps:
63+
- task: "init"
64+
cmds:
65+
- task: "cluster:destroy"

0 commit comments

Comments
 (0)