-
Notifications
You must be signed in to change notification settings - Fork 59
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
[Bug]: deployctl deploy executes entrypoint before setting --env vars #311
Comments
I wonder if I'm misunderstanding the intention of deployment-level envars. Maybe they are not really intended for configuration? I notice that Also the example in the
And env vars set at the project level (e.g via the deploy website) are set during deploy. |
Thanks for the report, this is indeed a bug (or rather current limitation with deployctl). To be clear, there are two levels where we can configure env vars; one is project level and the other is deployment level. As you noticed, setting env vars in the settings page of the Deno Deploy dashboard is the project level configuration, whereas what The current limitation we have with deployment-level env var configuration is as follows: what happens internally in So for now, one possible workaround would be setting the required env vars as the project-level - that is, create a project (or you can reuse the empty project you got as a result of running |
Thanks for the explanation & workaround, that's helpful. |
Something has to change. This workaround if (Deno.env.get("MYVAR")) {
main();
} else {
Deno.serve((_) => new Response("Deployment stage"));
} is not something good to have in your codebase. If you don't have the I understand the reasoning behind not having environment variables set during the deployment stage - nothing will be falsely triggered. But I believe that instead Deno Deploy should not try to execute the program before actually deploying it, more faith should be put into the user. You might argue that this should be taken to Deno Deploy feedback or somewhere, but it just works if you attach your repo and set environment variables through the interface. |
Actually, I believe it's important that it does execute before deploying, as it's otherwise easy to push a commit with e.g. an invalid import path that will then be deployed to prod and taking down the site. If a deploy should be made without executing the code first that should be behind a flag, e.g. |
@csvn that's your problem. Deploy, and if everything is fine, promote to production. Just like Deno Deploy does it if you are using the web interface. |
I actually don't have that problem, because we run
The web interface is only used for small experiments, real sites/project has their code in a Git. So this argument is not a point in favor IMO. Let's just agree to disagree about this part, since we seem to have differing opinions. I have my environment variables on the project directly, so I have no issues with this currently. |
@csvn agreeing to disagreeing is fine, but in my opinion arguments like |
One example, that was the reason this issue hit me. I was that running Deno locally and on CI and everything worked fine. But since Deno Deploy is not using the same Deno executable, it was lagging behind in versions, which caused code using import json from "./foo.json" with { type: "json" }; So in my case, I was glad it did not do a broken deploy and break prod just because of this syntax error. Invalid syntax, import issues, or missing features in Deno Deploy did not match the latest Deno CLI version. I learned then that I should be careful in updating CI Deno CLI version, because it's hard do know what version Deno Deploy is using. It's not great if it fails to start up due to env variables, but IMO it's good that it tries to resolve all files and syntax of code that will run, at least for now. I also think part of the reason they do a "dry run" is because Deno Deploy downloads all dependencies from
Fully agree it would be great if docs covered more of this, I've also had some things (like the above) I encountered that made things harder to figure out. |
Problem description
When creating a deployment from the CLI with
deployctl deploy
we can set environment variables with--env
/--env-file
. During deployment, Deno Deploy appears to execute the entrypoint module without the envars set.Steps to reproduce
Create a module/app that requires environment variables to work:
Deploy it with the environment variables set. Deployment fails due to the module being executed without the vars set:
If the throw is removed, deploy proceeds and shows
⠸ Setting environment variables...
after the point that it failed previously.Expected behavior
Environment variables provided should be set when the entrypoint is executed.
Environment
Possible solution
If vars can't be set before executing the entrypoint, maybe provide a way for an app to know it's being executed during deployment as a test, so that it can avoid loading config & failing if it's not available?
Additional context
No response
The text was updated successfully, but these errors were encountered: