denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.77k stars 5.22k forks source link

Production Deploys from `deployctl` use KV data from preview database instead #24579

Open huntercaron opened 1 month ago

huntercaron commented 1 month ago

With Deno Deploy, calling kv.set()/kv.get() from production uses "preview" KV database, rather than the main database as expected. This only happens on production deploys made with deployctl --prod, if Github integration is also active.

Reproduction Steps

  1. Start a project using deployctl
  2. Add Github integration and a deployment via it
  3. Make another production deploy with deployctl
  4. Using kv.set(["key", "id"], data) on that production deployment will store to preview database
  5. (You can easily verify in the Deno dashboard)

Additional Info

Reproduction To test this, I created a new minimal setup that stores into the KV. It stores a random number for a given slug, and is enough to reproduce the above

const kv = await Deno.openKv()

Deno.serve(async (request: Request) => {
  const random = String(Math.floor(Math.random() * 1000))
  const slug = request.url.split("/").pop() || ""

  if (!slug) {
    return new Response("Please provide a slug.", { status: 404 })
  }

  await kv.set(["random", slug], random)
  console.log("Stored:", random, "for", slug)

  return new Response(`Stored: ${random} for ${slug}`)
})

When running this code on a Deno Deploy project that has the Github integration set up and has its latest prod deploy created via the deployctl tool, it will store into the preview database. You can verify in the dashboard. Side note: without a preview branch, I wouldn't even expect this database to exist.

Screenshot 2024-07-14 at 11 16 14 Screenshot 2024-07-14 at 11 16 49

Version: Deno Deploy / Deno 1.45.1

huntercaron commented 1 month ago

As for why I am using both, Github deploys feel much slower, and when having to hot-fix something you want to be able to get the fix out before spending the time to ensure your git history is in good shape

skabber commented 1 month ago

I ran into this yesterday. It was a BIG problem for me when I went to do a deploy using deployctl deploy --prod and all of a sudden my prod domain showed all preview data.

I had to push a build via Github in order to get my domain to show the main (non-preview) data again.