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

feat: make finch config available in VM at $HOME/.finch #1180

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/config/nerdctl_config_applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/<user>/.finch/config.json).
// This config change also symlinks ~/.finch in the macOS/Windows perspective (e.g. /User/<user>/.finch) to
// ~/.finch in the vm's perspective (/home/<user>/.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.
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions pkg/config/nerdctl_config_applier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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,
),
Expand All @@ -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,
},
Expand Down
Loading