Skip to content

Commit

Permalink
refactor: improve artifact copy for artifact service
Browse files Browse the repository at this point in the history
  • Loading branch information
aweris committed Dec 15, 2023
1 parent 5eb971c commit 69cd116
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions actions/artifacts/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"context"
"fmt"
"time"
)

func New() *ActionsArtifactService {
Expand Down Expand Up @@ -74,14 +74,27 @@ func (m *ActionsArtifactService) Artifacts(
// run id of the workflow run to get artifacts for. If not provided, all artifacts saved in the cache will be returned.
runID string,
) *Directory {
var (
cache = m.Data
opts = ContainerWithMountedCacheOpts{Sharing: Shared}
copySH = fmt.Sprintf("if [ -d /artifacts/%s ]; then cp -r /artifacts/%s /exported_artifacts; else mkdir /exported_artifacts; fi", runID, runID)
)
copySH := `#!/bin/sh
echo "Copying artifacts for runID: $1"
if [ -d /artifacts/$1/ ]; then
echo "Copying artifacts for runID: $1"
cp -av /artifacts/$1/ /exported_artifacts/
else
echo "Artifacts for runID: $1 not found"
# list of run ids currently in the cache to help with debugging
echo "List of run ids in the cache:"
ls -la /artifacts/
mkdir -p /exported_artifacts
fi
`

return dag.Container().From("alpine:latest").
WithMountedCache("/artifacts", cache, opts).
WithExec([]string{"sh", "-c", copySH}).
WithMountedCache("/artifacts", m.Data, ContainerWithMountedCacheOpts{Sharing: Shared}).
WithNewFile("/usr/local/bin/copy-artifacts.sh", ContainerWithNewFileOpts{Contents: copySH, Permissions: 0700}).
WithExec([]string{"copy-artifacts.sh", runID, time.Now().Format(time.RFC3339Nano)}). // current time just to ensure exec is not cached.
Directory("/exported_artifacts")
}

0 comments on commit 69cd116

Please sign in to comment.