Skip to content

Commit

Permalink
refactor: improve artifact copy for artifact service (#198)
Browse files Browse the repository at this point in the history
* chore: add warning message for native docker

* chore: add warning message for native docker

* refactor: improve artifact copy for artifact service
  • Loading branch information
aweris authored Dec 15, 2023
1 parent 449392f commit d6f1073
Show file tree
Hide file tree
Showing 3 changed files with 27 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")
}
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func (g *Gale) Run(
log.Warnf("Both enableDocker and useDind are enabled. Using DinD to run docker commands.")
}

if useNativeDocker {
log.Warnf("Using native docker support. Please ensure that DOCKER_HOST is set correctly.", "DOCKER_HOST", dockerHost)
}

if useDind {
log.Warnf("Enabling DinD may lead to longer execution times.")
}
Expand Down
2 changes: 2 additions & 0 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func (r *Runner) Container(runID string) (*RunnerContainer, error) {
ctr = ctr.WithEnvVariable("DOCKER_HOST", "unix:///var/run/docker.sock")
case strings.HasPrefix(r.RunnerOpts.DockerHost, "tcp://"):
ctr = ctr.WithEnvVariable("DOCKER_HOST", r.RunnerOpts.DockerHost)
default:
return nil, fmt.Errorf("unsupported docker host: %s", r.RunnerOpts.DockerHost)
}
}

Expand Down

0 comments on commit d6f1073

Please sign in to comment.