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

If 'truncate' fails for /etc/machine-id during 'commit', attempt with 'sudo' before giving up #31

Merged
merged 2 commits into from
Oct 30, 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
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
Loading