-
Notifications
You must be signed in to change notification settings - Fork 73
fix deploy
and upload
commands not taking into account environment variables
#818
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
Conversation
🦋 Changeset detectedLatest commit: 945f849 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
const platformProxyEnvVars = await getEnvFromPlatformProxy({ | ||
configPath: args.configPath, | ||
environment: args.env, | ||
}); | ||
|
||
const envVars = { ...platformProxyEnvVars, ...process.env }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upload.ts
should be updated as well.
May be we could add a includeProcessEnv: Boolean
to getEnvFromPlatformProxy
so that we could document the purpose on the JSDoc of that functon.
I'm wondering if it should { ...platformProxyEnvVars, ...process.env }
or { ...process.env, ...platformProxyEnvVars}
- I would tend to prefer the latest as proxy vars are more specific as they could change with the environment but I don't have a very strong opinion on that. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I'm wondering if we should rather update
opennextjs-cloudflare/packages/cloudflare/src/cli/commands/skew-protection.ts
Lines 68 to 86 in c46eeee
if (!envVars.CF_WORKER_NAME) { | |
logger.error("CF_WORKER_NAME should be set when skew protection is enabled"); | |
process.exit(1); | |
} | |
if (!envVars.CF_PREVIEW_DOMAIN) { | |
logger.error("CF_PREVIEW_DOMAIN should be set when skew protection is enabled"); | |
process.exit(1); | |
} | |
if (!envVars.CF_WORKERS_SCRIPTS_API_TOKEN) { | |
logger.error("CF_WORKERS_SCRIPTS_API_TOKEN should be set when skew protection is enabled"); | |
process.exit(1); | |
} | |
if (!envVars.CF_ACCOUNT_ID) { | |
logger.error("CF_ACCOUNT_ID should be set when skew protection is enabled"); | |
process.exit(1); | |
} |
to read from either process.env
of envVars
.
That would be a more targeted change.
What are your thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upload.ts
should be updated as well.
Updated 👍
May be we could add a
includeProcessEnv: Boolean
togetEnvFromPlatformProxy
so that we could document the purpose on the JSDoc of that functon.
What about renaming the function getEnvironmentVariables
and have it always include values from both platformProxy
and process.env
? would there be an issue with that?
I'm wondering if it should
{ ...platformProxyEnvVars, ...process.env }
or{ ...process.env, ...platformProxyEnvVars}
- I would tend to prefer the latest as proxy vars are more specific as they could change with the environment but I don't have a very strong opinion on that. What do you think?
I purposely put ...process.env
as last since I think system environment variables should have precedence over those in the config files, for example if I run something line:
$ CF_ACCOUNT_ID="123" npm run deploy
I would personally expect that "123" would override a potential CF_ACCOUNT_ID
value present in the config file.
I do think that this is the common behavior for this sort of things. Having the system environment variables also adds more flexibility to users, that could for example very easily deploy their worker onto different accounts (silly example):
$ CF_ACCOUNT_ID="123" npm run deploy
$ CF_ACCOUNT_ID="456" npm run deploy
What would the benefits in having the platformProxy
have precedence over process.env
be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I'm wondering if we should rather update
opennextjs-cloudflare/packages/cloudflare/src/cli/commands/skew-protection.ts
Lines 68 to 86 in c46eeee
if (!envVars.CF_WORKER_NAME) { logger.error("CF_WORKER_NAME should be set when skew protection is enabled"); process.exit(1); } if (!envVars.CF_PREVIEW_DOMAIN) { logger.error("CF_PREVIEW_DOMAIN should be set when skew protection is enabled"); process.exit(1); } if (!envVars.CF_WORKERS_SCRIPTS_API_TOKEN) { logger.error("CF_WORKERS_SCRIPTS_API_TOKEN should be set when skew protection is enabled"); process.exit(1); } if (!envVars.CF_ACCOUNT_ID) { logger.error("CF_ACCOUNT_ID should be set when skew protection is enabled"); process.exit(1); } to read from either
process.env
ofenvVars
.That would be a more targeted change.
What are your thoughts?
I think that generally it would make more sense to get the environment variables from both getPlatformProxy
and process.env
, actually generally process.env
makes more sense to me if we're talking about build time variables, since the variables in getPlatformProxy
are, in my opinion, runtime variables.
But if you prefer I'll update the code to limit the change to the skew protection logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about renaming the function getEnvironmentVariables and have it always include values from both platformProxy and process.env? would there be an issue with that?
From the discussion, I think getEnvFromPlatformProxy
and have it returns only the the env. This is the original use case and what we usually want - i.e. when we access the cache at build time, we want to use the config that will be used at runtime.
So I think what we want is to pass the getEnvFromPlatformProxy()
and getDeployementMapping()
(i.e. no change from what we do today).
Inside this function you could add env = {...envVars, ...process.env};
with a comment that process.env has priority for those variables (agreed that process.env
should have priority)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, hopefully this is what you had in mind: 945f849
deploy
command not taking into account environment variablesdeploy
and upload
commands not taking into account environment variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Could you please comment the change at https://opennext.js.org/cloudflare/howtos/skew#:~:text=%7D-,Environment%20variables,-The%20following%20environment
How would you like me to update the docs there? I think that they are correct already? would you like me directly specify that environment variables are taken from both the platform proxy and the system env variables? |
Yes. The doc says "environment variables", we should clarify what this means wrt "process environment variables" and "wrangler environment variables". |
Fixes: #801