diff --git a/components/command/osCommand.go b/components/command/osCommand.go index 155adcda8..bfad1350c 100644 --- a/components/command/osCommand.go +++ b/components/command/osCommand.go @@ -1,6 +1,7 @@ package command import ( + "runtime" "strings" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" @@ -88,3 +89,11 @@ func copyRemoteFile( Triggers: pulumi.Array{createCommand, deleteCommand, pulumi.BoolPtr(useSudo)}, }, opts...) } + +func NewLocalOSCommand() OSCommand { + if runtime.GOOS == "windows" { + return NewWindowsOSCommand() + } else { + return NewUnixOSCommand() + } +} diff --git a/components/command/runner.go b/components/command/runner.go index 599ec7548..0505e031e 100644 --- a/components/command/runner.go +++ b/components/command/runner.go @@ -278,7 +278,7 @@ func (r *LocalRunner) PulumiOptions() []pulumi.ResourceOption { func (r *LocalRunner) CopyWindowsFile(name string, src, dst pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error) { createCmd := pulumi.Sprintf("Copy-Item -Path '%v' -Destination '%v'", src, dst) deleteCmd := pulumi.Sprintf("Remove-Item -Path '%v'", dst) - useSudo := false // TODO A + useSudo := false return r.Command(name, &Args{ @@ -292,7 +292,7 @@ func (r *LocalRunner) CopyWindowsFile(name string, src, dst pulumi.StringInput, func (r *LocalRunner) CopyUnixFile(name string, src, dst pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error) { createCmd := pulumi.Sprintf("cp '%v' '%v'", src, dst) deleteCmd := pulumi.Sprintf("rm '%v'", dst) - useSudo := false // TODO A + useSudo := false return r.Command(name, &Args{ diff --git a/components/command/unixOSCommand.go b/components/command/unixOSCommand.go index 58a313a35..6013501e4 100644 --- a/components/command/unixOSCommand.go +++ b/components/command/unixOSCommand.go @@ -97,8 +97,8 @@ func formatCommandIfNeeded(command pulumi.StringInput, sudo bool, password bool, func (fs unixOSCommand) MoveRemoteFile(runner Runner, name string, source, destination pulumi.StringInput, sudo bool, opts ...pulumi.ResourceOption) (Command, error) { backupPath := pulumi.Sprintf("%v.%s", destination, backupExtension) - copyCommand := pulumi.Sprintf(`cp '%v' '%v'`, source, destination) - createCommand := pulumi.Sprintf(`bash -c 'if [ -f '%v' ]; then mv -f '%v' '%v'; fi; %v'`, destination, destination, backupPath, copyCommand) - deleteCommand := pulumi.Sprintf(`bash -c 'if [ -f '%v' ]; then mv -f '%v' '%v'; else rm -f '%v'; fi'`, backupPath, backupPath, destination, destination) + copyCommand := pulumi.Sprintf(`cp "%v" "%v"`, source, destination) + createCommand := pulumi.Sprintf(`bash -c 'if [ -f "%v" ]; then mv -f "%v" "%v"; fi; %v'`, destination, destination, backupPath, copyCommand) + deleteCommand := pulumi.Sprintf(`bash -c 'if [ -f "%v" ]; then mv -f "%v" "%v"; else rm -f "%v"; fi'`, backupPath, backupPath, destination, destination) return copyRemoteFile(runner, fmt.Sprintf("move-file-%s", name), createCommand, deleteCommand, sudo, utils.MergeOptions(opts, pulumi.ReplaceOnChanges([]string{"*"}), pulumi.DeleteBeforeReplace(true))...) } diff --git a/components/command/windowsOSCommand.go b/components/command/windowsOSCommand.go index 8c20a4362..bdbaaf09e 100644 --- a/components/command/windowsOSCommand.go +++ b/components/command/windowsOSCommand.go @@ -83,8 +83,8 @@ func (fs windowsOSCommand) NewCopyFile(runner Runner, name string, localPath, re func (fs windowsOSCommand) MoveRemoteFile(runner Runner, name string, source, destination pulumi.StringInput, sudo bool, opts ...pulumi.ResourceOption) (Command, error) { backupPath := pulumi.Sprintf("%v.%s", destination, backupExtension) - copyCommand := pulumi.Sprintf(`Copy-Item -Path %v -Destination %v`, source, destination) - createCommand := pulumi.Sprintf(`if (Test-Path %v) { Move-Item -Force -Path %v -Destination %v }; %v`, destination, destination, backupPath, copyCommand) - deleteCommand := pulumi.Sprintf(`if (Test-Path %v) { Move-Item -Force -Path %v -Destination %v } else { Remove-Item -Force -Path %v }`, backupPath, backupPath, destination, destination) + copyCommand := pulumi.Sprintf(`Copy-Item -Path '%v' -Destination '%v'`, source, destination) + createCommand := pulumi.Sprintf(`if (Test-Path '%v') { Move-Item -Force -Path '%v' -Destination '%v' }; %v`, destination, destination, backupPath, copyCommand) + deleteCommand := pulumi.Sprintf(`if (Test-Path '%v') { Move-Item -Force -Path '%v' -Destination '%v' } else { Remove-Item -Force -Path %v }`, backupPath, backupPath, destination, destination) return copyRemoteFile(runner, fmt.Sprintf("move-file-%s", name), createCommand, deleteCommand, sudo, utils.MergeOptions(opts, pulumi.ReplaceOnChanges([]string{"*"}), pulumi.DeleteBeforeReplace(true))...) } diff --git a/resources/local/podman/vm.go b/resources/local/podman/vm.go index 706fb758a..8f823ef3f 100644 --- a/resources/local/podman/vm.go +++ b/resources/local/podman/vm.go @@ -4,7 +4,6 @@ import ( _ "embed" "os" "path" - "runtime" "github.com/DataDog/test-infra-definitions/common/utils" "github.com/DataDog/test-infra-definitions/components/command" @@ -22,13 +21,7 @@ var dockerfileContent string var customDockerConfig = "{}" func NewInstance(e resourceslocal.Environment, args VMArgs, opts ...pulumi.ResourceOption) (address pulumi.StringOutput, user string, port int, err error) { - var osCommand command.OSCommand - if runtime.GOOS == "windows" { - osCommand = command.NewWindowsOSCommand() - } else { - osCommand = command.NewUnixOSCommand() - } - runner := command.NewLocalRunner(&e, command.LocalRunnerArgs{OSCommand: osCommand}) + runner := command.NewLocalRunner(&e, command.LocalRunnerArgs{OSCommand: command.NewLocalOSCommand()}) fileManager := command.NewFileManager(runner) publicKey, err := os.ReadFile(e.DefaultPublicKeyPath())