Add --env-file-to-variables cli option
AmineDjeghri opened this issue ยท 25 comments
Is your feature request related to a problem? Please describe.
Currently, I must store the .env file in one directory, limiting flexibility, and having to manager two separate .env files. I'd like to be able to specify the .env file's location via an environment variable so it can be used from any directory or path.
Describe the solution you'd like
add the option to define the path to the .env file using an environment variable, like this: export GCL_ENV_FILE=.env. This would allow the gitlab-ci-local command to use the .env file from any given path, regardless of its directory. This change would allow for more flexibility in working with multiple environments and project structures.
What exactly are you trying to do ?
I assume you are hoping to have a centralized place to defined the "gitlab variables" for your pipeline
This might help help you
home-file-variables
project-file-variables
I just want to pass a .env file variables.
We have a project that runs with environment variables, and we do it with a .env.
If you take an example on GitHub Act (a tool to run GitHub actions locally), we can pass .env path.
Also for local testing, we also use .env file .
The purpose for the .env is not just for gitlab testing but for everything. It's a standard.
It would be great to have this on gitlab-ci-local
I see, so you're requesting for the hard-coded path .gitlab-ci-local-variables.yml
to be configurable right ?
Thank you for you quick response !
I'm asking for something like this :
export GCL_ENV_FILE=.env gitlab-ci-local
Creating the following symbolic link should be a quick fix while waiting for this to be implemented
ln -s .env .gitlab-ci-local-variables.yml
Is it a env file or variables file you want to be able to specify the location of? Or both ๐
ร .env preferably since it's the most used type of file to contain variables (in python)
But what kind of values are you putting in your .env file that you want to pass to gitlab-ci-local
?
I want to pass all the variables . A .env file is not specific and contains many env variables that change when you switch projects
I think you need to clarify very precisely what you want this feature to become in a new issue or here.
Add very realworld like .env files and gitlab-ci.yml's n' such...
Normally people put variables inside the <cwd>/.gitlab-ci-local-variables.yml
or ~/.gitlab-ci-local/variables.yml
Sorry but I don't know how to be clearer than this ๐
I want to be able to load the environment variables from a specified .env file .
So for example when I run the gitlab ci local, I provide the path of the .env file and it will load all the env variables
Here is an example of a .env file (this one is named .env.example but the true name is .env). It contains some environment variables that will be loaded
https://github.com/platformsh-templates/laravel/blob/master/.env.example
The variables inside a .env needs to have the "=" instead of ":".
WHO="I like ...."
But the idea is this . You are correct
Are we talking about the .env file should be extrapolated into GCL_
"commands/options" or variables living inside your jobs?
Are we talking about the .env file should be extrapolated into
GCL_
"commands/options" or variables living inside your jobs?
Yeah, I think this is where the confusion comes from, haha. I was wondering the same thing.
I believe he's referring to variables used within your jobs
.
This is why I wanted a precise .env file with real world contents ๐
I think it is better to write a little scenario for what I want
I have a repository that contains somewhere a .env file (it is ignored in .gitignore)
I run the gitlab ci local command with for example an argument : GCL_ENV_FILE=path/to/file/.env and I specify the path to the .env file
Gitlab ci local will load inside my container the variables that are inside the .env
If I do : echo $VARIABLE1 inside my gitlab ci local container, I will the the value of the variable that is inside the .env which means that it properly exported the variables inside the .env file
Yes yes...
We need a cli options called --env-file-to-variables=.env
Rename the title to "Add --env-file-to-variables cli option" ๐
Glad that we finally understand each other ๐
I renamed the title
We need a cli options called
--env-file-to-variables=.env
i was thinking about something like this instead, https://github.com/firecow/gitlab-ci-local/pull/1355/files#diff-3d6e22f8e4281faf7d19dcacaf5fe63566f6ada084252104ef5f04b9c687e140R121-R123
what do you think ?
if it's ok, i'll add some test cases for it
https://github.com/firecow/gitlab-ci-local/pull/1355/files#diff-59b63d2cf1329cb81baf1d68651daaaa07d5c91e2062db5051bc9fed04488bf0R1 .env files doesn't look like this.
Perhaps @AmineDjeghri at some point, would be so kind to provide an example .env
file preferably with rather complex key=value pairs ๐
ok just pushed the test, should be good now
I would like to thank you first for working on this. I really do enjoy what you did with this tool.
I already provided a link to a.env example. But here is a copy paste of that same file. As you can see, we can use quotes for string
#with quotes
APP_NAME="Laravel"
# without quotes
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
I just updated to the latest version and i got this message when i tried to use the .env
Running Gitlab Runner locally...
Running Docker compose services...
Unknown arguments: variables-file, variablesFile
make: *** [Makefile:120: gitlab-ci-local] Error 1
edit: my bad. I just checked and the fix is not yet released
i would like to suggest an update in the readme : #1379
@AmineDjeghri I'll get it released during the day