Skip to content

Commit 4634be3

Browse files
authored
If 'truncate' fails for /etc/machine-id during 'commit', attempt with '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.
1 parent 5276691 commit 4634be3

File tree

4 files changed

+4
-5
lines changed

4 files changed

+4
-5
lines changed

cmd/image_build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func imageBuildCommand() *cobra.Command {
280280
buildCmd.Flags().BoolVar(&resetMachineID, "reset-machine-id", true, "Whether or not to clear the /etc/machine-id file after provisioning")
281281
buildCmd.Flags().VarP(&vmPullPolicy, "pull-policy", "", "Whether or not to pull the source image.")
282282
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))
283-
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))
283+
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))
284284
buildCmd.Flags().BoolVarP(&push, "push", "", false, "Push the image after building")
285285
buildCmd.Flags().BoolVarP(&noCache, "no-cache", "", false, "Disable caching for the image build")
286286
buildCmd.Flags().StringVarP(&buildId, "build-id", "", "", "Build ID used to determine if an image needs to be rebuild.")

cmd/vm_exec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func vmExecCommand() *cobra.Command {
6464

6565
execCmd.Flags().VarP(&provFile, "provision", "p", "name of toml file containing provisioning steps")
6666
execCmd.Flags().StringArrayVarP(&provisionOverrides, "set", "s", []string{}, "set/override provisioning steps")
67-
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))
67+
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))
6868

6969
return execCmd
7070
}

cmd/vm_run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func vmRunCommand() *cobra.Command {
308308

309309
runCmd.Flags().VarP(&vmPullPolicy, "pull-policy", "", "Whether or not to pull the source image.")
310310
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))
311-
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))
311+
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))
312312
runCmd.Flags().StringVarP(&user, "user", "u", "root", "Remote user for ssh session")
313313
runCmd.Flags().BoolVarP(&vncEnabled, "vnc", "", false, "whether to configure VNC (remote GUI access) for the VM (defaults to false)")
314314
runCmd.Flags().IntVar(&vncPort, "vnc-port", 0, "VNC port. Defaults to 6000+id of this VM")

internal/virter/vm.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,7 @@ func (v *Virter) VMCommit(ctx context.Context, afterNotifier AfterNotifier, vmNa
476476
// We want these IDs to be unique, so reset to empty.
477477
err = v.VMExecShell(
478478
ctx, []string{vmName},
479-
&ProvisionShellStep{Script: "truncate -c -s 0 /etc/machine-id"})
480-
479+
&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; }"})
481480
if err != nil {
482481
return err
483482
}

0 commit comments

Comments
 (0)