Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --env-file-to-variables cli option #1332

Closed
AmineDjeghri opened this issue Sep 10, 2024 · 25 comments · Fixed by #1355
Closed

Add --env-file-to-variables cli option #1332

AmineDjeghri opened this issue Sep 10, 2024 · 25 comments · Fixed by #1355
Labels
feature Feature missing according to gitlab ci standard

Comments

@AmineDjeghri
Copy link

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.

@ANGkeith
Copy link
Collaborator

ANGkeith commented Sep 12, 2024

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

image

This might help help you
home-file-variables
project-file-variables

@AmineDjeghri
Copy link
Author

AmineDjeghri commented Sep 12, 2024

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

@ANGkeith
Copy link
Collaborator

I see, so you're requesting for the hard-coded path .gitlab-ci-local-variables.yml to be configurable right ?

@AmineDjeghri
Copy link
Author

Thank you for you quick response !
I'm asking for something like this :

export GCL_ENV_FILE=.env gitlab-ci-local

@ANGkeith
Copy link
Collaborator

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 

@firecow
Copy link
Owner

firecow commented Oct 1, 2024

Is it a env file or variables file you want to be able to specify the location of? Or both 😄

@AmineDjeghri
Copy link
Author

À .env preferably since it's the most used type of file to contain variables (in python)

@firecow
Copy link
Owner

firecow commented Oct 2, 2024

But what kind of values are you putting in your .env file that you want to pass to gitlab-ci-local?

@AmineDjeghri
Copy link
Author

I want to pass all the variables . A .env file is not specific and contains many env variables that change when you switch projects

@firecow
Copy link
Owner

firecow commented Oct 2, 2024

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

@AmineDjeghri
Copy link
Author

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

@ANGkeith
Copy link
Collaborator

ANGkeith commented Oct 3, 2024

image

is the top pane of the screenshot what you're requesting ?
are we understanding you correctly ?

@AmineDjeghri
Copy link
Author

The variables inside a .env needs to have the "=" instead of ":".

WHO="I like ...."

But the idea is this . You are correct

@firecow
Copy link
Owner

firecow commented Oct 3, 2024

Are we talking about the .env file should be extrapolated into GCL_ "commands/options" or variables living inside your jobs?

@ANGkeith
Copy link
Collaborator

ANGkeith commented Oct 3, 2024

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.

@firecow
Copy link
Owner

firecow commented Oct 3, 2024

This is why I wanted a precise .env file with real world contents 😄

@AmineDjeghri
Copy link
Author

AmineDjeghri commented Oct 3, 2024

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

@firecow
Copy link
Owner

firecow commented Oct 3, 2024

Yes yes...

We need a cli options called --env-file-to-variables=.env

Rename the title to "Add --env-file-to-variables cli option" 😄

@AmineDjeghri
Copy link
Author

Glad that we finally understand each other 😂
I renamed the title

@AmineDjeghri AmineDjeghri changed the title Support for Custom .env File Paths in gitlab-ci-local via Environment Variable Add --env-file-to-variables cli option Oct 3, 2024
@ANGkeith
Copy link
Collaborator

ANGkeith commented Oct 3, 2024

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

@firecow
Copy link
Owner

firecow commented Oct 3, 2024

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 😄

@ANGkeith
Copy link
Collaborator

ANGkeith commented Oct 3, 2024

ok just pushed the test, should be good now

@AmineDjeghri
Copy link
Author

AmineDjeghri commented Oct 3, 2024

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

@firecow firecow added the feature Feature missing according to gitlab ci standard label Oct 7, 2024
@AmineDjeghri
Copy link
Author

AmineDjeghri commented Oct 14, 2024

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

@firecow
Copy link
Owner

firecow commented Oct 15, 2024

@AmineDjeghri I'll get it released during the day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature missing according to gitlab ci standard
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants