diff --git a/pkg/config/nerdctl_config_applier.go b/pkg/config/nerdctl_config_applier.go index b03d1e5f0..9dbe97adc 100644 --- a/pkg/config/nerdctl_config_applier.go +++ b/pkg/config/nerdctl_config_applier.go @@ -76,6 +76,9 @@ func addLineToBashrc(fs afero.Fs, profileFilePath string, profStr string, cmd st // The [GNU docs for Bash] explain how these files work together in more details. // The default location of DOCKER_CONFIG is ~/.docker/config.json. This config change sets the location to // ~/.finch/config.json, but from the perspective of macOS (/Users//.finch/config.json). +// This config change also symlinks ~/.finch in the macOS/Windows perspective (e.g. /User//.finch) to +// ~/.finch in the vm's perspective (/home//.finch) so that it can be found in a well known location +// that doesn't require loading the user's bash rc. // The reason that we don't set environment variables inside /root/.bashrc is that the vars inside it are // not able to be picked up even if we specify `sudo -E`. We have to switch to root user in order to access them, while // normally we would access the VM as the regular user. @@ -107,6 +110,13 @@ func updateEnvironment(fs afero.Fs, fc *Finch, finchDir, homeDir, limaVMHomeDir }, cmdArr...) } + // Ensure we don't end up with a double '/' + // Normally, we would use filepath.Join to do this, but + // we don't want to follow host filepath semantics. This + // is a linux path inside the VM. + limaVMFinchDir := strings.TrimRight(limaVMHomeDir, "/") + "/.finch" + cmdArr = append(cmdArr, fmt.Sprintf(`[ -L %s ] || ln -s $FINCH_DIR %s`, limaVMFinchDir, limaVMFinchDir)) + profileFilePath := fmt.Sprintf("%s/.bashrc", limaVMHomeDir) profBuf, err := afero.ReadFile(fs, profileFilePath) if err != nil { diff --git a/pkg/config/nerdctl_config_applier_test.go b/pkg/config/nerdctl_config_applier_test.go index b8076d8b9..5039506cd 100644 --- a/pkg/config/nerdctl_config_applier_test.go +++ b/pkg/config/nerdctl_config_applier_test.go @@ -68,7 +68,8 @@ FINCH_DIR=/finch/dir AWS_DIR=/home/dir/.aws export DOCKER_CONFIG="$FINCH_DIR" [ -L /usr/local/bin/docker-credential-ecr-login ] || sudo ln -s "$FINCH_DIR"/cred-helpers/docker-credential-ecr-login /usr/local/bin/ -[ -L /root/.aws ] || sudo ln -fs "$AWS_DIR" /root/.aws`), string(fileBytes)) +[ -L /root/.aws ] || sudo ln -fs "$AWS_DIR" /root/.aws +[ -L /home/mock_user.linux/.finch ] || ln -s $FINCH_DIR /home/mock_user.linux/.finch`), string(fileBytes)) }, want: nil, }, @@ -95,7 +96,8 @@ FINCH_DIR=/finch/dir AWS_DIR=/home/dir/.aws export DOCKER_CONFIG="$FINCH_DIR" [ -L /usr/local/bin/docker-credential-ecr-login ] || sudo ln -s "$FINCH_DIR"/cred-helpers/docker-credential-ecr-login /usr/local/bin/ -[ -L /root/.aws ] || sudo ln -fs "$AWS_DIR" /root/.aws)`, +[ -L /root/.aws ] || sudo ln -fs "$AWS_DIR" /root/.aws) +[ -L /home/mock_user.linux/.finch ] || ln -s $FINCH_DIR /home/mock_user.linux/.finch`, ), 0o644, ), @@ -109,7 +111,8 @@ FINCH_DIR=/finch/dir AWS_DIR=/home/dir/.aws export DOCKER_CONFIG="$FINCH_DIR" [ -L /usr/local/bin/docker-credential-ecr-login ] || sudo ln -s "$FINCH_DIR"/cred-helpers/docker-credential-ecr-login /usr/local/bin/ -[ -L /root/.aws ] || sudo ln -fs "$AWS_DIR" /root/.aws)`), string(fileBytes)) +[ -L /root/.aws ] || sudo ln -fs "$AWS_DIR" /root/.aws) +[ -L /home/mock_user.linux/.finch ] || ln -s $FINCH_DIR /home/mock_user.linux/.finch`), string(fileBytes)) }, want: nil, },