Skip to content

Commit

Permalink
fix: make k8s store service files match docker (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
h4ck3rk3y committed Jun 9, 2023
1 parent d2b951c commit dc2d8cb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/kurtosis-tech/stacktrace"
"io"
apiv1 "k8s.io/api/core/v1"
"path/filepath"
)

const (
Expand Down Expand Up @@ -55,9 +56,17 @@ func CopyFilesFromUserService(
)
}

// we remove trailing slash
srcPath = filepath.Clean(srcPath)
// we get the base dir | file
srcPathBase := filepath.Base(srcPath)
// we get the dir that holds base the dir | file
srcPathDir := filepath.Dir(srcPath)

commandToRun := fmt.Sprintf(
`if command -v 'tar' > /dev/null; then tar cf - '%v'; else echo "Cannot copy files from path '%v' because the tar binary doesn't exist on the machine" >&2; exit 1; fi`,
srcPath,
`if command -v 'tar' > /dev/null; then cd '%v' && tar cf - '%v'; else echo "Cannot copy files from path '%v' because the tar binary doesn't exist on the machine" >&2; exit 1; fi`,
srcPathDir,
srcPathBase,
srcPath,
)
shWrappedCommandToRun := []string{
Expand Down
Expand Up @@ -18,9 +18,10 @@ const (
serviceName = "example-datastore-server-1"
serviceIdForDependentService = "example-datastore-server-2"
portId = "grpc"
fileToBeCreated = "/tmp/foo"
filePathOnDataStoreService = "/tmp/foo/"
fileToBeCreated = filePathOnDataStoreService + "doo.txt"
mountPathOnDependentService = "/tmp/doo"
pathToCheckOnDependentService = mountPathOnDependentService + "/foo"
pathToCheckOnDependentService = mountPathOnDependentService + "/foo/doo.txt"
renderedConfigMountPath = "/config"
renderedConfigRelativePath = "foo/bar.yml"
renderedConfigFile = renderedConfigMountPath + "/" + renderedConfigRelativePath
Expand All @@ -31,6 +32,7 @@ DATASTORE_SERVICE_NAME = "` + serviceName + `"
DATASTORE_PORT_ID = "` + portId + `"
DATASTORE_PORT_NUMBER = 1323
DATASTORE_PORT_PROTOCOL = "TCP"
DIR_OF_FILE_TO_BE_CREATED = "` + filePathOnDataStoreService + `"
FILE_TO_BE_CREATED = "` + fileToBeCreated + `"
SERVICE_DEPENDENT_ON_DATASTORE_SERVICE = "` + serviceIdForDependentService + `"
Expand All @@ -53,14 +55,20 @@ def run(plan, args):
result = plan.add_service(name = DATASTORE_SERVICE_NAME, config = config)
plan.print("Service " + result.name + " deployed successfully.")
plan.exec(
recipe = ExecRecipe(
command = ["mkdir", DIR_OF_FILE_TO_BE_CREATED],
),
service_name = DATASTORE_SERVICE_NAME,
)
plan.exec(
recipe = ExecRecipe(
command = ["touch", FILE_TO_BE_CREATED],
),
service_name = DATASTORE_SERVICE_NAME,
)
artifact_name = plan.store_service_files(name = "stored-file", service_name = DATASTORE_SERVICE_NAME, src = FILE_TO_BE_CREATED)
artifact_name = plan.store_service_files(name = "stored-file", service_name = DATASTORE_SERVICE_NAME, src = DIR_OF_FILE_TO_BE_CREATED)
plan.print("Stored file at " + artifact_name)
template_str = read_file(TEMPLATE_FILE_TO_RENDER)
Expand Down Expand Up @@ -119,6 +127,7 @@ Adding service example-datastore-server-1.
Service 'example-datastore-server-1' added with service UUID '[a-z-0-9]+'
Service example-datastore-server-1 deployed successfully.
Command returned with exit code '0' with no output
Command returned with exit code '0' with no output
Files with artifact name 'stored-file' uploaded with artifact UUID '[a-f0-9]{32}'
Stored file at stored-file
Templates artifact name 'rendered-file' rendered with artifact UUID '[a-f0-9]{32}'
Expand Down

0 comments on commit dc2d8cb

Please sign in to comment.