mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-10 19:50:30 +00:00
Previously the E2E test suite covered only RunnerSet. This refactors the existing E2E test code to extract the common test structure into a `env` struct and its methods, and use it to write two very similar tests, one for RunnerSet and another for RunnerDeployment.
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package testing
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os/exec"
|
|
"path/filepath"
|
|
|
|
"github.com/actions-runner-controller/actions-runner-controller/testing/runtime"
|
|
)
|
|
|
|
type Docker struct {
|
|
runtime.Cmdr
|
|
}
|
|
|
|
type DockerBuild struct {
|
|
Dockerfile string
|
|
Args []BuildArg
|
|
Image ContainerImage
|
|
}
|
|
|
|
type BuildArg struct {
|
|
Name, Value string
|
|
}
|
|
|
|
func (k *Docker) Build(ctx context.Context, builds []DockerBuild) error {
|
|
for _, build := range builds {
|
|
var args []string
|
|
args = append(args, "--build-arg=TARGETPLATFORM="+"linux/amd64")
|
|
for _, buildArg := range build.Args {
|
|
args = append(args, "--build-arg="+buildArg.Name+"="+buildArg.Value)
|
|
}
|
|
_, err := k.CombinedOutput(k.dockerBuildCmd(ctx, build.Dockerfile, build.Image.Repo, build.Image.Tag, args))
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("failed building %v: %w", build, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (k *Docker) dockerBuildCmd(ctx context.Context, dockerfile, repo, tag string, args []string) *exec.Cmd {
|
|
buildContext := filepath.Dir(dockerfile)
|
|
args = append([]string{"build", "--tag", repo + ":" + tag, "-f", dockerfile, buildContext}, args...)
|
|
|
|
cmd := exec.CommandContext(ctx, "docker", args...)
|
|
return cmd
|
|
}
|