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

fix: Refresh ~/.finch/confg.json based on finch.yaml #966

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions cmd/finch/virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,20 @@ func newVirtualMachineCommand(
fp path.Finch,
fs afero.Fs,
diskManager disk.UserDataDiskManager,
finchDir string,
) *cobra.Command {
virtualMachineCommand := &cobra.Command{
Use: virtualMachineRootCmd,
Short: "Manage the virtual machine lifecycle",
}

virtualMachineCommand.AddCommand(
newStartVMCommand(limaCmdCreator, logger, optionalDepGroups, lca, nca, fs, fp.LimaSSHPrivateKeyPath(), diskManager),
newStartVMCommand(limaCmdCreator, logger, optionalDepGroups, lca, nca, fs, fp.LimaSSHPrivateKeyPath(), diskManager, finchDir),
newStopVMCommand(limaCmdCreator, diskManager, logger),
newRemoveVMCommand(limaCmdCreator, diskManager, logger),
newStatusVMCommand(limaCmdCreator, logger, os.Stdout),
newInitVMCommand(limaCmdCreator, logger, optionalDepGroups, lca, nca, fp.BaseYamlFilePath(), fs,
fp.LimaSSHPrivateKeyPath(), diskManager),
fp.LimaSSHPrivateKeyPath(), diskManager, finchDir),
newSettingsVMCommand(logger, lca, fs, os.Stdout),
)

Expand Down Expand Up @@ -106,10 +107,12 @@ func virtualMachineCommands(
home string,
finchRootPath string,
) *cobra.Command {
finchDir := fp.FinchDir(finchRootPath)

return newVirtualMachineCommand(
lcc,
logger,
dependencies(ecc, fc, fp, fs, lcc, logger, fp.FinchDir(finchRootPath)),
dependencies(ecc, fc, fp, fs, lcc, logger, finchDir),
config.NewLimaApplier(
fc,
ecc,
Expand All @@ -123,13 +126,14 @@ func virtualMachineCommands(
fssh.NewDialer(),
fs,
fp.LimaSSHPrivateKeyPath(),
fp.FinchDir(finchRootPath),
finchDir,
home,
fp.LimaInstancePath(),
fc,
),
fp,
fs,
disk.NewUserDataDiskManager(lcc, ecc, &afero.OsFs{}, fp, finchRootPath, fc, logger),
finchDir,
)
}
18 changes: 17 additions & 1 deletion cmd/finch/virtual_machine_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package main

import (
"fmt"
"path/filepath"

"github.com/runfinch/finch/pkg/dependency/credhelper"
"github.com/runfinch/finch/pkg/disk"

"github.com/runfinch/finch/pkg/command"
Expand All @@ -28,11 +30,12 @@ func newInitVMCommand(
fs afero.Fs,
privateKeyPath string,
diskManager disk.UserDataDiskManager,
finchDir string,
) *cobra.Command {
initVMCommand := &cobra.Command{
Use: "init",
Short: "Initialize the virtual machine",
RunE: newInitVMAction(lcc, logger, optionalDepGroups, lca, baseYamlFilePath, diskManager).runAdapter,
RunE: newInitVMAction(lcc, logger, optionalDepGroups, lca, baseYamlFilePath, fs, diskManager, finchDir).runAdapter,
PostRunE: newPostVMStartInitAction(logger, lcc, fs, privateKeyPath, nca).runAdapter,
}

Expand All @@ -45,7 +48,9 @@ type initVMAction struct {
logger flog.Logger
optionalDepGroups []*dependency.Group
limaConfigApplier config.LimaConfigApplier
fs afero.Fs
diskManager disk.UserDataDiskManager
finchDir string
}

func newInitVMAction(
Expand All @@ -54,15 +59,19 @@ func newInitVMAction(
optionalDepGroups []*dependency.Group,
lca config.LimaConfigApplier,
baseYamlFilePath string,
fs afero.Fs,
diskManager disk.UserDataDiskManager,
finchDir string,
) *initVMAction {
return &initVMAction{
creator: creator,
logger: logger,
optionalDepGroups: optionalDepGroups,
limaConfigApplier: lca,
baseYamlFilePath: baseYamlFilePath,
fs: fs,
diskManager: diskManager,
finchDir: finchDir,
}
}

Expand All @@ -86,6 +95,13 @@ func (iva *initVMAction) run() error {
return err
}

finchConfigPath := filepath.Join(iva.finchDir, "finch.yaml")
configJSONPath := filepath.Join(iva.finchDir, "config.json")
err = credhelper.RefreshConfigFile(iva.fs, iva.logger, finchConfigPath, configJSONPath)
if err != nil {
return err
}

err = dependency.InstallOptionalDeps(iva.optionalDepGroups, iva.logger)
if err != nil {
iva.logger.Errorf("Dependency error: %v", err)
Expand Down
Loading
Loading