Skip to content

Commit

Permalink
Adding new function to check a full docker image path exists
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosroman committed Nov 28, 2024
1 parent 4cb277f commit 4a49cfb
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 11 deletions.
2 changes: 2 additions & 0 deletions common/config/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ type CloudEnv interface {
InternalRegistry() string
// InternalRegistryImageTagExists returns true if the image tag exists in the internal registry.
InternalRegistryImageTagExists(image, tag string) (bool, error)
// InternalRegistryFullImagePathExists returns true if the image and tag exists in the internal registry.
InternalRegistryFullImagePathExists(fullImagePath string) (bool, error)
}

func NewCommonEnvironment(ctx *pulumi.Context) (CommonEnvironment, error) {
Expand Down
10 changes: 10 additions & 0 deletions components/datadog/agent/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,18 @@ func NewDockerAgent(e config.Env, vm *remoteComp.Host, manager *docker.Manager,
if err != nil {
return err
}

defaultAgentParams(params)

// Check FullImagePath exists in internal registry
exists, err := e.InternalRegistryFullImagePathExists(params.FullImagePath)
if err != nil {
return err
}
if !exists {
return fmt.Errorf("image %q not found in the internal registry", params.FullImagePath)
}

// We can have multiple compose files in compose.
composeContents := []docker.ComposeInlineManifest{dockerAgentComposeManifest(params.FullImagePath, e.AgentAPIKey(), params.AgentServiceEnvironment)}
composeContents = append(composeContents, params.ExtraComposeManifests...)
Expand Down
15 changes: 4 additions & 11 deletions components/datadog/dockeragentparams/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,10 @@ func NewParams(e config.Env, options ...Option) (*Params, error) {
}

if e.PipelineID() != "" && e.CommitSHA() != "" {
baseTag := fmt.Sprintf("%s-%s", e.PipelineID(), e.CommitSHA())
for _, tag := range []string{baseTag, fmt.Sprintf("%s-jmx", baseTag)} {
exists, err := e.InternalRegistryImageTagExists(fmt.Sprintf("%s/agent", e.InternalRegistry()), tag)
if err != nil {
return nil, err
}
if !exists {
return nil, fmt.Errorf("image %s/agent:%s not found in the internal registry", e.InternalRegistry(), tag)
}
}
options = append(options, WithFullImagePath(utils.BuildDockerImagePath("669783387624.dkr.ecr.us-east-1.amazonaws.com/agent", baseTag)))
options = append(options,
WithFullImagePath(utils.BuildDockerImagePath(
"669783387624.dkr.ecr.us-east-1.amazonaws.com/agent",
fmt.Sprintf("%s-%s", e.PipelineID(), e.CommitSHA()))))
}

return common.ApplyOption(version, options)
Expand Down
16 changes: 16 additions & 0 deletions resources/aws/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ func (e *Environment) InternalRegistryImageTagExists(image, tag string) (bool, e
return true, nil
}

func (e *Environment) InternalRegistryFullImagePathExists(fullImagePath string) (bool, error) {
var image, tag string
lastColonIdx := strings.LastIndex(fullImagePath, ":")
if lastColonIdx > 0 &&
lastColonIdx < len(fullImagePath) &&
// Check not part of registry address (e.g., "registry:5000/image")
!strings.Contains(fullImagePath[:lastColonIdx], "/") {
image = fullImagePath[:lastColonIdx]
tag = fullImagePath[lastColonIdx+1:]
} else {
image = fullImagePath
tag = "latest"
}
return e.InternalRegistryImageTagExists(image, tag)
}

// Common
func (e *Environment) Region() string {
return e.GetStringWithDefault(e.awsConfig, awsRegionParamName, e.envDefault.aws.region)
Expand Down
4 changes: 4 additions & 0 deletions resources/azure/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (e *Environment) InternalRegistryImageTagExists(_, _ string) (bool, error)
return true, nil
}

func (e *Environment) InternalRegistryFullImagePathExists(_ string) (bool, error) {
return true, nil
}

// Common

func (e *Environment) DefaultSubscriptionID() string {
Expand Down
4 changes: 4 additions & 0 deletions resources/gcp/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ func (e *Environment) InternalRegistryImageTagExists(_, _ string) (bool, error)
return true, nil
}

func (e *Environment) InternalRegistryFullImagePathExists(_ string) (bool, error) {
return true, nil
}

// Common

func (e *Environment) DefaultPublicKeyPath() string {
Expand Down
4 changes: 4 additions & 0 deletions resources/hyperv/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (e *Environment) InternalRegistryImageTagExists(_, _ string) (bool, error)
return true, nil
}

func (e *Environment) InternalRegistryFullImagePathExists(_ string) (bool, error) {
return true, nil
}

// Common
func (e *Environment) DefaultPublicKeyPath() string {
return e.InfraConfig.Get(DDInfraDefaultPublicKeyPath)
Expand Down
5 changes: 5 additions & 0 deletions resources/local/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func (e *Environment) InternalRegistryImageTagExists(_, _ string) (bool, error)
return true, nil
}

// InternalRegistryFullImagePathExists returns true if the image and tag exists in the internal registry.
func (e *Environment) InternalRegistryFullImagePathExists(_ string) (bool, error) {
return true, nil
}

// Common
func (e *Environment) DefaultPublicKeyPath() string {
return e.InfraConfig.Get(DDInfraDefaultPublicKeyPath)
Expand Down

0 comments on commit 4a49cfb

Please sign in to comment.