Prisma1: Support for multiple (prod/stag/dev) environments

Created on 30 May 2018  路  7Comments  路  Source: prisma/prisma1

Feature Request

What feature are you missing?

Since I've been using Prisma in a production project, I've struggled with how to maintain separate environments. Currently, we have a /prisma folder with a docker-compose.yml file, this gives us the ability to develop locally with a local DB and Prisma instance.

When it comes to deploying to our staging / production environments, it would be really useful if the configuration for these could live "side-by-side" with the dev environment settings, and simply have a solution like:

  • prisma deploy - Deploys to dev environment
  • prisma deploy --staging - Deploy to staging environment
  • prisma deploy --production - Deploy to production environment

It might even be worth making a generic prisma deploy --stage=XXX.

Clearly, for each stage "name", there needs to be an appropriate configuration, such that it knows where the endpoint is, what the management API secret is, etc.

Potentially, environment variables might need to be thought about being utilised here? .env.prod / .env.staging etc. ?

Also, how this might work when integrating with CD tools, such as CircleCI.

bu0-needs-info statustale

Most helpful comment

prisma -e ENV-FILE deploy will pick up environment variables, and I think you can do everything you're looking for with that.

https://www.prisma.io/docs/reference/cli-command-reference/database-service/prisma-deploy-kee1iedaov

In prisma.yml you can reference environment variables:

endpoint: ${env:PRISMA_ENDPOINT}
secret: ${env:PRISMA_SECRET}

And docker-compose.yml:

...
managementApiSecret: ${PRISMA_MANAGEMENT_API_SECRET}
...

All 7 comments

prisma -e ENV-FILE deploy will pick up environment variables, and I think you can do everything you're looking for with that.

https://www.prisma.io/docs/reference/cli-command-reference/database-service/prisma-deploy-kee1iedaov

In prisma.yml you can reference environment variables:

endpoint: ${env:PRISMA_ENDPOINT}
secret: ${env:PRISMA_SECRET}

And docker-compose.yml:

...
managementApiSecret: ${PRISMA_MANAGEMENT_API_SECRET}
...

@mponizil But I think I'm right in saying that the prisma CLI doesn't automatically pick up environment variables defined in the shell/terminal, etc? This makes it pretty hard to do things with a CD tool such as CircleCI or such, as the .env files aren't committed to Git and the env vars in the environment get ignored?

Hmm, it should work with normal environment variables: https://www.prisma.io/docs/reference/service-configuration/prisma.yml/overview-and-example-foatho8aip#environment-variable

Are they not working for you? Note: environment vars are accessed with env: prefix in prisma.yml.

Ah, gotcha. Think I've got it all working now. So environments can now all be tweaked based on environment vars, which in-turn, allows use of .env.staging, etc. and CircleCI env injection. All sorted!

@mponizil After getting some time to try this all out, I've got it partially working, _but_ the -e ENV-FILE argument doesn't seem to be working. I've tried pointing it at a .env.staging file and it continues to use the ENV VARS defined locally, rather than the ones in the file.

(ie. local ENV VARS are taking "precedence" over the ones manually specified in the file path)

I believe it's down to this, as dotenv is being used internally: https://github.com/motdotla/dotenv#what-happens-to-environment-variables-that-were-already-set

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ragnorc picture ragnorc  路  3Comments

sorenbs picture sorenbs  路  3Comments

Fi1osof picture Fi1osof  路  3Comments

nikolasburk picture nikolasburk  路  3Comments

schickling picture schickling  路  3Comments