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

[wip] Migrate to rig v2 #755

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

[wip] Migrate to rig v2 #755

wants to merge 1 commit into from

Conversation

kke
Copy link
Contributor

@kke kke commented Aug 15, 2024

No description provided.

Signed-off-by: Kimmo Lehto <[email protected]>
@kke kke added enhancement New feature or request chore Housekeeping / typo / code quality improvements labels Aug 15, 2024
@kke
Copy link
Contributor Author

kke commented Aug 15, 2024

Here's some notes I wrote earlier about what needs to be changed:

  • the Host object needs to embed rig.ClientWithConfig - not rig.Connection or whatever its embedding now.
  • the client.Connect requires context, you can use something like ContextWithTimeout(60 * time.Second) - it also does not require any retry logic, rig does the retry on its own for that duration.
  • anything that has exec.Sudo() is broken. the way to do sudo now is h.Sudo().Exec(...)
  • anything that imports rig/exec needs to import rig/v2/cmd (unless it's done only to bring in Sudo(), in which case the import is probably not needed anyway). things like exec.Stdin(...) and other exec options are now cmd.Stdin(...) and so on.
  • in addition to ExecOutput, there's "ExecReader" (returns an io.Reader to read from, the read error will reflect the command exit status if the command errors out) and "ExecScanner" (like exec.Reader, but returns a bufio.Scanner for reading output line by line, reader.Err() returns the command's error if it errors out)
  • looks like launchpad never used the h.Execf("cmd %s", path) sprintf-style formatters. It probably does a lot of h.Exec(fmt.Sprintf(...)) , those will still work but there's a better command builder available now: h.Exec(sh.Command("cmd", path)) it will automatically shellescape the args. The sh.CommandBuilder variant can do crazy stuff like: sh.CommandBuilder("cmd").Arg(path).Pipe("grep").Args("-q", query).ErrToNull().String()
  • the os-release stuff that was made earlier for the weird extra fields is now in h.GetOS() or was it h.OS(). It now has Extra field.
  • all the InstallPackages things in configurers can be thrown away and usages replaced with h.PackageManager().Install("foo", "bar")
  • Service starting and stopping is like h.Service("service-name").Start(ctx)
  • the initExec in common.go needs to be changed (there's no more confirm, disableredact is in cmd)
  • any configurer that imports rig.Linux or whatever, needs to stop doing that.
  • there's no more things like Configurer.ReadFile(...) - instead you do f, err := h.FS().Open(path); buf := io.ReadAll(f) or h.FS().ReadFile(path) or to use sudo: h.Sudo().FS().ReadFile(path) - some of the stuff that was behind Configurer may now exist behind h.FS() if it's file related.
  • h.FS() implements the fs.FS from io/fs and thus can be used as a regular filesystem for some stuff.
  • it's now possible / easy to mock the connection / command running in tests. you can do something like conn := rigtest.NewMockConnection(); conn.AddCommandOutput("ls", "file1.txt"); h.Setup(rig.WithConnection(conn)) and then if your code does h.Exec("ls"), the output will be file1.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Housekeeping / typo / code quality improvements enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant