Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 9 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
55 changes: 55 additions & 0 deletions packages/cli/internal/pkg/cli/workflow/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type runProps struct {
path string
packPath string
workflowUrl string
manifestPath string
inputsPath string
input Input
optionFileUrl string
Expand Down Expand Up @@ -118,6 +119,12 @@ type workflowOutputProps struct {
workflowRunLogOutputs map[string]interface{}
}

type ManifestProps struct {
MainWorkFlowURL string `json:"mainWorkFlowURL"`
InputFileURLs []string `json:"inputFileURLs"`
EngineOptions string `json:"engineOptions"`
}

type Manager struct {
Project storage.ProjectClient
Config storage.ConfigClient
Expand Down Expand Up @@ -311,6 +318,12 @@ func (m *Manager) uploadWorkflowToS3() {
if m.err != nil {
return
}
log.Debug().Msgf("copying %s to temp directory", m.path)
err := copyFileRecursivelyToLocation("temp", m.path)
if err != nil {
m.err = err
return
}
objectKey := fmt.Sprintf("%s/%s", m.baseWorkflowKey, workflowZip)
log.Debug().Msgf("updloading '%s' to 's3://%s/%s", m.packPath, m.bucketName, objectKey)
m.err = m.S3.UploadFile(m.bucketName, objectKey, m.packPath)
Expand Down Expand Up @@ -348,6 +361,37 @@ func (m *Manager) parseInputToArguments() {
m.arguments = []string{arguments}
}

// writeTempManifest writes the inputsFile included in the command line to the temporary MANIFEST.json located in temp directory
// This function is only called if there is a path included in the command line with the --inputsFile flag
func (m *Manager) writeTempManifest() {
if m.err != nil || m.inputsPath == "" {
return
}
m.manifestPath = filepath.Join("temp", "MANIFEST.json")
log.Debug().Msgf("Reading %s", m.manifestPath)
bytes, err := m.Storage.ReadAsBytes(m.manifestPath)
if err != nil {
m.err = err
return
}
var data ManifestProps
if err := json.Unmarshal(bytes, &data); err != nil {
m.err = err
return
}
data.InputFileURLs = append(data.InputFileURLs, m.inputsPath)
bytes, err = json.Marshal(data)
if err != nil {
m.err = err
return
}
err = m.Storage.WriteFromBytes(m.manifestPath, bytes)
if err != nil {
m.err = err
return
}
}

func (m *Manager) uploadInputsToS3() {
if m.err != nil || m.input == nil {
return
Expand Down Expand Up @@ -526,6 +570,16 @@ func (m *Manager) saveAttachments() {
}
}

func (m *Manager) removeTempManifest() {
log.Debug().Msgf("removing temp directory")
err := removeAll("temp")
if err != nil {
log.Warn().Msgf("Failed to remove temp directory")
m.err = err
return
}
}

func (m *Manager) cleanUpAttachments() {
for _, attachment := range m.attachments {
log.Debug().Msgf("cleaning up '%s'", attachment)
Expand All @@ -534,6 +588,7 @@ func (m *Manager) cleanUpAttachments() {
log.Warn().Msgf("Failed to clean up temporary file '%s': %s", attachment, err)
}
}
m.removeTempManifest()
}

func (m *Manager) runWorkflow() {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/internal/pkg/cli/workflow/workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (m *Manager) RunWorkflow(contextName, workflowName, inputsFileUrl string, o
}
m.calculateFinalLocation()
m.readInput(inputsFileUrl)
m.writeTempManifest()
m.uploadInputsToS3()
m.parseInputToArguments()
m.readOptionFile(optionFileUrl)
Expand Down
Loading