N
Neon2y ago
deep-jade

Vercel deployments are failing due to Neon Branching check

After enabling the Vercel & Neon integration all my deployments through the Vercel CLI are failing due to the Non branching check. The only log I can find is the one in the picture ("Status not available"). However, from the neon side it looks like the preview branches are being created. Please help.
No description
30 Replies
metropolitan-bronze
metropolitan-bronze2y ago
Hello, Sorry to hear you're having trouble with the integration. I suppose this is for preview environments right? Can you please verify if the environment variables for previews in Vercel are correct?
equal-aqua
equal-aqua2y ago
all my deployments through the Vercel CLI
Do you mind sharing more details about your setup? Are you using the Vercel CLI locally to create preview deployments?
deep-jade
deep-jadeOP2y ago
Thanks for the prompt reply. Yes, this is in preview environments. About my setup: the deployment is being done from CircleCI using vercel deploy. The build itself is being done in Vercel, although the check fails before the build completes. As far as the environment variables... I see that DATABASE_URL is missing and the DATABASE_URL_UNPOOLED is duplicated:
deep-jade
deep-jadeOP2y ago
No description
deep-jade
deep-jadeOP2y ago
Update on some troubleshooting from our side: we noticed we had a "DATABASE_URL" environment variable when the integration was added and we assumed this could have been part of the problem. So we removed the integration, removed our "DATABASE_URL" environment variable, and added the integration again. This time we did see more environment variables added by the Neon plugin:
deep-jade
deep-jadeOP2y ago
No description
deep-jade
deep-jadeOP2y ago
However, the check is still failing:
deep-jade
deep-jadeOP2y ago
No description
deep-jade
deep-jadeOP2y ago
And FWIW, Ive notived that there are not environment variables set for the preview environment. I suppose these are set once the branch is created. Is this right?
equal-aqua
equal-aqua2y ago
I think the issue is that you're deploying from CI while also using the Vercel integration The way the integration works might mess up with your other flow because I believe under the hood the Vercel integration cancels a deployment that's triggered by opening a PR, injects the environment variable, and redeploys
deep-jade
deep-jadeOP2y ago
I do not think that is the case, since I am not using the github integration, hence preview deployments do not get created when opening a PR. Plus, my deployment build succeds but the CLI throws an error because of the Neon check. What is it being checked there? The deployment is triggered through the CLI in CircleCI. Not by opening a PR. is the check there to cancel the deployment? If that is its purpose, then yes this is the issue
equal-aqua
equal-aqua2y ago
is the check there to cancel the deployment? If that is its purpose, then yes this is the issue
Pretty sure that's the reason cc @Mike J correct me if I'm wrong please
deep-jade
deep-jadeOP2y ago
Thanks for the support. If that is the case, then we wont be able to use the vercel integration and we will have to build our own using Neon's CLI. However, something is not checking for me. If the check is there to cancel the deployment, why is the integration not setting the environment variables and kicking off a redeploy? So... Ive gotten the branch creation through the CLI inside Circle CI working and I am now passing the DATABASE_URL environment variable to my preview deployment. My only concern is how to do the clean up of these branches once the preview is promoted to prod or abandoned. Any help would be appreciated. We will make sure to write a blog post of the learnings.
equal-aqua
equal-aqua2y ago
GitHub
GitHub - neondatabase/preview-branches-with-vercel: Example project...
Example project that shows how you can create a branch for every preview deployment on Vercel using GitHub actions - neondatabase/preview-branches-with-vercel
equal-aqua
equal-aqua2y ago
My only concern is how to do the clean up of these branches once the preview is promoted to prod or abandoned.
So the idea is you would name the neon branch with something you can infer later (e.g. the git branch name), this way you can delete it later when the git branch is merged
equal-aqua
equal-aqua2y ago
btw the Neon github actions use the Neon CLI. So pretty sure you can reuse the same logic https://github.com/neondatabase/create-branch-action/blob/main/action.yml (for example here we're handling the case if a Neon branch name already exists we return it instead of an error. This way if you re-run CI it wouldn't break) https://github.com/neondatabase/delete-branch-action/blob/main/action.yaml
GitHub
create-branch-action/action.yml at main · neondatabase/create-branc...
GitHub Action to create a new Neon branch. Contribute to neondatabase/create-branch-action development by creating an account on GitHub.
GitHub
delete-branch-action/action.yaml at main · neondatabase/delete-bran...
Contribute to neondatabase/delete-branch-action development by creating an account on GitHub.
equal-aqua
equal-aqua2y ago
We will make sure to write a blog post of the learnings.
That would be fantastic! Also, feel free to ping me if you run into any issues. Would love to help
deep-jade
deep-jadeOP2y ago
@Mahmoud is there a policy of mechanism to automatically delete branches that have not been used for X amount of time? Automating the deletion of branches when a merge is done adds some (although not much) complexity to our pipeline and does not account for edge cases (PR abandoned or rejected).
equal-aqua
equal-aqua2y ago
We currently don't support automatically deleting branches
adds some (although not much) complexity to our pipeline and does not account for edge cases (PR abandoned or rejected).
That's understandable. I'll share your feedback with the team
sunny-green
sunny-green2y ago
Hey. Quick summary of the workflow with the Neon Vercel integration as it's touched on above: - Vercel preview build starts (what triggers it doesn't really matter) - Vercel sends a message to Neon "Hey a preview build started" - Neon creates a new branch - It's not possible to inject the DATABASE_URL into the preview build at this point, so instead: a) Neon sends a "stop the build!" message to Vercel b) Neon creates the DATABASE_URL env in Vercel c) Neon sends a "start a new build" message to Vercel This means for every preview you'll see both a failed cancelled build and (hopefully) a success build in Vercel. Unfortunately, it's the best we can do today. We're chatting to our friends at Vercel with the hope they can send us a "Hey a preview build is about to start soon" then give us xxx seconds to set the DATABASE_URL before the build starts.
deep-jade
deep-jadeOP2y ago
Thanks @Mike J - so that failed check that I am seeing is Neon telling Vercel to stop the build? If so, the "stop the build" commands has the side effect of noticing the CLI that de deployment failed, ergo this will break any CI/CD that uses the Vercel CLI.
sunny-green
sunny-green2y ago
I think it could be. Noting Vercel dashboard has a status "cancelled" that's distinct from "error".
No description
No description
sunny-green
sunny-green2y ago
On the topic of unused or stale branches … it's not awesome but you could run a periodic job that used Neon's API to iterate over your project's branches and check all the following are true: 1. The branch has a naming convention you recognie (e.g. it's name starts preview/pr). 2. The branch has only one compute endpoint. 3. The last_active value on the endpoint is older than xxx days. If all true, delete the branch. https://api-docs.neon.tech/reference/getprojectendpoint
deep-jade
deep-jadeOP2y ago
Thanks @Mike J . We manually integrated Neon into our CI/CD (Circle CI deploying to vercel) using the Neon cli. It was relatively strightfoward. However - FWIW, the behavior you describe is different than what we observed. So we may have ran into another issue with the native integrarion. We never saw a cancelled deployment, all we saw was a check done by the Neon integration that was failing. Here are some screenshot:
deep-jade
deep-jadeOP2y ago
No description
deep-jade
deep-jadeOP2y ago
No description
deep-jade
deep-jadeOP2y ago
No description
deep-jade
deep-jadeOP2y ago
I hope this helps. Regards
sunny-green
sunny-green2y ago
Thanks for the info. We've identified an issue with the Vercel integration and Neon org accounts. That should be resolved within the next few hours; it may be the cause if you are an org user. If the problem continues, please do raise a support ticket so we can dig in deeper.
deep-jade
deep-jadeOP2y ago
We are an org user. I am glad we were able to help, we love your product!

Did you find this page helpful?