Skip to content

Commit

Permalink
fix: ImageBuildSpec build_file feature
Browse files Browse the repository at this point in the history
  • Loading branch information
leovct authored and tedim52 committed Mar 18, 2024
1 parent f9875de commit 686ab8d
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import (
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/concurrent_writer"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/image_utils"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/uuid_generator"
"github.com/kurtosis-tech/kurtosis/path-compression"
path_compression "github.com/kurtosis-tech/kurtosis/path-compression"
"github.com/kurtosis-tech/stacktrace"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -1408,6 +1408,7 @@ func (manager *DockerManager) BuildImage(ctx context.Context, imageName string,
}()
defer buildkitSession.Close() //nolint

buildFile := imageBuildSpec.GetBuildFile()
buildArgs := imageBuildSpec.GetBuildArgs()
buildArgsMapStringStringPtr := map[string]*string{}
for k, v := range buildArgs {
Expand All @@ -1433,7 +1434,7 @@ func (manager *DockerManager) BuildImage(ctx context.Context, imageName string,
CgroupParent: "",
NetworkMode: "",
ShmSize: 0,
Dockerfile: defaultContainerImageFile,
Dockerfile: buildFile,
Ulimits: []*units.Ulimit{},
BuildArgs: buildArgsMapStringStringPtr,
AuthConfigs: map[string]registry.AuthConfig{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ type privateImageBuildSpec struct {
//
TargetStage string

// Name of the build file
BuildFile string

// Dockerfile build args
BuildArgs map[string]string
}

func NewImageBuildSpec(contextDirPath string, containerImageFilePath string, targetStage string, buildArgs map[string]string) *ImageBuildSpec {
func NewImageBuildSpec(contextDirPath string, containerImageFilePath string, targetStage string, buildFile string, buildArgs map[string]string) *ImageBuildSpec {
internalImageBuildSpec := &privateImageBuildSpec{
ContainerImageFilePath: containerImageFilePath,
ContextDirPath: contextDirPath,
TargetStage: targetStage,
BuildFile: buildFile,
BuildArgs: buildArgs,
}
return &ImageBuildSpec{internalImageBuildSpec}
Expand All @@ -65,6 +69,10 @@ func (imageBuildSpec *ImageBuildSpec) GetTargetStage() string {
return imageBuildSpec.privateImageBuildSpec.TargetStage
}

func (imageBuildSpec *ImageBuildSpec) GetBuildFile() string {
return imageBuildSpec.privateImageBuildSpec.BuildFile
}

func (imageBuildSpec *ImageBuildSpec) GetBuildArgs() map[string]string {
return imageBuildSpec.privateImageBuildSpec.BuildArgs
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func testImageBuildSpec() *image_build_spec.ImageBuildSpec {
"test-image",
"path",
"",
"",
nil)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package test_engine

import (
"fmt"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_download_mode"
"testing"

"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_download_mode"

"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_build_spec"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/port_spec"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/service"
Expand Down Expand Up @@ -40,12 +41,14 @@ func (suite *KurtosisTypeConstructorTestSuite) TestServiceConfigWithImageBuildSp
}

func (t *serviceConfigImageBuildSpecTestCase) GetStarlarkCode() string {
imageBuildSpec := fmt.Sprintf("%s(%s=%q, %s=%q, %s=%q, %s=%s)",
imageBuildSpec := fmt.Sprintf("%s(%s=%q, %s=%q, %s=%q, %s=%q, %s=%s)",
service_config.ImageBuildSpecTypeName,
service_config.BuiltImageNameAttr,
testContainerImageName,
service_config.BuildContextAttr,
testBuildContextDir,
service_config.BuildFileAttr,
defaultBuildFile,
service_config.TargetStageAttr,
testTargetStage,
service_config.BuildArgsAttr,
Expand Down Expand Up @@ -76,6 +79,7 @@ func (t *serviceConfigImageBuildSpecTestCase) Assert(typeValue builtin_argument.
testOnDiskContextDirPath,
testOnDiskContainerImagePath,
testTargetStage,
defaultBuildFile,
expectedBuildArgs)
expectedServiceConfig, err := service.CreateServiceConfig(
testContainerImageName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ var (
testModuleFileName = "github.com/kurtosistech/test-package/helpers.star"
testModuleRelativeLocator = "./helpers.star"

testModuleAbsoluteLocator = startosis_packages.NewPackageAbsoluteLocator(testModuleFileName, "")

emptyAbsoluteLocator = startosis_packages.NewPackageAbsoluteLocator("", "")

testModuleAbsoluteLocator = startosis_packages.NewPackageAbsoluteLocator(testModuleFileName, "")
emptyAbsoluteLocator = startosis_packages.NewPackageAbsoluteLocator("", "")
testContainerImageName = "kurtosistech/example-datastore-server"
testBuildContextDir = "./"
testBuildFile = "foo.Dockerfile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (imageBuildSpec *ImageBuildSpec) ToKurtosisType(
return nil, interpretationErr
}

return image_build_spec.NewImageBuildSpec(buildContextDirPathOnDisk, containerImageFilePathOnDisk, targetStageStr, buildArgs), nil
return image_build_spec.NewImageBuildSpec(buildContextDirPathOnDisk, containerImageFilePathOnDisk, targetStageStr, buildFile, buildArgs), nil
}

// Returns the filepath of the build context directory and container image on APIC based on package info
Expand Down
13 changes: 12 additions & 1 deletion internal_testsuites/starlark/image-build-package/main.star
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def run(plan, args):
plan.add_service(
name="service",
name="service-1",
config=ServiceConfig(
image=ImageBuildSpec(
image_name="kurtosistech/service",
Expand All @@ -11,3 +11,14 @@ def run(plan, args):
),
)
)

plan.add_service(
name="service-2",
config=ServiceConfig(
image=ImageBuildSpec(
image_name="kurtosistech/service",
build_context_dir="./test",
build_file="test.Dockerfile",
)
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:latest

WORKDIR /app

COPY . .

CMD ["echo", "Hello, Kurtosis!"]

0 comments on commit 686ab8d

Please sign in to comment.