#Build secrets for preview workers

22 messages · Page 1 of 1 (latest)

cosmic jetty
#

I have a worker that has both variables and secrets in the "Settings" panel for Worker Builds. In production builds everything's fine, but in preview builds, secrets appear empty. To check that I added an env call before builds and logging in the js code. This is what I see:

API_BASEURL=https://****/api/
API_SECRET_KEY=
...
Error: Invalid baseUrl or secretKey ("https://****/api/", "")

What can I do?

nova salmon
#

Can you share your wrangler config and you deploy command?

cosmic jetty
#

can I send you the wrangler.toml privately?

nova salmon
#

Can you redact? I'm mostly interested in your environments config and non production deploy command

cosmic jetty
#

the build command is:

curl https://ipinfo.io/ip ; env ; pnpm run cf-build

the preview deploy command is:

pnpm run deploy --env staging

(without --env staging in the production case)

nova salmon
#

Gotcha, and your staging Worker, can you see if your Worker has the vars set in dash?

cosmic jetty
cosmic jetty
#

the API_SECRET_KEY is set both in build secrets and in "run environment" secrets, or the production build would fail

nova salmon
#

You want these in "variables and secrets" in the Worker settings

#

alternatively wrangler secret put --env staging API_SECRET_KEY

cosmic jetty
#

API_SECRET_KEY is used by next during build to get data for prebuilding pages

nova salmon
#

Honestly I'm not sure up to date on Workers CI (not on that team) that I wouldn't be able to tell ya 😅 . I think you want that as a regular variable for use during your app build

cosmic jetty
#

maybe I'm beginning to understand something... using environments creates automatically a new "worker" with the original name "-environment", but since my build fails that still doesn't exist, so I cannot set build secrets... am I right?

cosmic jetty
nova salmon
cosmic jetty
#

I'm confused as well! There's no way to set secrets on one environment or the other from the "main" worker, so it seems all is ok... thank you very much!

#

for me it's the end of the working day, but I will check back later if someone replied, thanks again!

warm oasis
#

Hey @cosmic jetty 👋 ! Could you share your build_uuid for a preview build which didn't have the env vars you expect, as well as a production build which had the env vars?

#

?workers-build-id