How should I be using the kickstart.success webhook?
-
This question was originally posted on Github here: https://github.com/FusionAuth/fusionauth-issues/issues/1178#issuecomment-1043217851
The exact problem is described here by someone else and is how I found out about the kickstart webhook to address this as of v1.30: https://fusionauth.io/community/forum/topic/751/kickstart-in-ci-environment-unpredictable/2
Documentation links if you're not aware of it:
- https://fusionauth.io/docs/v1/tech/installation-guide/kickstart#determining-kickstart-completion
- https://fusionauth.io/docs/v1/tech/events-webhooks/events/kickstart-success
The question is:
How exactly does one create this webhook at the time of creating the fusionauth instance and what exactly do I point it to in a CI/CD pipeline?My exact scenario:
I have a repo on github with a single docker-compose file that starts up fusionauth with a postgresql db as well as my own django app and its own database. I have a github action configured to build my local docker image and pull the other images from docker hub, then deploy and do some basic testing so I know my application works when I commit and push changes.Every now and then I seem to run into a race condition that fusionauth does not complete startup yet the rest of my containers start up and carry on like normal, then when the testing code runs it just all falls over, simply re-running the CI/CD action on github again and annoyingly yields different results, it just needs an extra second or two.
I personally would have preferred if there was an API endpoint I could query is to whether or not the kickstart has completed successfully, but instead we were given a webhook and I'm not quite sure how I should be using it.
From what I can gather I have to create and enable the webhook, but I want to do this automatically in the existing CI/CD pipeline I have in github, so does that mean that I must create the webhook using the kickstart itself and how do I get it to fire the webhook back on itself?
My application has not yet started so I can send the webhook to my django application.
Also in my case there is no long running instance to point the webhook to, as mentioned earlier in the same CI/CD pipeline for fusionauth I have the rest of my application code that builds and start up AFTER fusionauth, and it's all in one place using docker-compose.
Can someone please explain what is the correct and expected use of this webhook as it's not very clear to me how it should work or how I should be using this. Would I have to redesign my app to accept this? I just want to make sure I do the right thing and I'm not overlooking something blindingly obvious to others.
I assume something like this would go in the kickstart.json, but I'm not sure and would like some advice on how to use this correctly.
{ "requests": [ { "method": "POST", "url": "/api/webhook", "body": { "webhook": { "connectTimeout": 1000, "description": "Kickstart Sucess Webhook", "eventsEnabled": { "kickstart.success": true }, "httpAuthenticationPassword": "password", "httpAuthenticationUsername": "username", "url": "what goes here?" } } } ] }
-
-
So it sounds like you're trying to figure out a way to know when FusionAuth has completed startup.
The webhook is one way to do that. As you said, you can set up a kickstart event webhook within a kickstart file.
Another way is to poll for a known value, such as a non-default tenant that you know your setup has added. That may be a simpler solution for you.
Either way, you'll have to write some code to kick off the testing once you receive a signal that FusionAuth is ready.
I personally would have preferred if there was an API endpoint I could query is to whether or not the kickstart has completed successfully, but instead we were given a webhook and I'm not quite sure how I should be using it.
You'll need to write a webhook receiver that will kick off your tests (or whatever the next step of your testing setup is). I'm not quite sure how do that in one github action, but it should be pretty easy to split up a github action into two actions, a setup one (where you set everything up, including FusionAuth) and a test action (which you kick off in response to the FusionAuth webhook firing).
I think you'd want the workflow_call event: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_call