Skip to content

Commit a663089

Browse files
committed
use docker cmd instead of testcontainers-go
1 parent dc944c3 commit a663089

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

framework/components/clnode/clnode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
259259
}
260260
if req.Image == "" {
261261
req.Image = TmpImageName
262-
if err := framework.BuildImageOnce(ctx, once, in.Node.DockerContext, in.Node.DockerFilePath, req.Image); err != nil {
262+
if err := framework.BuildImageOnce(once, in.Node.DockerContext, in.Node.DockerFilePath, req.Image); err != nil {
263263
return nil, err
264264
}
265265
req.KeepImage = false

framework/docker.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"bytes"
66
"context"
77
"encoding/binary"
8-
"errors"
98
"fmt"
109
"github.com/docker/docker/api/types/container"
1110
"github.com/docker/docker/client"
@@ -15,6 +14,7 @@ import (
1514
"golang.org/x/sync/errgroup"
1615
"io"
1716
"os"
17+
"os/exec"
1818
"path/filepath"
1919
"strings"
2020
"sync"
@@ -69,6 +69,14 @@ func DefaultTCName(name string) string {
6969
return fmt.Sprintf("%s-%s", name, uuid.NewString()[0:5])
7070
}
7171

72+
// runCommand executes a command and prints the output.
73+
func runCommand(name string, args ...string) error {
74+
cmd := exec.Command(name, args...)
75+
cmd.Stdout = os.Stdout
76+
cmd.Stderr = os.Stderr
77+
return cmd.Run()
78+
}
79+
7280
// DockerClient wraps a Docker API client and provides convenience methods
7381
type DockerClient struct {
7482
cli *client.Client
@@ -242,29 +250,19 @@ func WriteAllContainersLogs() error {
242250
return eg.Wait()
243251
}
244252

245-
func BuildImageOnce(ctx context.Context, once *sync.Once, dctx, dfile, nameAndTag string) error {
246-
var (
247-
p *tc.DockerProvider
248-
dockerCtx string
249-
err error
250-
)
253+
func BuildImageOnce(once *sync.Once, dctx, dfile, nameAndTag string) error {
254+
var err error
251255
once.Do(func() {
252-
nt := strings.Split(nameAndTag, ":")
253-
if len(nt) != 2 {
254-
err = errors.New("BuildImageOnce, tag must be in 'repo:tag' format")
255-
return
256+
dfilePath := filepath.Join(dctx, dfile)
257+
err = runCommand("docker", "build", "-t", nameAndTag, "-f", dfilePath, dctx)
258+
if err != nil {
259+
err = fmt.Errorf("failed to build Docker image: %w", err)
256260
}
257-
p, err = tc.NewDockerProvider()
258-
dockerCtx, err = filepath.Abs(dctx)
259-
_, err = p.BuildImage(ctx, &tc.ContainerRequest{
260-
FromDockerfile: tc.FromDockerfile{
261-
Repo: nt[0],
262-
Tag: nt[1],
263-
Context: dockerCtx,
264-
Dockerfile: dfile,
265-
PrintBuildLog: true,
266-
},
267-
})
268261
})
269262
return err
270263
}
264+
265+
func BuildImage(dctx, dfile, nameAndTag string) error {
266+
dfilePath := filepath.Join(dctx, dfile)
267+
return runCommand("docker", "build", "-t", nameAndTag, "-f", dfilePath, dctx)
268+
}

0 commit comments

Comments
 (0)