Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change latest flag behavior #483

Merged
merged 6 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- New cli flag --distributed for running cluster with Charon distributed validator

### Changed
- Override `--latest` flag to not use the latest version of the image in the clients if image is specified

## [v1.7.2] - 2024-11-12

### Fixed
Expand Down
55 changes: 47 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,15 @@ 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 if tc.genData.ConsensusClient.Name == "nimbus" {
assert.True(t, strings.HasSuffix(named.String(), ":multiarch-latest"))
} 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 +481,15 @@ 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 if tc.genData.ValidatorClient.Name == "nimbus" {
assert.True(t, strings.HasSuffix(named.String(), ":multiarch-latest"))
} 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:], ":")
executionOpClient.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
15 changes: 11 additions & 4 deletions internal/pkg/generate/generate_scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,17 @@ 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 {
splits := strings.Split(cls.Image, ":")
splits[len(splits)-1] = "latest"
return strings.Join(splits, ":")
if latest && !cls.Modified {
if cls.Name == "nimbus" {
splits := strings.Split(cls.Image, ":")
splits[len(splits)-1] = "multiarch-latest"
return strings.Join(splits, ":")

} else {
splits := strings.Split(cls.Image, ":")
splits[len(splits)-1] = "latest"
return strings.Join(splits, ":")
}
}
return cls.Image
}
Expand Down
Loading