Skip to content

Commit

Permalink
feat: override latest tag if image is set
Browse files Browse the repository at this point in the history
  • Loading branch information
stdevMac committed Nov 29, 2024
1 parent 6e485d7 commit 9be726d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
51 changes: 43 additions & 8 deletions cli/actions/generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,39 @@ func TestGenerateDockerCompose(t *testing.T) {
},
},
genTestData{
name: fmt.Sprintf("execution: %s, consensus: %s, validator: %s, network: %s, no validator, with latest", executionCl, consensusCl, consensusCl, network),
name: fmt.Sprintf("execution: %s, consensus: %s, validator: %s, network: %s, no validator, with latest, execution has image specified", executionCl, consensusCl, consensusCl, network),
genData: generate.GenData{
ExecutionClient: &clients.Client{Name: executionCl, Type: "execution"},
ExecutionClient: &clients.Client{Name: executionCl, Type: "execution", Image: "execution/execution:1.1.1", Modified: true},
ConsensusClient: &clients.Client{Name: consensusCl, Type: "consensus"},
Services: []string{"execution", "consensus"},
Network: network,
ContainerTag: "sampleTag",
LatestVersion: true,
},
},
genTestData{
name: fmt.Sprintf("execution: %s, consensus: %s, validator: %s, network: %s, no validator, with latest, consensus has image specified", executionCl, consensusCl, consensusCl, network),
genData: generate.GenData{
ExecutionClient: &clients.Client{Name: executionCl, Type: "execution"},
ConsensusClient: &clients.Client{Name: consensusCl, Type: "consensus", Image: "consensus/consensus:1.1.1", Modified: true},
Services: []string{"execution", "consensus"},
Network: network,
ContainerTag: "sampleTag",
LatestVersion: true,
},
},
genTestData{
name: fmt.Sprintf("execution: %s, consensus: %s, validator: %s, network: %s, no validator, with latest, consensus and validator has image specified", executionCl, consensusCl, consensusCl, network),
genData: generate.GenData{
ExecutionClient: &clients.Client{Name: executionCl, Type: "execution"},
ConsensusClient: &clients.Client{Name: consensusCl, Type: "consensus", Image: "consensus/consensus:1.1.1", Modified: true},
ValidatorClient: &clients.Client{Name: consensusCl, Type: "validator", Image: "validator/validator:1.1.1", Modified: true},
Services: []string{"execution", "consensus", "validator"},
Network: network,
ContainerTag: "sampleTag",
LatestVersion: true,
},
},
)
}

Expand Down Expand Up @@ -350,9 +373,13 @@ func TestGenerateDockerCompose(t *testing.T) {
named, err := reference.ParseNormalizedNamed(ecImageVersion)
assert.NoError(t, err, "invalid image", ecImageVersion)

// Test that the execution image is set to latest if flag --latest is provided
// Test that the execution image is set to latest if flag --latest is provided, and the image is not modified
if tc.genData.LatestVersion {
assert.True(t, strings.HasSuffix(named.String(), ":latest"))
if tc.genData.ExecutionClient.Modified {
assert.True(t, strings.HasSuffix(named.String(), tc.genData.ExecutionClient.Image))
} else {
assert.True(t, strings.HasSuffix(named.String(), ":latest"))
}
}

// Check that mev-boost service is not set when execution only
Expand Down Expand Up @@ -387,9 +414,13 @@ func TestGenerateDockerCompose(t *testing.T) {
named, err := reference.ParseNormalizedNamed(ccImageVersion)
assert.NoError(t, err, "invalid image", ccImageVersion)

// Test that the consensus image is set to latest if flag --latest is provided
// Test that the consensus image is set to latest if flag --latest is provided, and the image is not modified
if tc.genData.LatestVersion {
assert.True(t, strings.HasSuffix(named.String(), ":latest"))
if tc.genData.ConsensusClient.Modified {
assert.True(t, strings.HasSuffix(named.String(), tc.genData.ConsensusClient.Image))
} else {
assert.True(t, strings.HasSuffix(named.String(), ":latest"))
}
}
// Validate Execution API and AUTH URLs
apiEndpoint, authEndpoint := envData["EC_API_URL"], envData["EC_AUTH_URL"]
Expand Down Expand Up @@ -448,9 +479,13 @@ func TestGenerateDockerCompose(t *testing.T) {
named, err := reference.ParseNormalizedNamed(vlImageVersion)
assert.NoError(t, err, "invalid image", vlImageVersion)

// Test that the consensus image is set to latest if flag --latest is provided
// Test that the consensus image is set to latest if flag --latest is provided, and the image is not modified
if tc.genData.LatestVersion {
assert.True(t, strings.HasSuffix(named.String(), ":latest"))
if tc.genData.ValidatorClient.Modified {
assert.True(t, strings.HasSuffix(named.String(), tc.genData.ValidatorClient.Image))
} else {
assert.True(t, strings.HasSuffix(named.String(), ":latest"))
}
}

// Check Consensus API URL is set and is valid
Expand Down
10 changes: 6 additions & 4 deletions cli/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func valClients(allClients clients.OrderedClients, flags *GenCmdFlags, services
if len(executionParts) > 1 {
log.Warn(configs.CustomExecutionImagesWarning)
executionClient.Image = strings.Join(executionParts[1:], ":")
flags.latestVersion = false
executionClient.Modified = true
}
}
executionClient.SetImageOrDefault(strings.Join(executionParts[1:], ":"))
Expand All @@ -425,7 +425,7 @@ func valClients(allClients clients.OrderedClients, flags *GenCmdFlags, services
if len(consensusParts) > 1 {
log.Warn(configs.CustomConsensusImagesWarning)
consensusClient.Image = strings.Join(consensusParts[1:], ":")
flags.latestVersion = false
consensusClient.Modified = true
}
}
consensusClient.SetImageOrDefault(strings.Join(consensusParts[1:], ":"))
Expand All @@ -447,8 +447,7 @@ func valClients(allClients clients.OrderedClients, flags *GenCmdFlags, services
if len(validatorParts) > 1 {
log.Warn(configs.CustomValidatorImagesWarning)
validatorClient.Image = strings.Join(validatorParts[1:], ":")
flags.latestVersion = false

validatorClient.Modified = true
}
}
validatorClient.SetImageOrDefault(strings.Join(validatorParts[1:], ":"))
Expand All @@ -469,6 +468,7 @@ func valClients(allClients clients.OrderedClients, flags *GenCmdFlags, services
opClient.Name = "opnode"
if len(optimismParts) > 1 {
opClient.Image = strings.Join(optimismParts[1:], ":")
opClient.Modified = true
}
}
opClient.SetImageOrDefault(strings.Join(optimismParts[1:], ":"))
Expand All @@ -485,6 +485,7 @@ func valClients(allClients clients.OrderedClients, flags *GenCmdFlags, services
executionOpClient.Name = strings.ReplaceAll(optimismExecutionParts[0], "-", "")
if len(optimismExecutionParts) > 1 {
executionOpClient.Image = strings.Join(optimismExecutionParts[1:], ":")
executionClient.Modified = true
}
}
executionOpClient.SetImageOrDefault(strings.Join(optimismExecutionParts[1:], ":"))
Expand All @@ -510,6 +511,7 @@ func valClients(allClients clients.OrderedClients, flags *GenCmdFlags, services
distributedValidatorClient.Name = distributedValidatorParts[0]
if len(distributedValidatorParts) > 1 {
distributedValidatorClient.Image = strings.Join(distributedValidatorParts[1:], ":")
distributedValidatorClient.Modified = true
}
distributedValidatorClient.SetImageOrDefault(strings.Join(distributedValidatorParts[1:], ":"))
} else {
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/clients/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Client struct {
Name string
Type string
Image string
Modified bool
Endpoint string
Supported bool
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/generate/generate_scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ func joinIfNotEmpty(strs ...string) string {
// imageOrEmpty returns the image of the client if it is not nil, otherwise returns an empty string
func imageOrEmpty(cls *clients.Client, latest bool) string {
if cls != nil {
if latest {
if latest && !cls.Modified {
splits := strings.Split(cls.Image, ":")
splits[len(splits)-1] = "latest"
return strings.Join(splits, ":")
Expand Down

0 comments on commit 9be726d

Please sign in to comment.