Skip to content

Commit

Permalink
If 'truncate' fails for /etc/machine-id during 'commit', attempt with…
Browse files Browse the repository at this point in the history
… 'sudo' before giving up

If 'truncate' fails for /etc/machine-id, attempt with 'sudo' before giving up (#29). Also, fix a spelling error in the help messages.
  • Loading branch information
mmguero authored Oct 30, 2024
1 parent 5276691 commit 4634be3
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/image_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func imageBuildCommand() *cobra.Command {
buildCmd.Flags().BoolVar(&resetMachineID, "reset-machine-id", true, "Whether or not to clear the /etc/machine-id file after provisioning")
buildCmd.Flags().VarP(&vmPullPolicy, "pull-policy", "", "Whether or not to pull the source image.")
buildCmd.Flags().VarP(&vmPullPolicy, "vm-pull-policy", "", fmt.Sprintf("Whether or not to pull the source image. Valid values: [%s, %s, %s]", pullpolicy.Always, pullpolicy.IfNotExist, pullpolicy.Never))
buildCmd.Flags().VarP(&containerPullPolicy, "container-pull-policy", "", fmt.Sprintf("Whether or not to pull container images used durign provisioning. Overrides the `pull` value of every provision step. Valid values: [%s, %s, %s]", pullpolicy.Always, pullpolicy.IfNotExist, pullpolicy.Never))
buildCmd.Flags().VarP(&containerPullPolicy, "container-pull-policy", "", fmt.Sprintf("Whether or not to pull container images used during provisioning. Overrides the `pull` value of every provision step. Valid values: [%s, %s, %s]", pullpolicy.Always, pullpolicy.IfNotExist, pullpolicy.Never))
buildCmd.Flags().BoolVarP(&push, "push", "", false, "Push the image after building")
buildCmd.Flags().BoolVarP(&noCache, "no-cache", "", false, "Disable caching for the image build")
buildCmd.Flags().StringVarP(&buildId, "build-id", "", "", "Build ID used to determine if an image needs to be rebuild.")
Expand Down
2 changes: 1 addition & 1 deletion cmd/vm_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func vmExecCommand() *cobra.Command {

execCmd.Flags().VarP(&provFile, "provision", "p", "name of toml file containing provisioning steps")
execCmd.Flags().StringArrayVarP(&provisionOverrides, "set", "s", []string{}, "set/override provisioning steps")
execCmd.Flags().VarP(&containerPullPolicy, "container-pull-policy", "", fmt.Sprintf("Whether or not to pull container images used durign provisioning. Overrides the `pull` value of every provision step. Valid values: [%s, %s, %s]", pullpolicy.Always, pullpolicy.IfNotExist, pullpolicy.Never))
execCmd.Flags().VarP(&containerPullPolicy, "container-pull-policy", "", fmt.Sprintf("Whether or not to pull container images used during provisioning. Overrides the `pull` value of every provision step. Valid values: [%s, %s, %s]", pullpolicy.Always, pullpolicy.IfNotExist, pullpolicy.Never))

return execCmd
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/vm_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func vmRunCommand() *cobra.Command {

runCmd.Flags().VarP(&vmPullPolicy, "pull-policy", "", "Whether or not to pull the source image.")
runCmd.Flags().VarP(&vmPullPolicy, "vm-pull-policy", "", fmt.Sprintf("Whether or not to pull the source image. Valid values: [%s, %s, %s]", pullpolicy.Always, pullpolicy.IfNotExist, pullpolicy.Never))
runCmd.Flags().VarP(&containerPullPolicy, "container-pull-policy", "", fmt.Sprintf("Whether or not to pull container images used durign provisioning. Overrides the `pull` value of every provision step. Valid values: [%s, %s, %s]", pullpolicy.Always, pullpolicy.IfNotExist, pullpolicy.Never))
runCmd.Flags().VarP(&containerPullPolicy, "container-pull-policy", "", fmt.Sprintf("Whether or not to pull container images used during provisioning. Overrides the `pull` value of every provision step. Valid values: [%s, %s, %s]", pullpolicy.Always, pullpolicy.IfNotExist, pullpolicy.Never))
runCmd.Flags().StringVarP(&user, "user", "u", "root", "Remote user for ssh session")
runCmd.Flags().BoolVarP(&vncEnabled, "vnc", "", false, "whether to configure VNC (remote GUI access) for the VM (defaults to false)")
runCmd.Flags().IntVar(&vncPort, "vnc-port", 0, "VNC port. Defaults to 6000+id of this VM")
Expand Down
3 changes: 1 addition & 2 deletions internal/virter/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ func (v *Virter) VMCommit(ctx context.Context, afterNotifier AfterNotifier, vmNa
// We want these IDs to be unique, so reset to empty.
err = v.VMExecShell(
ctx, []string{vmName},
&ProvisionShellStep{Script: "truncate -c -s 0 /etc/machine-id"})

&ProvisionShellStep{Script: "CMD='truncate -c -s 0 /etc/machine-id'; [ \"$(id -u)\" -eq 0 ] && $CMD || { ESC=$(command -v sudo || command -v doas || command -v please || echo ''); $ESC $CMD; }"})
if err != nil {
return err
}
Expand Down

0 comments on commit 4634be3

Please sign in to comment.