E2E: Use standalone Image Renderer for tests instead of plugin (#112266)

* E2E: Use standalone Image Renderer for tests instead of plugin

* E2E: Allow configuring image renderer version if needed

(cherry picked from commit 9a2a314dc9)
This commit is contained in:
Matheus Macabu
2025-11-06 10:49:44 +00:00
committed by github-actions[bot]
parent 3696a9aadf
commit dfe4d122fc
6 changed files with 59 additions and 18 deletions
+11 -3
View File
@@ -109,10 +109,15 @@ func NewCmd() *cli.Command {
},
&cli.BoolFlag{
Name: "image-renderer",
Usage: "Install the image renderer plugin (requires --start-grafana)",
Usage: "Start the image renderer Docker container (requires --start-grafana)",
Category: "Grafana Server",
},
&cli.StringFlag{
Name: "image-renderer-version",
Usage: "When enabling the image renderer, which version to use",
Value: "latest",
Category: "Grafana Server",
},
&cli.StringFlag{
Name: "suite",
Usage: "Path to the suite to run (e.g. './e2e/dashboards-suite')",
@@ -194,7 +199,10 @@ func runAction(ctx context.Context, c *cli.Command) error {
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("TZ=%s", c.String("timezone")))
if c.Bool("image-renderer") {
cmd.Env = append(cmd.Env, "INSTALL_IMAGE_RENDERER=true")
cmd.Env = append(cmd.Env, "START_IMAGE_RENDERER=true")
}
if c.String("image-renderer-version") != "" {
cmd.Env = append(cmd.Env, fmt.Sprintf("IMAGE_RENDERER_VERSION=%s", c.String("image-renderer-version")))
}
cmd.Stdout = prefixGrafana(os.Stdout)
cmd.Stderr = prefixGrafana(os.Stderr)
+9 -2
View File
@@ -62,9 +62,14 @@ func NewApp() *cli.Command {
},
&cli.BoolFlag{
Name: "image-renderer",
Usage: "Install the image renderer plugin",
Usage: "Enable the image renderer plugin",
Value: false,
},
&cli.StringFlag{
Name: "image-renderer-version",
Usage: "When enabling the image renderer, which version to use",
Value: "latest",
},
},
Action: run,
}
@@ -76,6 +81,7 @@ func run(ctx context.Context, cmd *cli.Command) error {
targzPath := cmd.String("package")
licensePath := cmd.String("license")
imageRenderer := cmd.Bool("image-renderer")
imageRendererVersion := cmd.String("image-renderer-version")
runnerFlags := cmd.String("flags")
d, err := dagger.Connect(ctx)
@@ -104,7 +110,8 @@ func run(ctx context.Context, cmd *cli.Command) error {
GrafanaTarGz: targz,
YarnCache: yarnCache,
License: license,
InstallImageRenderer: imageRenderer,
StartImageRenderer: imageRenderer,
ImageRendererVersion: imageRendererVersion,
})
if err != nil {
return fmt.Errorf("failed to create Grafana service: %w", err)
+8 -3
View File
@@ -27,7 +27,8 @@ type GrafanaServiceOpts struct {
GrafanaTarGz *dagger.File
YarnCache *dagger.CacheVolume
License *dagger.File
InstallImageRenderer bool
StartImageRenderer bool
ImageRendererVersion string
}
func Frontend(src *dagger.Directory) *dagger.Directory {
@@ -97,10 +98,14 @@ func GrafanaService(ctx context.Context, d *dagger.Client, opts GrafanaServiceOp
licenseArg = "/src/license.jwt"
}
if opts.InstallImageRenderer {
container = container.WithEnvVariable("INSTALL_IMAGE_RENDERER", "true").
if opts.StartImageRenderer {
container = container.WithEnvVariable("START_IMAGE_RENDERER", "true").
WithExec([]string{"apt-get", "update"}).
WithExec([]string{"apt-get", "install", "-y", "ca-certificates"})
if opts.ImageRendererVersion != "" {
container = container.WithEnvVariable("IMAGE_RENDERER_VERSION", opts.ImageRendererVersion)
}
}
// We add all GF_ environment variables to allow for overriding Grafana configuration.
+29 -9
View File
@@ -12,6 +12,8 @@ fi
./scripts/grafana-server/kill-server
docker ps -q --filter "name=grafana-image-renderer" | xargs docker stop || true
mkdir $RUNDIR
echo -e "Copying grafana backend files to temp dir..."
@@ -55,9 +57,17 @@ elif [ -d "../e2e-playwright/test-plugins" ]; then
cp -r "../e2e-playwright/test-plugins" "$RUNDIR/data/plugins"
fi
if [ "$INSTALL_IMAGE_RENDERER" ]; then
echo -e "Installing image renderer"
$RUNDIR/bin/"$ARCH"grafana cli --pluginsDir "$RUNDIR/data/plugins" plugins install grafana-image-renderer
if [ "$START_IMAGE_RENDERER" ]; then
echo -e "Starting image renderer container"
docker run -d --rm --name=grafana-image-renderer -p ${IR_DEFAULT_PORT}:${IR_DEFAULT_PORT} grafana/grafana-image-renderer:${IMAGE_RENDERER_VERSION:-latest}
if [[ "$(uname)" == "Darwin" ]]; then
DOCKER_HOST="host.docker.internal"
echo "Detected Mac host, using $DOCKER_HOST as the Docker host"
else
DOCKER_HOST="172.17.0.1"
echo "Detected Linux host, using $DOCKER_HOST as the Docker host"
fi
fi
echo -e "Copy provisioning setup from devenv"
@@ -74,10 +84,20 @@ echo -e "Starting Grafana server port $PORT"
# We get a lot of "context canceled" errors from navigating away from pages,
# so filter them out because they're not useful
{
exec "$RUNDIR/bin/${ARCH}grafana" server \
--homepath="$HOME_PATH" \
--pidfile="$RUNDIR/pid" \
cfg:server.http_port="$PORT" \
cfg:enterprise.license_path="$1" \
2>&1
CMD=(
"$RUNDIR/bin/${ARCH}grafana" server
--homepath="$HOME_PATH"
--pidfile="$RUNDIR/pid"
cfg:server.http_port="$PORT"
cfg:enterprise.license_path="$1"
)
if [ "$START_IMAGE_RENDERER" ]; then
CMD+=(
cfg:rendering.callback_url="http://$DOCKER_HOST:$PORT"
cfg:rendering.server_url="http://localhost:$IR_DEFAULT_PORT/render"
)
fi
exec "${CMD[@]}" 2>&1
} | grep -v -i "context canceled"
+1
View File
@@ -8,3 +8,4 @@ PIDFILE=$RUNDIR/pid
PROV_DIR=$RUNDIR/conf/provisioning
DEFAULT_HOST=localhost
DEFAULT_PORT=3001
IR_DEFAULT_PORT=8081
+1 -1
View File
@@ -8,7 +8,7 @@ PORT=${PORT:-$DEFAULT_PORT}
printf "Waiting for grafana-server to finish starting, host=%s, port=%s" "$HOST" "$PORT"
timeout=60
timeout=180
elapsed=0
while ! curl -s -f http://$HOST:$PORT/health > /dev/null 2>&1; do