From 6a484977374227bb881553c4af6d71936b8aaccd Mon Sep 17 00:00:00 2001 From: Peter Broadhurst Date: Tue, 26 Oct 2021 14:21:36 -0400 Subject: [PATCH 01/11] Add jobs for database migration and auto-registration Signed-off-by: Peter Broadhurst --- .../firefly/templates/core/migration-job.yaml | 65 +++++++++++++++++++ .../templates/core/registration-job.yaml | 59 +++++++++++++++++ deploy/charts/firefly/values.yaml | 6 ++ 3 files changed, 130 insertions(+) create mode 100644 deploy/charts/firefly/templates/core/migration-job.yaml create mode 100644 deploy/charts/firefly/templates/core/registration-job.yaml diff --git a/deploy/charts/firefly/templates/core/migration-job.yaml b/deploy/charts/firefly/templates/core/migration-job.yaml new file mode 100644 index 0000000000..a3b7babc58 --- /dev/null +++ b/deploy/charts/firefly/templates/core/migration-job.yaml @@ -0,0 +1,65 @@ +{{- if .Values.config.postgresMigrationJob -}} +apiVersion: batch/v1 +kind: Job +metadata: + name: "{{ template "firefly.fullname" . }}-{{ .Values.core.image.tag }}-migrations" +spec: + backoffLimit: 5 + activeDeadlineSeconds: 12000 + template: + spec: + containers: + - name: migration + image: "{{ .Values.core.image.repository }}:{{ .Values.core.image.tag | default .Chart.AppVersion }}" + command: + - sh + - -ce + - | + # Install deps + apk add postgresql-client curl jq + + # Extract the database name from the end of the PSQL URL, and check it's there + DB_NAME=`echo ${PSQL_URL} | sed 's/^.*\///'` + COLONS=`echo -n $DB_NAME | sed 's/[^:]//g'` + echo "Database name: '${DB_NAME}'" + if [ -z "${DB_NAME}" ] || [ -n "${COLONS}" ] + then + echo "Postgres URL does not appear to contain a database name" + exit 1 + fi + + # Build a URL that doesn't have the database name + PSQL_URL_NO_DB=`echo ${PSQL_URL} | sed "s/\/${DB_NAME}//"` + + # Check we can connect to the PSQL Server + while ! psql -c "SELECT 1;" ${PSQL_URL_NO_DB}; do + echo "Waiting for database..." + sleep 1 + done + + # Create the database if it doesn't exist + if ! psql -c "SELECT datname FROM pg_database WHERE datname = 'firefly';" ${PSQL_URL_NO_DB} | grep firefly + then + psql -c "CREATE DATABASE firefly;" `echo ${PSQL_URL_NO_DB} | sed 's/\/firefly//'` + fi + + # Wait for the database itself to be available + while ! psql -c "SELECT 1;" ${PSQL_URL}; do + echo "Waiting for database..." + sleep 1 + done + + # Download the latest migration tool + MIGRATE_RELEASE=$(curl -sL https://api.github.com/repos/golang-migrate/migrate/releases/latest | jq -r '.name') + curl -sL https://github.com/golang-migrate/migrate/releases/download/${MIGRATE_RELEASE}/migrate.linux-amd64.tar.gz | tar xz + + # Do the migrations + ./migrate -database ${PSQL_URL} -path db/migrations/postgres up + env: + - name: PSQL_URL + valueFrom: + secretKeyRef: + name: {{ include "firefly.fullname" . }}-config + key: psql_url + restartPolicy: Never +{{- end }} diff --git a/deploy/charts/firefly/templates/core/registration-job.yaml b/deploy/charts/firefly/templates/core/registration-job.yaml new file mode 100644 index 0000000000..93bdbce5e5 --- /dev/null +++ b/deploy/charts/firefly/templates/core/registration-job.yaml @@ -0,0 +1,59 @@ +{{- if .Values.config.registrationJob -}} +apiVersion: batch/v1 +kind: Job +metadata: + name: "{{ template "firefly.fullname" . }}-{{ .Values.core.image.tag }}-registration" +spec: + backoffLimit: 5 + activeDeadlineSeconds: 12000 + template: + spec: + containers: + - name: migration + image: "{{ .Values.core.image.repository }}:{{ .Values.core.image.tag | default .Chart.AppVersion }}" + command: + - sh + - -ce + - | + #!/bin/sh + + apk add curl jq + + while ! STATUS=$(curl http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}/api/v1/status); do + echo "Waiting for FireFly..." + sleep 5 + done + + if [ `echo $STATUS | jq -r .registered` != "true" ]; then + + echo "Registering organization" + HTTP_CODE=`curl --silent --output /dev/stderr --write-out "%{http_code}" \ + -X POST -d '{}' -H 'Content-Type: application/json' \ + "http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}/api/v1/network/organizations/self?confirm"` + if [ "$HTTP_CODE" -ne 200 ]; then + echo "Failed to register with code ${HTTP_CODE}" + exit 1 + fi + + echo "Registering node" + HTTP_CODE=`curl --silent --output /dev/stderr --write-out "%{http_code}" \ + -X POST -d '{}' -H 'Content-Type: application/json' \ + "http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}/api/v1/network/nodes/self?confirm"` + if [ "$HTTP_CODE" -ne 200 ]; then + echo "Failed to register with code ${HTTP_CODE}" + exit 1 + fi + + else + + echo "Already registered. Nothing to do" + + fi + env: + - name: PSQL_URL + valueFrom: + secretKeyRef: + name: {{ include "firefly.fullname" . }}-config + key: psql_url + restartPolicy: Never +{{- end }} diff --git a/deploy/charts/firefly/values.yaml b/deploy/charts/firefly/values.yaml index 1ba08214ef..6f61013076 100644 --- a/deploy/charts/firefly/values.yaml +++ b/deploy/charts/firefly/values.yaml @@ -25,6 +25,9 @@ config: # Whether or not to apply schema migrations automatically on startup, not recommended for production postgresAutomigrate: false + # Whether to create a migration job to perform migrations each time a new tag is pushed for the FireFly image (supports DB creation) + postgresMigrationJob: false + # The URL of the HTTPS DataExchange for the node to use for the dataexchange plugin i.e. private messaging, only needed if `dataexchange.enabled` is set to false dataexchangeUrl: "" @@ -64,6 +67,9 @@ config: # The long prefix FireFly will prepend to certain headers it sends to Ethconnect i.e. FireFly or Kaleido ethconnectPrefixLong: "" + # Whether to use a Job to perform auto-registration of the FireFly runtime + registrationJob: false + # The following values can be used to override the templating of specific plugin sections, in the case where # the user wants greater control to template the sections using global values, additional helpers, etc. OR if they # want to use other plugin types i.e. `fabric` which currently do not exist at the time of writing. From fd73f3be499148a0b7688f206c0bfa6494a131d5 Mon Sep 17 00:00:00 2001 From: Peter Broadhurst Date: Tue, 26 Oct 2021 14:24:37 -0400 Subject: [PATCH 02/11] Remove DB hardcode Signed-off-by: Peter Broadhurst --- deploy/charts/firefly/templates/core/migration-job.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/charts/firefly/templates/core/migration-job.yaml b/deploy/charts/firefly/templates/core/migration-job.yaml index a3b7babc58..7134f085f4 100644 --- a/deploy/charts/firefly/templates/core/migration-job.yaml +++ b/deploy/charts/firefly/templates/core/migration-job.yaml @@ -38,9 +38,9 @@ spec: done # Create the database if it doesn't exist - if ! psql -c "SELECT datname FROM pg_database WHERE datname = 'firefly';" ${PSQL_URL_NO_DB} | grep firefly + if ! psql -c "SELECT datname FROM pg_database WHERE datname = '${DB_NAME}';" ${PSQL_URL_NO_DB} | grep ${DB_NAME} then - psql -c "CREATE DATABASE firefly;" `echo ${PSQL_URL_NO_DB} | sed 's/\/firefly//'` + psql -c "CREATE DATABASE ${DB_NAME};" ${PSQL_URL_NO_DB} fi # Wait for the database itself to be available From eac309d7541d11b8dc56b94593da5013ade24dc8 Mon Sep 17 00:00:00 2001 From: Peter Broadhurst Date: Tue, 26 Oct 2021 14:32:26 -0400 Subject: [PATCH 03/11] Add note on registration Signed-off-by: Peter Broadhurst --- deploy/charts/firefly/values.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deploy/charts/firefly/values.yaml b/deploy/charts/firefly/values.yaml index 6f61013076..f67e30c82b 100644 --- a/deploy/charts/firefly/values.yaml +++ b/deploy/charts/firefly/values.yaml @@ -67,7 +67,8 @@ config: # The long prefix FireFly will prepend to certain headers it sends to Ethconnect i.e. FireFly or Kaleido ethconnectPrefixLong: "" - # Whether to use a Job to perform auto-registration of the FireFly runtime + # Whether to use a Job to perform auto-registration of the FireFly runtime. + # Note registration will not be successful until the new node has caught up with the head of the chain. registrationJob: false # The following values can be used to override the templating of specific plugin sections, in the case where From 9d807438bd01d7137fb5a3d3c7646c9d34924260 Mon Sep 17 00:00:00 2001 From: Peter Broadhurst Date: Tue, 26 Oct 2021 14:36:40 -0400 Subject: [PATCH 04/11] Job only re-runs on org name change Signed-off-by: Peter Broadhurst --- deploy/charts/firefly/templates/core/registration-job.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/charts/firefly/templates/core/registration-job.yaml b/deploy/charts/firefly/templates/core/registration-job.yaml index 93bdbce5e5..d1f262dfbd 100644 --- a/deploy/charts/firefly/templates/core/registration-job.yaml +++ b/deploy/charts/firefly/templates/core/registration-job.yaml @@ -2,7 +2,7 @@ apiVersion: batch/v1 kind: Job metadata: - name: "{{ template "firefly.fullname" . }}-{{ .Values.core.image.tag }}-registration" + name: "{{ template "firefly.fullname" . }}-{{ .Values.config.organizationName | lower }}-registration" spec: backoffLimit: 5 activeDeadlineSeconds: 12000 From b9bded193b13e1cc18e4d3fd0463cec18e00cbd1 Mon Sep 17 00:00:00 2001 From: Peter Broadhurst Date: Tue, 26 Oct 2021 15:00:10 -0400 Subject: [PATCH 05/11] Use scripts Signed-off-by: Peter Broadhurst --- .../firefly/scripts/ff-db-migrations.sh | 40 ++++++++++++++++++ .../charts/firefly/scripts/ff-registration.sh | 34 +++++++++++++++ .../firefly/templates/core/migration-job.yaml | 41 +------------------ .../templates/core/registration-job.yaml | 35 +--------------- 4 files changed, 76 insertions(+), 74 deletions(-) create mode 100644 deploy/charts/firefly/scripts/ff-db-migrations.sh create mode 100644 deploy/charts/firefly/scripts/ff-registration.sh diff --git a/deploy/charts/firefly/scripts/ff-db-migrations.sh b/deploy/charts/firefly/scripts/ff-db-migrations.sh new file mode 100644 index 0000000000..cfc0194538 --- /dev/null +++ b/deploy/charts/firefly/scripts/ff-db-migrations.sh @@ -0,0 +1,40 @@ +# Install deps +apk add postgresql-client curl jq + +# Extract the database name from the end of the PSQL URL, and check it's there +DB_NAME=`echo ${PSQL_URL} | sed 's/^.*\///'` +COLONS=`echo -n $DB_NAME | sed 's/[^:]//g'` +echo "Database name: '${DB_NAME}'" +if [ -z "${DB_NAME}" ] || [ -n "${COLONS}" ] +then + echo "Postgres URL does not appear to contain a database name" + exit 1 +fi + +# Build a URL that doesn't have the database name +PSQL_URL_NO_DB=`echo ${PSQL_URL} | sed "s/\/${DB_NAME}//"` + +# Check we can connect to the PSQL Server +while ! psql -c "SELECT 1;" ${PSQL_URL_NO_DB}; do + echo "Waiting for database..." + sleep 1 +done + +# Create the database if it doesn't exist +if ! psql -c "SELECT datname FROM pg_database WHERE datname = '${DB_NAME}';" ${PSQL_URL_NO_DB} | grep ${DB_NAME} +then + psql -c "CREATE DATABASE ${DB_NAME};" ${PSQL_URL_NO_DB} +fi + +# Wait for the database itself to be available +while ! psql -c "SELECT 1;" ${PSQL_URL}; do + echo "Waiting for database..." + sleep 1 +done + +# Download the latest migration tool +MIGRATE_RELEASE=$(curl -sL https://api.github.com/repos/golang-migrate/migrate/releases/latest | jq -r '.name') +curl -sL https://github.com/golang-migrate/migrate/releases/download/${MIGRATE_RELEASE}/migrate.linux-amd64.tar.gz | tar xz + +# Do the migrations +./migrate -database ${PSQL_URL} -path db/migrations/postgres up diff --git a/deploy/charts/firefly/scripts/ff-registration.sh b/deploy/charts/firefly/scripts/ff-registration.sh new file mode 100644 index 0000000000..34d27d0039 --- /dev/null +++ b/deploy/charts/firefly/scripts/ff-registration.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +apk add curl jq + +while ! STATUS=$(curl http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}/api/v1/status); do + echo "Waiting for FireFly..." + sleep 5 +done + +if [ `echo $STATUS | jq -r .registered` != "true" ]; then + + echo "Registering organization" + HTTP_CODE=`curl --silent --output /dev/stderr --write-out "%{http_code}" \ + -X POST -d '{}' -H 'Content-Type: application/json' \ + "http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}/api/v1/network/organizations/self?confirm"` + if [ "$HTTP_CODE" -ne 200 ]; then + echo "Failed to register with code ${HTTP_CODE}" + exit 1 + fi + + echo "Registering node" + HTTP_CODE=`curl --silent --output /dev/stderr --write-out "%{http_code}" \ + -X POST -d '{}' -H 'Content-Type: application/json' \ + "http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}/api/v1/network/nodes/self?confirm"` + if [ "$HTTP_CODE" -ne 200 ]; then + echo "Failed to register with code ${HTTP_CODE}" + exit 1 + fi + +else + + echo "Already registered. Nothing to do" + +fi diff --git a/deploy/charts/firefly/templates/core/migration-job.yaml b/deploy/charts/firefly/templates/core/migration-job.yaml index 7134f085f4..2b64f0c7a1 100644 --- a/deploy/charts/firefly/templates/core/migration-job.yaml +++ b/deploy/charts/firefly/templates/core/migration-job.yaml @@ -15,46 +15,7 @@ spec: - sh - -ce - | - # Install deps - apk add postgresql-client curl jq - - # Extract the database name from the end of the PSQL URL, and check it's there - DB_NAME=`echo ${PSQL_URL} | sed 's/^.*\///'` - COLONS=`echo -n $DB_NAME | sed 's/[^:]//g'` - echo "Database name: '${DB_NAME}'" - if [ -z "${DB_NAME}" ] || [ -n "${COLONS}" ] - then - echo "Postgres URL does not appear to contain a database name" - exit 1 - fi - - # Build a URL that doesn't have the database name - PSQL_URL_NO_DB=`echo ${PSQL_URL} | sed "s/\/${DB_NAME}//"` - - # Check we can connect to the PSQL Server - while ! psql -c "SELECT 1;" ${PSQL_URL_NO_DB}; do - echo "Waiting for database..." - sleep 1 - done - - # Create the database if it doesn't exist - if ! psql -c "SELECT datname FROM pg_database WHERE datname = '${DB_NAME}';" ${PSQL_URL_NO_DB} | grep ${DB_NAME} - then - psql -c "CREATE DATABASE ${DB_NAME};" ${PSQL_URL_NO_DB} - fi - - # Wait for the database itself to be available - while ! psql -c "SELECT 1;" ${PSQL_URL}; do - echo "Waiting for database..." - sleep 1 - done - - # Download the latest migration tool - MIGRATE_RELEASE=$(curl -sL https://api.github.com/repos/golang-migrate/migrate/releases/latest | jq -r '.name') - curl -sL https://github.com/golang-migrate/migrate/releases/download/${MIGRATE_RELEASE}/migrate.linux-amd64.tar.gz | tar xz - - # Do the migrations - ./migrate -database ${PSQL_URL} -path db/migrations/postgres up +{{ (.Files.Glob "scripts/ff-db-migrations.sh") | indent 10 }} env: - name: PSQL_URL valueFrom: diff --git a/deploy/charts/firefly/templates/core/registration-job.yaml b/deploy/charts/firefly/templates/core/registration-job.yaml index d1f262dfbd..8e2f2ade01 100644 --- a/deploy/charts/firefly/templates/core/registration-job.yaml +++ b/deploy/charts/firefly/templates/core/registration-job.yaml @@ -15,40 +15,7 @@ spec: - sh - -ce - | - #!/bin/sh - - apk add curl jq - - while ! STATUS=$(curl http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}/api/v1/status); do - echo "Waiting for FireFly..." - sleep 5 - done - - if [ `echo $STATUS | jq -r .registered` != "true" ]; then - - echo "Registering organization" - HTTP_CODE=`curl --silent --output /dev/stderr --write-out "%{http_code}" \ - -X POST -d '{}' -H 'Content-Type: application/json' \ - "http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}/api/v1/network/organizations/self?confirm"` - if [ "$HTTP_CODE" -ne 200 ]; then - echo "Failed to register with code ${HTTP_CODE}" - exit 1 - fi - - echo "Registering node" - HTTP_CODE=`curl --silent --output /dev/stderr --write-out "%{http_code}" \ - -X POST -d '{}' -H 'Content-Type: application/json' \ - "http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}/api/v1/network/nodes/self?confirm"` - if [ "$HTTP_CODE" -ne 200 ]; then - echo "Failed to register with code ${HTTP_CODE}" - exit 1 - fi - - else - - echo "Already registered. Nothing to do" - - fi +{{ (.Files.Glob "scripts/ff-registration.sh") | indent 10 }} env: - name: PSQL_URL valueFrom: From c2b0816adc9db64562853b3a329695958424635e Mon Sep 17 00:00:00 2001 From: Peter Broadhurst Date: Tue, 26 Oct 2021 17:39:20 -0400 Subject: [PATCH 06/11] Use Get for simplicity Signed-off-by: Peter Broadhurst --- deploy/charts/firefly/templates/core/migration-job.yaml | 2 +- deploy/charts/firefly/templates/core/registration-job.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/charts/firefly/templates/core/migration-job.yaml b/deploy/charts/firefly/templates/core/migration-job.yaml index 2b64f0c7a1..860761b7ba 100644 --- a/deploy/charts/firefly/templates/core/migration-job.yaml +++ b/deploy/charts/firefly/templates/core/migration-job.yaml @@ -15,7 +15,7 @@ spec: - sh - -ce - | -{{ (.Files.Glob "scripts/ff-db-migrations.sh") | indent 10 }} +{{ .Files.Get "scripts/ff-db-migrations.sh" | indent 10 }} env: - name: PSQL_URL valueFrom: diff --git a/deploy/charts/firefly/templates/core/registration-job.yaml b/deploy/charts/firefly/templates/core/registration-job.yaml index 8e2f2ade01..395db12daa 100644 --- a/deploy/charts/firefly/templates/core/registration-job.yaml +++ b/deploy/charts/firefly/templates/core/registration-job.yaml @@ -15,7 +15,7 @@ spec: - sh - -ce - | -{{ (.Files.Glob "scripts/ff-registration.sh") | indent 10 }} +{{ .Files.Get "scripts/ff-registration.sh" | indent 10 }} env: - name: PSQL_URL valueFrom: From 84922c9ab0b5b481c12764f48c531282028a79e2 Mon Sep 17 00:00:00 2001 From: Peter Broadhurst Date: Tue, 26 Oct 2021 17:43:11 -0400 Subject: [PATCH 07/11] Move to env vars into scripts not templating Signed-off-by: Peter Broadhurst --- deploy/charts/firefly/scripts/ff-registration.sh | 6 +++--- deploy/charts/firefly/templates/core/registration-job.yaml | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/deploy/charts/firefly/scripts/ff-registration.sh b/deploy/charts/firefly/scripts/ff-registration.sh index 34d27d0039..6cc1910834 100644 --- a/deploy/charts/firefly/scripts/ff-registration.sh +++ b/deploy/charts/firefly/scripts/ff-registration.sh @@ -2,7 +2,7 @@ apk add curl jq -while ! STATUS=$(curl http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}/api/v1/status); do +while ! STATUS=$(curl ${FF_URL}/api/v1/status); do echo "Waiting for FireFly..." sleep 5 done @@ -12,7 +12,7 @@ if [ `echo $STATUS | jq -r .registered` != "true" ]; then echo "Registering organization" HTTP_CODE=`curl --silent --output /dev/stderr --write-out "%{http_code}" \ -X POST -d '{}' -H 'Content-Type: application/json' \ - "http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}/api/v1/network/organizations/self?confirm"` + "${FF_URL}/api/v1/network/organizations/self?confirm"` if [ "$HTTP_CODE" -ne 200 ]; then echo "Failed to register with code ${HTTP_CODE}" exit 1 @@ -21,7 +21,7 @@ if [ `echo $STATUS | jq -r .registered` != "true" ]; then echo "Registering node" HTTP_CODE=`curl --silent --output /dev/stderr --write-out "%{http_code}" \ -X POST -d '{}' -H 'Content-Type: application/json' \ - "http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}/api/v1/network/nodes/self?confirm"` + "${FF_URL}/api/v1/network/nodes/self?confirm"` if [ "$HTTP_CODE" -ne 200 ]; then echo "Failed to register with code ${HTTP_CODE}" exit 1 diff --git a/deploy/charts/firefly/templates/core/registration-job.yaml b/deploy/charts/firefly/templates/core/registration-job.yaml index 395db12daa..32ae7fcfd2 100644 --- a/deploy/charts/firefly/templates/core/registration-job.yaml +++ b/deploy/charts/firefly/templates/core/registration-job.yaml @@ -17,6 +17,8 @@ spec: - | {{ .Files.Get "scripts/ff-registration.sh" | indent 10 }} env: + - name: FF_URL + value: "http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}" - name: PSQL_URL valueFrom: secretKeyRef: From 0977afdbb0bcc75a02dc4c06be66b5751d530239 Mon Sep 17 00:00:00 2001 From: Peter Broadhurst Date: Tue, 26 Oct 2021 17:48:29 -0400 Subject: [PATCH 08/11] Move to non-deprecated field Signed-off-by: Peter Broadhurst --- deploy/charts/firefly/templates/_helpers.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/charts/firefly/templates/_helpers.tpl b/deploy/charts/firefly/templates/_helpers.tpl index eef8e1fc0f..dbafcf5d49 100644 --- a/deploy/charts/firefly/templates/_helpers.tpl +++ b/deploy/charts/firefly/templates/_helpers.tpl @@ -101,7 +101,7 @@ ui: path: ./frontend org: name: {{ .Values.config.organizationName }} - identity: {{ .Values.config.organizationIdentity }} + key: {{ .Values.config.organizationIdentity }} {{- if .Values.config.blockchainOverride }} blockchain: {{- toYaml (tpl .Values.config.blockchainOverride .) | nindent 2 }} From 1368d75247829756769b144bdea07e82e18be140 Mon Sep 17 00:00:00 2001 From: Peter Broadhurst Date: Tue, 26 Oct 2021 18:11:42 -0400 Subject: [PATCH 09/11] Check org registration separate to node registration Signed-off-by: Peter Broadhurst --- deploy/charts/firefly/scripts/ff-registration.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/deploy/charts/firefly/scripts/ff-registration.sh b/deploy/charts/firefly/scripts/ff-registration.sh index 6cc1910834..f198cc31d6 100644 --- a/deploy/charts/firefly/scripts/ff-registration.sh +++ b/deploy/charts/firefly/scripts/ff-registration.sh @@ -7,7 +7,7 @@ while ! STATUS=$(curl ${FF_URL}/api/v1/status); do sleep 5 done -if [ `echo $STATUS | jq -r .registered` != "true" ]; then +if [ `echo $STATUS | jq -r .org.registered` != "true" ]; then echo "Registering organization" HTTP_CODE=`curl --silent --output /dev/stderr --write-out "%{http_code}" \ @@ -18,6 +18,10 @@ if [ `echo $STATUS | jq -r .registered` != "true" ]; then exit 1 fi +fi + +if [ `echo $STATUS | jq -r .registered` != "true" ]; then + echo "Registering node" HTTP_CODE=`curl --silent --output /dev/stderr --write-out "%{http_code}" \ -X POST -d '{}' -H 'Content-Type: application/json' \ From 40ba6a9b313eeb67ea9a7e6787a307059a227be0 Mon Sep 17 00:00:00 2001 From: Peter Broadhurst Date: Wed, 27 Oct 2021 07:48:42 -0400 Subject: [PATCH 10/11] Fix check for status Signed-off-by: Peter Broadhurst --- deploy/charts/firefly/scripts/ff-registration.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/charts/firefly/scripts/ff-registration.sh b/deploy/charts/firefly/scripts/ff-registration.sh index f198cc31d6..8769e66669 100644 --- a/deploy/charts/firefly/scripts/ff-registration.sh +++ b/deploy/charts/firefly/scripts/ff-registration.sh @@ -20,7 +20,7 @@ if [ `echo $STATUS | jq -r .org.registered` != "true" ]; then fi -if [ `echo $STATUS | jq -r .registered` != "true" ]; then +if [ `echo $STATUS | jq -r .node.registered` != "true" ]; then echo "Registering node" HTTP_CODE=`curl --silent --output /dev/stderr --write-out "%{http_code}" \ From ebc992260cb3dbe90f13572e9c04fbc490f5c8d6 Mon Sep 17 00:00:00 2001 From: Peter Broadhurst Date: Thu, 28 Oct 2021 21:10:54 -0400 Subject: [PATCH 11/11] Close out review comments Signed-off-by: Peter Broadhurst --- deploy/charts/firefly/README.md | 2 +- deploy/charts/firefly/ci/it-values.yaml | 2 +- deploy/charts/firefly/scripts/ff-db-migrations.sh | 6 ++++-- deploy/charts/firefly/scripts/ff-registration.sh | 2 +- deploy/charts/firefly/templates/_helpers.tpl | 2 +- deploy/charts/firefly/templates/core/registration-job.yaml | 7 +------ deploy/charts/firefly/values.yaml | 4 ++-- 7 files changed, 11 insertions(+), 14 deletions(-) diff --git a/deploy/charts/firefly/README.md b/deploy/charts/firefly/README.md index 5c8d16663b..a8bc6d3574 100644 --- a/deploy/charts/firefly/README.md +++ b/deploy/charts/firefly/README.md @@ -18,7 +18,7 @@ for simple, private messaging using HTTPS backed with mTLS. $ helm install acme-firefly ./deploy/charts/firefly \ --set dataexchange.tlsSecret.name=acme-dx-tls \ --set config.organizationName=acme \ - --set config.organizationIdentity="0xeb7284ce905e0665b7d42cabe31c76c45da1d331" \ + --set config.organizationKey="0xeb7284ce905e0665b7d42cabe31c76c45da1d331" \ --set config.fireflyContractAddress="0xeb7284ce905e0665b7d42cabe31c76c45da1d254" ``` diff --git a/deploy/charts/firefly/ci/it-values.yaml b/deploy/charts/firefly/ci/it-values.yaml index 79d627388b..a661806d14 100644 --- a/deploy/charts/firefly/ci/it-values.yaml +++ b/deploy/charts/firefly/ci/it-values.yaml @@ -4,7 +4,7 @@ config: preInit: true organizationName: "firefly-os" - organizationIdentity: "0xeb7284ce905e0665b7d42cabe31c76c45da1d331" + organizationKey: "0xeb7284ce905e0665b7d42cabe31c76c45da1d331" fireflyContractAddress: "0xeb7284ce905e0665b7d42cabe31c76c45da1d254" ethconnectUrl: "http://ethconnect.firefly-os" diff --git a/deploy/charts/firefly/scripts/ff-db-migrations.sh b/deploy/charts/firefly/scripts/ff-db-migrations.sh index cfc0194538..2699dc4243 100644 --- a/deploy/charts/firefly/scripts/ff-db-migrations.sh +++ b/deploy/charts/firefly/scripts/ff-db-migrations.sh @@ -1,3 +1,5 @@ +#!/bin/sh + # Install deps apk add postgresql-client curl jq @@ -15,7 +17,7 @@ fi PSQL_URL_NO_DB=`echo ${PSQL_URL} | sed "s/\/${DB_NAME}//"` # Check we can connect to the PSQL Server -while ! psql -c "SELECT 1;" ${PSQL_URL_NO_DB}; do +until psql -c "SELECT 1;" ${PSQL_URL_NO_DB}; do echo "Waiting for database..." sleep 1 done @@ -27,7 +29,7 @@ then fi # Wait for the database itself to be available -while ! psql -c "SELECT 1;" ${PSQL_URL}; do +until psql -c "SELECT 1;" ${PSQL_URL}; do echo "Waiting for database..." sleep 1 done diff --git a/deploy/charts/firefly/scripts/ff-registration.sh b/deploy/charts/firefly/scripts/ff-registration.sh index 8769e66669..46bfd265ca 100644 --- a/deploy/charts/firefly/scripts/ff-registration.sh +++ b/deploy/charts/firefly/scripts/ff-registration.sh @@ -2,7 +2,7 @@ apk add curl jq -while ! STATUS=$(curl ${FF_URL}/api/v1/status); do +until STATUS=$(curl ${FF_URL}/api/v1/status); do echo "Waiting for FireFly..." sleep 5 done diff --git a/deploy/charts/firefly/templates/_helpers.tpl b/deploy/charts/firefly/templates/_helpers.tpl index dbafcf5d49..f32f690d17 100644 --- a/deploy/charts/firefly/templates/_helpers.tpl +++ b/deploy/charts/firefly/templates/_helpers.tpl @@ -101,7 +101,7 @@ ui: path: ./frontend org: name: {{ .Values.config.organizationName }} - key: {{ .Values.config.organizationIdentity }} + key: {{ .Values.config.organizationKey }} {{- if .Values.config.blockchainOverride }} blockchain: {{- toYaml (tpl .Values.config.blockchainOverride .) | nindent 2 }} diff --git a/deploy/charts/firefly/templates/core/registration-job.yaml b/deploy/charts/firefly/templates/core/registration-job.yaml index 32ae7fcfd2..51968bb741 100644 --- a/deploy/charts/firefly/templates/core/registration-job.yaml +++ b/deploy/charts/firefly/templates/core/registration-job.yaml @@ -9,7 +9,7 @@ spec: template: spec: containers: - - name: migration + - name: registration image: "{{ .Values.core.image.repository }}:{{ .Values.core.image.tag | default .Chart.AppVersion }}" command: - sh @@ -19,10 +19,5 @@ spec: env: - name: FF_URL value: "http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}" - - name: PSQL_URL - valueFrom: - secretKeyRef: - name: {{ include "firefly.fullname" . }}-config - key: psql_url restartPolicy: Never {{- end }} diff --git a/deploy/charts/firefly/values.yaml b/deploy/charts/firefly/values.yaml index f67e30c82b..73cb9f88d1 100644 --- a/deploy/charts/firefly/values.yaml +++ b/deploy/charts/firefly/values.yaml @@ -13,8 +13,8 @@ config: # The name of the organization the FireFly node belongs to organizationName: "" - # The blockchain identity of the organization e.g. the Ethereum account address - organizationIdentity: "" + # The blockchain signing key of the organization e.g. the Ethereum account address + organizationKey: "" # The Ethereum address of the pre-deployed FireFly smart contract fireflyContractAddress: "/instances/contractAddress"