Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Mar 21, 2024
1 parent 9456750 commit b1df3c7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,13 +555,12 @@ func createStartServiceOperation(
envVars[key] = strings.Replace(envVars[key], privateIPAddrPlaceholder, privateIPAddrStr, unlimitedReplacements)
}

// THIS IS A HACK
// TODO clean this up
// TODO clean this hack up
// this path will only be hit if `files_to_be_moved` is set in Starlark; which is a hidden property
// used by compose transpilation
if len(filesToBeMoved) > 0 {
var err error
cmdArgs, entrypointArgs, err = handleFilesToBeMovedForDockerCompose(ctx, dockerManager, containerImageName, cmdArgs, entrypointArgs, filesToBeMoved)
cmdArgs, entrypointArgs, err = getUpdatedEntrypointAndCmdFromFilesToBeMoved(ctx, dockerManager, containerImageName, cmdArgs, entrypointArgs, filesToBeMoved)
if err != nil {
return nil, stacktrace.Propagate(err, "an error occurred while handling files for compose")
}
Expand Down Expand Up @@ -769,15 +768,15 @@ func createStartServiceOperation(
}

// TODO - clean this up this is super janky, a way to handle compose & volume
func handleFilesToBeMovedForDockerCompose(ctx context.Context, dockerManager *docker_manager.DockerManager, containerImageName string, cmdArgs []string, entrypointArgs []string, filesToBeMoved map[string]string) ([]string, []string, error) {
func getUpdatedEntrypointAndCmdFromFilesToBeMoved(ctx context.Context, dockerManager *docker_manager.DockerManager, containerImageName string, cmdArgs []string, entrypointArgs []string, filesToBeMoved map[string]string) ([]string, []string, error) {
concatenatedFilesToBeMoved := []string{}
for source, destination := range filesToBeMoved {
// TODO improve this; the first condition handles files the other folders
concatenatedFilesToBeMoved = append(concatenatedFilesToBeMoved, fmt.Sprintf("mv %v %v", source, destination))
}

concatenatedFilesToBeMovedAsStr := strings.Join(concatenatedFilesToBeMoved, " && ")
originalEntrypointArgs, originalCmdArgs, err := dockerManager.GetOriginalEntryPointAndCommand(ctx, containerImageName)
originalEntrypointArgs, originalCmdArgs, err := dockerManager.GetEntryPointAndCommand(ctx, containerImageName)
if err != nil {
return nil, nil, stacktrace.Propagate(err, "an error occurred fetching data about image '%v'", containerImageName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ func (manager *DockerManager) getImagePlatform(ctx context.Context, imageName st
return imageInspect.Architecture, nil
}

func (manager *DockerManager) GetOriginalEntryPointAndCommand(ctx context.Context, imageName string) ([]string, []string, error) {
func (manager *DockerManager) GetEntryPointAndCommand(ctx context.Context, imageName string) ([]string, []string, error) {
imageInspect, _, err := manager.dockerClient.ImageInspectWithRaw(ctx, imageName)
if err != nil {
return nil, nil, stacktrace.Propagate(err, "an error occurred while running image inspect on image '%v'", imageName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (t *serviceConfigFullTestCase) GetStarlarkCode() string {
fileArtifact1 := fmt.Sprintf("%s(%s=[%q])", directory.DirectoryTypeName, directory.ArtifactNamesAttr, testFilesArtifactName1)
fileArtifact2 := fmt.Sprintf("%s(%s=[%q])", directory.DirectoryTypeName, directory.ArtifactNamesAttr, testFilesArtifactName2)
persistentDirectory := fmt.Sprintf("%s(%s=%q)", directory.DirectoryTypeName, directory.PersistentKeyAttr, testPersistentDirectoryKey)
starlarkCode := fmt.Sprintf("%s(%s=%q, %s=%s, %s=%s, %s=%s, %s=%s, %s=%s, %s=%s, %s=%q, %s=%d, %s=%d, %s=%d, %s=%d, %s=%s, %s=%v, %s=%v, files_to_be_moved={\"/foo/bar\": \"/doo/dar\"})",
starlarkCode := fmt.Sprintf("%s(%s=%q, %s=%s, %s=%s, %s=%s, %s=%s, %s=%s, %s=%s, %s=%q, %s=%d, %s=%d, %s=%d, %s=%d, %s=%s, %s=%v, %s=%v, %s=%v)",
service_config.ServiceConfigTypeName,
service_config.ImageAttr, testContainerImageName,
service_config.PortsAttr, fmt.Sprintf("{%q: PortSpec(number=%d, transport_protocol=%q, application_protocol=%q, wait=%q)}", testPrivatePortId, testPrivatePortNumber, testPrivatePortProtocolStr, testPrivateApplicationProtocol, testWaitConfiguration),
Expand All @@ -56,7 +56,8 @@ func (t *serviceConfigFullTestCase) GetStarlarkCode() string {
service_config.ReadyConditionsAttr,
getDefaultReadyConditionsScriptPart(),
service_config.LabelsAttr, fmt.Sprintf("{%q: %q, %q: %q}", testServiceConfigLabelsKey1, testServiceConfigLabelsValue1, testServiceConfigLabelsKey2, testServiceConfigLabelsValue2),
service_config.NodeSelectorsAttr, fmt.Sprintf("{%q: %q}", testNodeSelectorKey1, testNodeSelectorValue1))
service_config.NodeSelectorsAttr, fmt.Sprintf("{%q: %q}", testNodeSelectorKey1, testNodeSelectorValue1),
service_config.FilesToBeMovedAttr, fmt.Sprintf("{%q: %q}", testFilesToBeMoved, testFilesToBeMoved))
return starlarkCode
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,6 @@ var (
testTolerationKey = "test-key"
testTolerationValue = "test-value"
testTolerationSeconds = int64(64)

testFilesToBeMoved = "test.txt"
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"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_registry_spec"
"github.com/sirupsen/logrus"
"math"
"path"

Expand Down Expand Up @@ -520,13 +519,11 @@ func (config *ServiceConfig) ToKurtosisType(
return nil, interpretationErr
}
if found && filesToBeMovedStarlark.Len() > 0 {
logrus.Info("this is confusing")
filesToBeMoved, interpretationErr = kurtosis_types.SafeCastToMapStringString(filesToBeMovedStarlark, FilesToBeMovedAttr)
if interpretationErr != nil {
return nil, interpretationErr
}
}
logrus.Infof("the attribute is '%v'", filesToBeMoved)

serviceConfig, err := service.CreateServiceConfig(
imageName,
Expand Down

0 comments on commit b1df3c7

Please sign in to comment.