Skip to content

Commit 7023af2

Browse files
authored
run: allow passing a custom version of the Docker image (#480)
By default, when using `boe run --docker`, the version of the BOE CLI will be used (if it is an officially released one), and fall back to `latest` otherwise. This change allows passing a command line flag to set the version of the Docker image to use. Signed-off-by: Ignasi Barrera <ignasi@tetrate.io>
1 parent 630a849 commit 7023af2

5 files changed

Lines changed: 36 additions & 7 deletions

File tree

cli/cmd/run.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type Run struct {
5454
TestUpstreamCluster string `name:"test-upstream-cluster" help:"Name of an existing configured cluster to use as the test upstream. The cluster must be configured via --cluster, --cluster-insecure, or --cluster-json. Mutually exclusive with --test-upstream-host."`
5555
Docker bool `help:"Run Envoy as a Docker container instead of using func-e." default:"false" env:"BOE_RUN_DOCKER"`
5656
Pull string `name:"pull" help:"Pull policy for the BOE Docker image (missing, always, never). Only applicable when running with --docker." enum:"missing,always,never" default:"missing"`
57+
DockerImageVersion string `name:"docker-image-version" help:"Override the BOE Docker image tag to use when running with --docker. By default, the image version matches the BOE version."`
5758
OCI OCIFlags `embed:""`
5859

5960
extensionPositions extensionPositions `kong:"-"` // Internal field: tracks the original position of extensions specified via both --extension and --local flags
@@ -103,6 +104,9 @@ func (r *Run) Validate() error {
103104
if r.EnvoyPath != "" && r.EnvoyVersion != "" {
104105
return fmt.Errorf("--envoy-path and --envoy-version are mutually exclusive")
105106
}
107+
if r.DockerImageVersion != "" && !r.Docker {
108+
return fmt.Errorf("--docker-image-version can only be used with --docker")
109+
}
106110
return nil
107111
}
108112

@@ -120,6 +124,7 @@ func (r *Run) Run(ctx context.Context, dirs *xdg.Directories, logger *slog.Logge
120124
Arch: runtime.GOARCH,
121125
LocalExtensions: r.Local,
122126
Pull: r.Pull,
127+
ImageVersion: r.DockerImageVersion,
123128
}
124129
return runner.Run(ctx)
125130
}

cli/cmd/run_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ Flags:
108108
--pull="missing" Pull policy for the BOE Docker image
109109
(missing, always, never). Only applicable
110110
when running with --docker.
111+
--docker-image-version=STRING
112+
Override the BOE Docker image tag to use
113+
when running with --docker. By default,
114+
the image version matches the BOE version.
111115
--registry="%s"
112116
OCI registry URL for the extensions
113117
($BOE_REGISTRY).
@@ -290,6 +294,14 @@ func TestRunValidateMutualExclusion(t *testing.T) {
290294
},
291295
expectedErr: "--envoy-path and --envoy-version are mutually exclusive",
292296
},
297+
{
298+
name: "docker image version without docker",
299+
run: Run{
300+
LogLevel: "all:error",
301+
DockerImageVersion: "custom-version",
302+
},
303+
expectedErr: "--docker-image-version can only be used with --docker",
304+
},
293305
}
294306

295307
for _, tt := range tests {

cli/internal/envoy/runner.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,13 @@ type RunnerDocker struct {
391391
Arch string
392392
LocalExtensions []string
393393
Pull string
394+
ImageVersion string
394395
}
395396

396397
// Run starts Envoy in a Docker container.
397398
func (r *RunnerDocker) Run(ctx context.Context) error {
398399
var (
399-
version = imageVersion(internal.CurrentVersion())
400+
version = imageVersion(internal.CurrentVersion(), r.ImageVersion)
400401
image = fmt.Sprintf("%s/%s:%s", r.Registry, dockerImage, version)
401402
)
402403

@@ -458,7 +459,10 @@ func (r *RunnerDocker) dockerRunArgs(image string, localExtArgs []string) []stri
458459

459460
// imageVersion returns the image version to use for the Docker runner. For dev versions, it returns "latest"
460461
// to pull the most recent image. For release versions, it returns the specific version tag to pull the corresponding image.
461-
func imageVersion(version internal.Version) string {
462+
func imageVersion(version internal.Version, requestedVersion string) string {
463+
if requestedVersion != "" {
464+
return requestedVersion
465+
}
462466
if version.CommitsAhead != 0 || version.ClosestTag == "" || version.Sha == "" {
463467
return "latest"
464468
}
@@ -525,6 +529,12 @@ func (r *RunnerDocker) processCommandArgs(args []string) []string {
525529
// Skip the --docker and --pull flags as they are only relevant to the host CLI
526530
// and should not be passed to the container.
527531
// Need to do prefix match not equality because flags could be in the form of --docker=true or --pull=always.
532+
533+
// Handle --docker-image-version value
534+
if arg == "--docker-image-version" && i+1 < len(args) {
535+
i++ // skip next arg (the value for --docker-image-version)
536+
continue
537+
}
528538
if strings.HasPrefix(arg, "--docker") {
529539
continue
530540
}

cli/internal/envoy/runner_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,10 @@ func TestPassthroughEnvVars(t *testing.T) {
357357
}
358358

359359
func TestImageVersion(t *testing.T) {
360-
require.Equal(t, "0.6.6", imageVersion(internal.Version{ClosestTag: "v0.6.6", Sha: "123"}))
361-
require.Equal(t, "latest", imageVersion(internal.CurrentVersion()))
362-
require.Equal(t, "latest", imageVersion(internal.Version{ClosestTag: "v0.6.6", CommitsAhead: 2, Sha: "123"}))
363-
require.Equal(t, "latest", imageVersion(internal.Version{Sha: "123"}))
364-
require.Equal(t, "latest", imageVersion(internal.Version{ClosestTag: "v0.6.6", CommitsAhead: 0}))
360+
require.Equal(t, "0.6.6", imageVersion(internal.Version{ClosestTag: "v0.6.6", Sha: "123"}, ""))
361+
require.Equal(t, "latest", imageVersion(internal.CurrentVersion(), ""))
362+
require.Equal(t, "latest", imageVersion(internal.Version{ClosestTag: "v0.6.6", CommitsAhead: 2, Sha: "123"}, ""))
363+
require.Equal(t, "latest", imageVersion(internal.Version{Sha: "123"}, ""))
364+
require.Equal(t, "latest", imageVersion(internal.Version{ClosestTag: "v0.6.6", CommitsAhead: 0}, ""))
365+
require.Equal(t, "custom-version", imageVersion(internal.CurrentVersion(), "custom-version"))
365366
}

website/src/pages/docs/cli/run.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ boe run --help
116116
| `--test-upstream-cluster` | Name of an existing configured cluster to use as the test upstream. The cluster must be configured via --cluster, --cluster-insecure, or --cluster-json. Mutually exclusive with --test-upstream-host. | `string` | - | - | No |
117117
| `--docker` | Run Envoy as a Docker container instead of using func-e. | `bool` | `false` | `BOE_RUN_DOCKER` | No |
118118
| `--pull` | Pull policy for the BOE Docker image (missing, always, never). Only applicable when running with --docker. | `string` | `missing` | - | No |
119+
| `--docker-image-version` | Override the BOE Docker image tag to use when running with --docker. By default, the image version matches the BOE version. | `string` | - | - | No |
119120
| `--registry` | OCI registry URL for the extensions. | `string` | `ghcr.io/tetratelabs/built-on-envoy` | `BOE_REGISTRY` | No |
120121
| `--insecure` | Allow connecting to an insecure (HTTP) registry. | `bool` | `false` | `BOE_REGISTRY_INSECURE` | No |
121122
| `--username` | Username for the OCI registry. | `string` | - | `BOE_REGISTRY_USERNAME` | No |

0 commit comments

Comments
 (0)