composer rewrites my .env file by new generated one - symfony

When I run composer install for my symfony project, my .env file is rewrote by new generated one. What should I do to save my .env intact?

Applications created after November 2018 had a slightly different system, read changes
From the official documentation
.env.local : defines/overrides env vars for all environments but only in your local machine
.env : defines the default value of env vars.
The .env and .env.<environment> files should be committed to the shared repository because they are the same for all developers. However, the .env.local and .env.<environment>.local and files should not be committed because only you will use them. In fact, the .gitignore file that comes with Symfony prevents them from being committed.

Related

vercel nextjs not load env variables

When I do git push to the project without put .env to .gitignore file the project work fine and load the env variables but when put .env in .gitignore file and do git push and add env variables to project setting and redeploy the project in this case vercel not load env variables.
UI Setting env variables
I don't know why ?
any suggestions please !

How to set environment variables with Prisma, Nextjs, and Vercel

Nextjs wants you to use a .env.local file to store env vars.
Prisma uses .env
If I use a .env.local file then setting up the Prisma db
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
I get a DATABASE_URL does not exist error.
What's the right way to set up env vars for a Prisma, Nextjs, Vercel app?
You can use dotenv-cli to force loading specific environment file.
1- Install dotenv-cli package
2- create script to run env before prisma migration on your package
"scripts": {
...
"prismaDev": "dotenv -e .env.local prisma migrate dev ",
}
3- now you can simply run npm run prismaDev
You can load environment variables with process.env.DATABASE_URL in your case and you can leave it in .env as Prisma asks for. Nextjs can handle multiple .env files without any extra effort.
No need to use an extra package, Nextjs will handle the env vars for you.
https://nextjs.org/docs/basic-features/environment-variables
You can leave the standard setup and use the created .env file (by the prisma cli:
https://www.prisma.io/docs/getting-started/setup-prisma) and add your connection string.
the rest is magically handled by next.
Be sure to follow the instructions (manual or cli pointers) regarding gitignore and such..
To reiterate: both can live next to each other! Check the next documentation for load order if it matters. (see link above)

How to load environment variables from a dotenv file in Flyway?

Flyway supports environment variables in config files.
Is there a way to make Flyway load these variables from a file, similarly to what Docker and Node.js with dotenv do?
The content of the .env file is for example:
DB_URL=jdbc:postgresql://localhost:5432/db_name
And flyway.conf:
flyway.url=${DB_URL}
If you are using flyway-maven-plugin, you have 3 ways currently:
Defining flyway properties in POM.xml
eg.
<properties>
<flyway.url>jdbc:h2:mem:public;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MySQL;INIT=CREATE SCHEMA IF NOT EXISTS "public";</flyway.url>
<flyway.user>root</flyway.user>
<flyway.password></flyway.password>
</properties>
Defining your flyway properties in some .env or a .conf file.
mvn -Dflyway.configFiles=src/main/resources/some-env-file.env flyway:migrate
Contents of some-env-file.env:
flyway.url=jdbc:h2:mem:public;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MySQL;INIT=CREATE SCHEMA IF NOT EXISTS "public";
flyway.user=root
flyway.password=
Injecting the environment variables directly during maven goal execution:
mvn -Dflyway.url="jdbc:h2:mem:public;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MySQL;INIT=CREATE SCHEMA IF NOT EXISTS public;" -Dflyway.user=root -Dflyway.password=root flyway:migrate
But if you want to load properties from some file using properties-maven-plugin and make them available as enviroment variables, to be used by your flyway-maven-plugin , then unfortunately that is not working.
Here is the github issue tracking this.

Vue firebase hosting environment variables

Currently in my dev environment i have my .env.development file with my firebase environment variables stored as:
VUE_APP_FB_API_KEY='abc123000123',
VUE_APP_FB_AUTH_DOMAIN='site.firebaseapp.com',
etc...
This works fine for my dev machine but once i deploy this to firebase hosting it breaks and throws console errors that the various options are not configured. I tried adding them with
firebase functions:config:set env.VUE_APP_FB_API_KEY='abc123000123'
but this is still not working for me.
What is wrong here? Also per the docs upper-case characters are not allowed..
When you run on local, vue-cli will read .env.development config file. But when you build for production, it will use production mode and will read .env file.
You should copy .env.development to .env then build and deploy again.
Or you can create .env.production file, which is only used for production build.
.env # loaded in all cases
.env.local # loaded in all cases, ignored by git
.env.[mode] # only loaded in specified mode
.env.[mode].local # only loaded in specified mode, ignored by git
You can read more about the enviroment variable and build mode in vue-cli official document.

Edit env file in pipeline

I have a symfony skeleton project, and I use the .env file for storing the environment variables.
Inside the Dockerfile, I run composer install, but it creates a .env file. From my pipeline environment variables I want to edit the .env file. What is the best approach to do that?
Delete the .env and create my own? Or is there a way to edit the .env file?
You can use bash redirection to append values to your .env file.
echo ENV_VARAIBLE=value > .env - Use this if .env doesn't exist, (op.a. it overwrites existing .env)
echo ENV_VARIABLE_2=value2 >> .env - Use this to append variable to existing .env file.
More: https://unix.stackexchange.com/questions/89386/what-is-symbol-and-in-unix-linux
A lot more: http://www.catonmat.net/blog/bash-one-liners-explained-part-three/

Resources