mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-11 03:57:01 +00:00
e2e: Cover RunnerDeployment (#668)
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.
This commit is contained in:
49
testing/docker.go
Normal file
49
testing/docker.go
Normal file
@@ -0,0 +1,49 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user