deploy_feedback icon indicating copy to clipboard operation
deploy_feedback copied to clipboard

Provide preset environment variable to distinguish Preview vs Production Deployments

Open thegaryroberts opened this issue 4 years ago • 3 comments

It would be useful for code to be able to determine which type of deployment it is running within via environment variable. Right now I have to manage this with a flag in code that only lives in the main branch, and be careful not to invalidate that flag during merges.

I can give more details on my specific use case if it is of interest.

thegaryroberts avatar Dec 24 '21 20:12 thegaryroberts

I agree that I need this feature.

For my use case, I want to access the development database from the preview deployment and the production database from the production deployment. So I need a way to distinguish between preview and production.

ayame113 avatar Dec 07 '22 08:12 ayame113

I completely agree. For my external DB credentials I keep two similar sets of env:

MY_DBNAME_PREVIEW=my-db-dev
MY_USER_PREVIEW=my-dbuser-dev
MY_PASS_PREVIEW=123dev789

MY_DBNAME_PROD=my-db-prod
MY_USER_PROD=my-dbuser-prod
MY_PASS_PROD=123prod789

It's because a production build at deno deploy receives a shorter and a longer URL at the same time, latter being indistinguishable with any other preview builds. To distinguish PROD or REVIEW, I use hostname from user's request. When the URL is shorter, it is likely about PROD, otherwise PREVIEW. But there is no guarantee. PROD also receives a longer URL and users can call it without notice. So I have to keep both _PROD and _REVIEW variables just in case, and everytime I receive an incoming request I have to run a function like targetFromRequest(req): Target { ... } to obtain the target type. This is request based, not service (build) based, which is inconvenient.

We need a more straightforward and stable solution to tell if it's PROD or REVIEW.

tanquar avatar Dec 23 '22 14:12 tanquar

It cannot be discerned from this URL if it's a prod or preview deployment: "{project_name}-{deployment_id}.deno.dev"

martpet avatar Jan 19 '24 13:01 martpet