There’s sevral way in Expo to store secets for our build. Directly like:
eas secret:create --name API_KEY --value 0123456789 --type string
or by uploading a .env
file like so:
eas secret:push --scope project --env-file .env
The struggle I have here is that, given different environments like development, staging and production, I have no idea how I am able to “select” the right environment variables for different builds.
So far, I only discovered uploading prefixed versions of environment variables like this:
eas secret:create --name DEV_API_KEY --value dev-dev-dev --type string
eas secret:create --name STG_API_KEY --value stg-stg-stg --type string
eas secret:create --name PRD_API_KEY --value prd-prd-prd --type string
and than map them in my eas.json
like so:
"development": {
"env": { "API_KEY": "DEV_API_KEY" }
},
"staging": {
"env": { "API_KEY": "STG_API_KEY" }
},
"production": {
"env": { "API_KEY": "PRD_API_KEY" }
}
but please now imagine you’d have five or ten secrets..
The only “workaround” I’d see here would be to create different projects. Each project has its own slug which means it would be possible to add do this inside the app.config.ts
:
const SLUGS = {
development: "my-project-dev",
staging: "my-project-stg",
production: "my-project-prd",
}
type SlugKey = keyof typeof SLUGS;
export default ({ config }: ConfigContext): ExpoConfig => {
return {
...(config as ExpoConfig),
slug: SLUGS[process.env.ENVIRONMENT as SlugKey],
}
}
But this as well feels like an abuse.
I couldn’t find any guidelines on how to manage this. How can we manage different environments without having to store prefixed environment variables?