Skip to content

Commit

Permalink
Merge branch 'main' of github.com:DataDog/test-infra-definitions into…
Browse files Browse the repository at this point in the history
… kfairise/fix-filepath-join-windows
  • Loading branch information
KevinFairise2 committed Jan 10, 2025
2 parents e889e4f + 9f38bc4 commit 7617c58
Show file tree
Hide file tree
Showing 69 changed files with 827 additions and 493 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
uses: docker/build-push-action@b32b51a8eda65d6793cd0494a773d4f6bcef32dc
with:
context: components/datadog/apps/${{ matrix.app }}/images/${{ matrix.image }}
platforms: linux/amd64,linux/arm64
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ Pulumi.*.yaml
# Build files
dist/main
mem.pprof

# Python cache files
**/__pycache__/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Adapted from https://github.com/pulumi/pulumi-docker-containers/blob/main/docker/pulumi/Dockerfile
# to minimize image size

FROM public.ecr.aws/docker/library/python:3.13-slim-bullseye AS base
FROM public.ecr.aws/docker/library/python:3.12-slim-bullseye AS base

ENV GO_VERSION=1.23.3
ENV GO_SHA=a0afb9744c00648bafb1b90b4aba5bdb86f424f02f9275399ce0c20b93a2c3a8
Expand Down
10 changes: 10 additions & 0 deletions common/config/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const (
DDAgentSite = "site"
DDAgentMajorVersion = "majorVersion"
DDAgentExtraEnvVars = "extraEnvVars" // extraEnvVars is expected in the format: <key1>=<value1>,<key2>=<value2>,...
DDAgentJMX = "jmx"
DDAgentFIPS = "fips"

// Updater Namespace
DDUpdaterParamName = "deploy"
Expand Down Expand Up @@ -430,3 +432,11 @@ func (e *CommonEnvironment) GetIntWithDefault(config *sdkconfig.Config, paramNam

return defaultValue
}

func (e *CommonEnvironment) AgentFIPS() bool {
return e.GetBoolWithDefault(e.AgentConfig, DDAgentFIPS, false)
}

func (e *CommonEnvironment) AgentJMX() bool {
return e.GetBoolWithDefault(e.AgentConfig, DDAgentJMX, false)
}
5 changes: 2 additions & 3 deletions components/activedirectory/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package activedirectory
import (
"github.com/DataDog/test-infra-definitions/common/utils"
"github.com/DataDog/test-infra-definitions/components/command"
pulumiRemote "github.com/pulumi/pulumi-command/sdk/go/command/remote"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumiverse/pulumi-time/sdk/go/time"
)
Expand Down Expand Up @@ -49,7 +48,7 @@ func WithDomain(domainFqdn, domainAdmin, domainAdminPassword string) Option {
}

func (adCtx *activeDirectoryContext) joinActiveDirectoryDomain(params *JoinDomainConfiguration) error {
var joinCmd *pulumiRemote.Command
var joinCmd command.Command
joinCmd, err := adCtx.comp.host.OS.Runner().Command(adCtx.comp.namer.ResourceName("join-domain"), &command.Args{
Create: pulumi.Sprintf(`
Add-Computer -DomainName %s -Credential (New-Object System.Management.Automation.PSCredential -ArgumentList %s, %s)
Expand Down Expand Up @@ -90,7 +89,7 @@ func WithDomainController(domainFqdn, adminPassword string) func(*Configuration)
}

func (adCtx *activeDirectoryContext) installDomainController(params *DomainControllerConfiguration) error {
var installCmd *pulumiRemote.Command
var installCmd command.Command
installCmd, err := adCtx.comp.host.OS.Runner().Command(adCtx.comp.namer.ResourceName("install-forest"), &command.Args{
Create: pulumi.Sprintf(`
Add-WindowsFeature -name ad-domain-services -IncludeManagementTools;
Expand Down
19 changes: 9 additions & 10 deletions components/command/filemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ import (
"runtime"
"strings"

"github.com/pulumi/pulumi-command/sdk/go/command/remote"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

type FileManager struct {
runner *Runner
runner Runner
command OSCommand
}

func NewFileManager(runner *Runner) *FileManager {
func NewFileManager(runner Runner) *FileManager {
return &FileManager{
runner: runner,
command: runner.osCommand,
command: runner.OsCommand(),
}
}

Expand All @@ -31,26 +30,26 @@ func (fm *FileManager) IsPathAbsolute(path string) bool {
}

// CreateDirectoryFromPulumiString if it does not exist from directory name as a Pulumi String
func (fm *FileManager) CreateDirectoryFromPulumiString(name string, remotePath pulumi.String, useSudo bool, opts ...pulumi.ResourceOption) (*remote.Command, error) {
func (fm *FileManager) CreateDirectoryFromPulumiString(name string, remotePath pulumi.String, useSudo bool, opts ...pulumi.ResourceOption) (Command, error) {
return fm.command.CreateDirectory(fm.runner, name, remotePath, useSudo, opts...)
}

// CreateDirectoryForFile if the directory does not exist
// To avoid pulumi.URN collisions if multiple files use the same directory, use the full filePath as URN and path.Split out the folderPath for creation
func (fm *FileManager) CreateDirectoryForFile(remotePath string, useSudo bool, opts ...pulumi.ResourceOption) (*remote.Command, error) {
func (fm *FileManager) CreateDirectoryForFile(remotePath string, useSudo bool, opts ...pulumi.ResourceOption) (Command, error) {
// if given just a directory path, path.Split returns "" as file
// eg. path.Split("/a/b/c/") -> "/a/b/c/", ""
folderPath, _ := path.Split(remotePath)
return fm.command.CreateDirectory(fm.runner, "create-directory-"+remotePath, pulumi.String(folderPath), useSudo, opts...)
}

// CreateDirectory if it does not exist
func (fm *FileManager) CreateDirectory(remotePath string, useSudo bool, opts ...pulumi.ResourceOption) (*remote.Command, error) {
func (fm *FileManager) CreateDirectory(remotePath string, useSudo bool, opts ...pulumi.ResourceOption) (Command, error) {
return fm.command.CreateDirectory(fm.runner, "create-directory-"+remotePath, pulumi.String(remotePath), useSudo, opts...)
}

// TempDirectory creates a temporary directory
func (fm *FileManager) TempDirectory(folderName string, opts ...pulumi.ResourceOption) (*remote.Command, string, error) {
func (fm *FileManager) TempDirectory(folderName string, opts ...pulumi.ResourceOption) (Command, string, error) {
tempDir := path.Join(fm.command.GetTemporaryDirectory(), folderName)
folderCmd, err := fm.CreateDirectory(tempDir, false, opts...)
return folderCmd, tempDir, err
Expand All @@ -59,14 +58,14 @@ func (fm *FileManager) TempDirectory(folderName string, opts ...pulumi.ResourceO
// HomeDirectory creates a directory in home directory, if it does not exist
// A home directory is a file system directory on a multi-user operating system containing files for a given user of the system.
// It does not require sudo, using sudo in home directory allows to change default ownership and it is discouraged.
func (fm *FileManager) HomeDirectory(folderName string, opts ...pulumi.ResourceOption) (*remote.Command, string, error) {
func (fm *FileManager) HomeDirectory(folderName string, opts ...pulumi.ResourceOption) (Command, string, error) {
homeDir := path.Join(fm.command.GetHomeDirectory(), folderName)
folderCmd, err := fm.CreateDirectory(homeDir, false, opts...)
return folderCmd, homeDir, err
}

func (fm *FileManager) CopyFile(name string, localPath, remotePath pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error) {
return fm.runner.NewCopyFile(name, localPath, remotePath, opts...)
return fm.runner.newCopyFile(name, localPath, remotePath, opts...)
}

func (fm *FileManager) CopyInlineFile(fileContent pulumi.StringInput, remotePath string, opts ...pulumi.ResourceOption) (pulumi.Resource, error) {
Expand Down
27 changes: 19 additions & 8 deletions components/command/osCommand.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package command

import (
"runtime"
"strings"

"github.com/pulumi/pulumi-command/sdk/go/command/remote"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

Expand All @@ -13,11 +13,12 @@ type OSCommand interface {
GetHomeDirectory() string

CreateDirectory(
runner *Runner,
runner Runner,
resourceName string,
remotePath pulumi.StringInput,
useSudo bool,
opts ...pulumi.ResourceOption) (*remote.Command, error)
opts ...pulumi.ResourceOption) (Command, error)
MoveFile(runner Runner, name string, source, destination pulumi.StringInput, sudo bool, opts ...pulumi.ResourceOption) (Command, error)

BuildCommandString(
command pulumi.StringInput,
Expand All @@ -29,7 +30,9 @@ type OSCommand interface {
IsPathAbsolute(path string) bool
PathJoin(parts ...string) string

NewCopyFile(runner *Runner, name string, localPath, remotePath pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error)
NewCopyFile(runner Runner, name string, localPath, remotePath pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error)
copyLocalFile(runner *LocalRunner, name string, src, dst pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error)
copyRemoteFile(runner *RemoteRunner, name string, src, dst pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error)
}

// ------------------------------
Expand All @@ -39,13 +42,13 @@ type OSCommand interface {
const backupExtension = "pulumi.backup"

func createDirectory(
runner *Runner,
runner Runner,
name string,
createCmd string,
deleteCmd string,
useSudo bool,
opts ...pulumi.ResourceOption,
) (*remote.Command, error) {
) (Command, error) {
// If the folder was previously created, make sure to delete it before creating it.
opts = append(opts, pulumi.DeleteBeforeReplace(true))
return runner.Command(name,
Expand Down Expand Up @@ -73,13 +76,13 @@ func buildCommandString(
}

func copyRemoteFile(
runner *Runner,
runner Runner,
name string,
createCommand pulumi.StringInput,
deleteCommand pulumi.StringInput,
useSudo bool,
opts ...pulumi.ResourceOption,
) (*remote.Command, error) {
) (Command, error) {
return runner.Command(name,
&Args{
Create: createCommand,
Expand All @@ -88,3 +91,11 @@ func copyRemoteFile(
Triggers: pulumi.Array{createCommand, deleteCommand, pulumi.BoolPtr(useSudo)},
}, opts...)
}

func NewLocalOSCommand() OSCommand {
if runtime.GOOS == "windows" {
return NewWindowsOSCommand()
}

return NewUnixOSCommand()
}
17 changes: 8 additions & 9 deletions components/command/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@ import (

"github.com/DataDog/test-infra-definitions/common/namer"
"github.com/DataDog/test-infra-definitions/common/utils"
"github.com/pulumi/pulumi-command/sdk/go/command/remote"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

type GenericPackageManager struct {
namer namer.Namer
updateDBCommand *remote.Command
runner *Runner
updateDBCommand Command
runner Runner
opts []pulumi.ResourceOption
installCmd string
updateCmd string
env pulumi.StringMap
}

func NewGenericPackageManager(
runner *Runner,
runner Runner,
name string,
installCmd string,
updateCmd string,
env pulumi.StringMap,
) *GenericPackageManager {
packageManager := &GenericPackageManager{
namer: namer.NewNamer(runner.e.Ctx(), name),
namer: namer.NewNamer(runner.Environment().Ctx(), name),
runner: runner,
installCmd: installCmd,
updateCmd: updateCmd,
Expand All @@ -37,7 +36,7 @@ func NewGenericPackageManager(
return packageManager
}

func (m *GenericPackageManager) Ensure(packageRef string, transform Transformer, checkBinary string, opts ...pulumi.ResourceOption) (*remote.Command, error) {
func (m *GenericPackageManager) Ensure(packageRef string, transform Transformer, checkBinary string, opts ...pulumi.ResourceOption) (Command, error) {
opts = append(opts, m.opts...)
if m.updateCmd != "" {
updateDB, err := m.updateDB(opts)
Expand All @@ -55,7 +54,7 @@ func (m *GenericPackageManager) Ensure(packageRef string, transform Transformer,
}

cmdName := m.namer.ResourceName("install-"+packageRef, utils.StrHash(cmdStr))
cmdArgs := Args{
var cmdArgs RunnerCommandArgs = &Args{
Create: pulumi.String(cmdStr),
Environment: m.env,
Sudo: true,
Expand All @@ -66,7 +65,7 @@ func (m *GenericPackageManager) Ensure(packageRef string, transform Transformer,
cmdName, cmdArgs = transform(cmdName, cmdArgs)
}

cmd, err := m.runner.Command(cmdName, &cmdArgs, opts...)
cmd, err := m.runner.Command(cmdName, cmdArgs, opts...)
if err != nil {
return nil, err
}
Expand All @@ -76,7 +75,7 @@ func (m *GenericPackageManager) Ensure(packageRef string, transform Transformer,
return cmd, nil
}

func (m *GenericPackageManager) updateDB(opts []pulumi.ResourceOption) (*remote.Command, error) {
func (m *GenericPackageManager) updateDB(opts []pulumi.ResourceOption) (Command, error) {
if m.updateDBCommand != nil {
return m.updateDBCommand, nil
}
Expand Down
Loading

0 comments on commit 7617c58

Please sign in to comment.