-
Notifications
You must be signed in to change notification settings - Fork 242
Add jobs for database migration and auto-registration #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
nguyer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't speak for the actual kubernetes things going on here, but everything going on inside it in terms of migrations and registration looks good to me.
| - sh | ||
| - -ce | ||
| - | | ||
| # Install deps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could make this a proper script in a scripts folder and then template it into this job like so (or something along these lines):
{{ (.Files.Glob "scripts/ff-db-migrations.sh") | indent 2 }}
that way when folks are editing this script they can have their editor help them w/ the shell syntax rather than dealing w/ writing shell w/in yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a few extra changes to get this right @hfuss - but it's there now.
Asked for a re-review if you have a min to double check.
I also found through testing that we should handle the situation where the org is registered, but the node isn't.
The common case is as follows:
- You run the job, while the events are syncing with the chain
- The job times and out and re-runs
- Eventually all is caught up - the original Org registration works
- The script ties to re-register the org, and fails - which it doesn't need to do
You should see this handled in the script now.
onelapahead
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, was going to say we could use the go-migrate image but I see we're taking advantage of the fact that the sql migrations are bundled into the core FF container 👍🏻
Perhaps we could make a firefly-utility image on top of the core image that has postgres-client, jq, and go-migrate preinstalled.
Think this is a great suggestion, although I might need to leave the next step on that one with you or @nguyer |
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Codecov Report
@@ Coverage Diff @@
## main #294 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 224 224
Lines 12387 12387
=========================================
Hits 12387 12387 Continue to review full report at Codecov.
|
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only asking for removing the unnecessary env var and renaming the container in the registration job manifest, everything else is speculation or a suggestion.
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do until rather than while ! to avoid the negation logic. It's six or half a dozen but I always prefer to avoid negations for readability.
Unless there's no until in sh and its bashism 🤷🏻♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
confirmed until is in BusyBox
| org: | ||
| name: {{ .Values.config.organizationName }} | ||
| identity: {{ .Values.config.organizationIdentity }} | ||
| key: {{ .Values.config.organizationIdentity }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename the value to match? i.e. organizationKey ?
In eth this is an address right? But for fabric its something else... a channel? And I guess the rename was to avoid confusion w/ the new identity plugin?
| env: | ||
| - name: FF_URL | ||
| value: "http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}" | ||
| - name: PSQL_URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't believe this one is needed for this job / script
| template: | ||
| spec: | ||
| containers: | ||
| - name: migration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - name: migration | |
| - name: registration |
| echo "Registering organization" | ||
| HTTP_CODE=`curl --silent --output /dev/stderr --write-out "%{http_code}" \ | ||
| -X POST -d '{}' -H 'Content-Type: application/json' \ | ||
| "${FF_URL}/api/v1/network/organizations/self?confirm"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this API synchronous now?
I remember when we wrote the original internal registration job, mimicking what was in ff-cli, we'd poll after org registration to ensure that the org had be published before going onto the node registration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was answered by #294 (comment) but could use confirmation from @peterbroadhurst
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this API synchronous now?
Yep, with the confirm option
| @@ -0,0 +1,40 @@ | |||
| # Install deps | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clearly doesn't affect the actual job from running but to make the script executable locally would ask the shebang get added.
|
|
||
| apk add curl jq | ||
|
|
||
| while ! STATUS=$(curl ${FF_URL}/api/v1/status); do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here for until if you care
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Sounds like a good idea. Scope for a different PR though? |
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
|
Great review comments, thanks @hfuss |
onelapahead
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for addressing all the particulars and answering my questions! ![]()
Adds a couple of simple jobs, with configuration options to enable them:
config.postgresMigrationJob: trueconfig.registrationJob: true