Merged in feature/dockerfileintest (pull request #130)

Dockerfile in Test

* dockerfile

* network

* const
This commit is contained in:
Michael McGuinness
2025-05-03 11:29:10 +00:00
parent dd2eebf13a
commit 721ca8a6e6
27 changed files with 83 additions and 110 deletions
+18 -16
View File
@@ -13,8 +13,10 @@ import (
"queryorchestration/internal/serviceconfig"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/archive"
"github.com/docker/go-connections/nat"
"github.com/gruntwork-io/terratest/modules/shell"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
@@ -43,7 +45,7 @@ var (
imageBuild sync.Once
)
func buildImage(t testing.TB) {
func buildImage(t testing.TB, ctx context.Context) {
imageBuild.Do(func() {
dockerContextPath, err := os.Getwd()
require.NoError(t, err, "Failed to get current directory")
@@ -54,25 +56,25 @@ func buildImage(t testing.TB) {
candidatePath := filepath.Join(dockerContextPath, dockerfilePath)
t.Logf("Checking for Dockerfile at: %s", dockerContextPath)
if _, err := os.Stat(candidatePath); err == nil {
dockerfilePath = candidatePath
t.Logf("Found Dockerfile at: %s", candidatePath)
_, err := os.Stat(candidatePath)
if err == nil {
break
}
dockerContextPath = filepath.Join(dockerContextPath, "..")
}
dockerBuildCmd := shell.Command{
Command: "docker",
Args: []string{
"build",
"--file", dockerfilePath,
"--tag", imageTag,
dockerContextPath,
},
}
err = shell.RunCommandE(t, dockerBuildCmd)
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
require.NoError(t, err)
buildContext, err := archive.TarWithOptions(dockerContextPath, &archive.TarOptions{})
require.NoError(t, err)
defer buildContext.Close()
_, err = cli.ImageBuild(ctx, buildContext, types.ImageBuildOptions{
Dockerfile: dockerfilePath,
Tags: []string{imageTag},
})
require.NoError(t, err)
})
}
@@ -111,7 +113,7 @@ func createContainer(t testing.TB, ctx context.Context, network string, cfg *con
env[string(GetRunnerEnvFromName(e))] = GetQueueURL(t, cfg.Cfg, e)
}
buildImage(t)
buildImage(t, ctx)
req := testcontainers.ContainerRequest{
Image: imageTag,