Skip to content

Commit 2a8fff6

Browse files
committed
simplify docker build logic
1 parent 4559cb5 commit 2a8fff6

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

framework/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@ This module includes the CTFv2 harness, a lightweight, modular, and data-driven
2828
| LOKI_URL | URL to `Loki` push api, should be like`${host}/loki/api/v1/push` | URL | - | If you use `Loki` then ✅ |
2929
| LOKI_TENANT_ID | Streams all components logs to `Loki`, see params below | `true`, `false` | - | If you use `Loki` then ✅ |
3030
| TESTCONTAINERS_RYUK_DISABLED | Testcontainers-Go reaper container, removes all the containers after the test exit | `true`, `false` | `false` | 🚫 |
31-
| CTF_BUILD_DOCKER_IMAGES | Rebuild and publish local docker images if there are changes | `true`, `false` | `false` | 🚫 |
3231
| RESTY_DEBUG | Log all Resty client HTTP calls | `true`, `false` | `false` | 🚫 |

framework/clclient/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func NewChainlinkClient(c *Config) (*ChainlinkClient, error) {
5757
}, nil
5858
}
5959

60-
// NewCLCDefaultlients connects all the clients using clnode.Output and default login/password
61-
func NewCLCDefaultlients(outs []*clnode.Output, l zerolog.Logger) ([]*ChainlinkClient, error) {
60+
// NewCLDefaultClients connects all the clients using clnode.Output and default login/password
61+
func NewCLDefaultClients(outs []*clnode.Output, l zerolog.Logger) ([]*ChainlinkClient, error) {
6262
clients := make([]*ChainlinkClient, 0)
6363
for _, out := range outs {
6464
c, err := NewChainlinkClient(&Config{

framework/components/clnode/clnode.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package clnode
33
import (
44
"bytes"
55
"context"
6+
"errors"
67
"fmt"
78
"github.com/docker/go-connections/nat"
89
"github.com/smartcontractkit/chainlink-testing-framework/framework"
@@ -217,12 +218,14 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
217218
})
218219
}
219220
req.Files = append(req.Files, files...)
220-
localImg, err := framework.RebuildDockerImage(once, in.Node.DockerFilePath, in.Node.DockerContext, in.Node.DockerImageName)
221-
if err != nil {
222-
return nil, err
223-
}
224-
if localImg != "" {
225-
req.Image = localImg
221+
if req.Image != "" && (in.Node.DockerFilePath != "" || in.Node.DockerContext != "" || in.Node.DockerImageName != "") {
222+
return nil, errors.New("you provided both 'image' and one of 'docker_file', 'docker_ctx', 'docker_image_name' fields. Please provide either 'image' or params to build a local one")
223+
}
224+
if req.Image == "" {
225+
req.Image, err = framework.RebuildDockerImage(once, in.Node.DockerFilePath, in.Node.DockerContext, in.Node.DockerImageName)
226+
if err != nil {
227+
return nil, err
228+
}
226229
}
227230
c, err := tc.GenericContainer(ctx, tc.GenericContainerRequest{
228231
ContainerRequest: req,

framework/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const (
2929
EnvVarTestConfigs = "CTF_CONFIGS"
3030
EnvVarLokiStream = "CTF_LOKI_STREAM"
3131
EnvVarAWSSecretsManager = "CTF_AWS_SECRETS_MANAGER"
32-
EnvVarDockerImagesBuild = "CTF_BUILD_DOCKER_IMAGES"
3332
// EnvVarCI this is a default env variable many CI runners use so code can detect we run in CI
3433
EnvVarCI = "CI"
3534
)

framework/docker.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ func DefaultTCName(name string) string {
5151
func BuildAndPublishLocalDockerImage(once *sync.Once, dockerfile string, buildContext string, imageName string) error {
5252
var retErr error
5353
once.Do(func() {
54+
L.Info().
55+
Str("Dockerfile", dockerfile).
56+
Str("Ctx", buildContext).
57+
Str("ImageName", imageName).
58+
Msg("Building local docker file")
5459
registryRunning := isContainerRunning("local-registry")
5560
if registryRunning {
5661
fmt.Println("Local registry container is already running.")
@@ -64,7 +69,6 @@ func BuildAndPublishLocalDockerImage(once *sync.Once, dockerfile string, buildCo
6469
}
6570

6671
img := fmt.Sprintf("localhost:5050/%s:latest", imageName)
67-
L.Info().Str("DockerFile", dockerfile).Str("Context", buildContext).Msg("Building Docker image")
6872
err := runCommand("docker", "build", "-t", fmt.Sprintf("localhost:5050/%s:latest", imageName), "-f", dockerfile, buildContext)
6973
if err != nil {
7074
retErr = fmt.Errorf("failed to build Docker image: %w", err)
@@ -102,7 +106,7 @@ func runCommand(name string, args ...string) error {
102106

103107
// RebuildDockerImage rebuilds docker image if necessary
104108
func RebuildDockerImage(once *sync.Once, dockerfile string, buildContext string, imageName string) (string, error) {
105-
if os.Getenv(EnvVarDockerImagesBuild) == "true" {
109+
if dockerfile != "" || buildContext != "" || imageName != "" {
106110
if dockerfile == "" {
107111
return "", errors.New("docker_file path must be provided")
108112
}

0 commit comments

Comments
 (0)