Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/orchestrator/internal/template/build/commands/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/e2b-dev/infra/packages/orchestrator/internal/template/metadata"
templatemanager "github.com/e2b-dev/infra/packages/shared/pkg/grpc/template-manager"
"github.com/e2b-dev/infra/packages/shared/pkg/storage"
"github.com/e2b-dev/infra/packages/shared/pkg/utils"
)

type Copy struct {
Expand All @@ -35,11 +36,25 @@ type copyScriptData struct {
TargetPath string
Owner string
Permissions string

// Workdir is the working directory for the target path resolution if relative.
Workdir string
// User is used for filling the workdir if empty.
User string
}

var copyScriptTemplate = txtTemplate.Must(txtTemplate.New("copy-script-template").Parse(`
#!/bin/bash

workdir="{{ .Workdir }}"

# Fill the workdir with user home directory if empty
if [ -z "${workdir}" ]; then
# Use the owner's home directory
workdir=$(getent passwd "{{ .User }}" | cut -d: -f6)
fi
cd "$workdir"

# Get the parent folder of the source file/folder
sourceFolder="$(dirname "{{ .SourcePath}}")"

Expand Down Expand Up @@ -177,6 +192,9 @@ func (c *Copy) Execute(

var moveScript bytes.Buffer
err = copyScriptTemplate.Execute(&moveScript, copyScriptData{
Workdir: utils.DerefOrDefault(cmdMetadata.WorkDir, ""),
User: cmdMetadata.User,

SourcePath: filepath.Join(sbxUnpackPath, args.SourcePath),
TargetPath: args.TargetPath,
Owner: args.Owner,
Expand Down
Loading