diff --git a/CHANGELOG.md b/CHANGELOG.md index 30044eaa74..7c998a1569 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to [Earthly](https://github.com/earthly/earthly) will be doc ### Added +- Added support for a custom `.netrc` file path using the standard `NETRC` environmental variable. [#2426](https://github.com/earthly/earthly/pull/2426) - Ability to run multiple Earthly installations at a time via `EARTHLY_INSTALLATION_NAME` environment variable, or the `--installation-name` CLI flag. The installation name defaults to `earthly` if not specified. Different installations use different configurations, different buildkit Daemons, different cache volumes, and different ports. ### Changed diff --git a/buildcontext/gitlookup.go b/buildcontext/gitlookup.go index b5f545033e..5c3ee85a28 100644 --- a/buildcontext/gitlookup.go +++ b/buildcontext/gitlookup.go @@ -436,8 +436,12 @@ func (gl *GitLookup) detectProtocol(host string) (protocol gitProtocol, err erro var errNoRCHostEntry = fmt.Errorf("no netrc host entry") func (gl *GitLookup) lookupNetRCCredential(host string) (login, password string, err error) { - homeDir, _ := fileutil.HomeDir() - n, err := netrc.Parse(filepath.Join(homeDir, ".netrc")) + netrcPath := os.Getenv("NETRC") + if netrcPath == "" { + homeDir, _ := fileutil.HomeDir() + netrcPath = filepath.Join(homeDir, ".netrc") + } + n, err := netrc.Parse(netrcPath) if err != nil { return "", "", errors.Wrap(err, "failed to parse .netrc") }