run with copy of workingdir

This commit is contained in:
Casey Lee
2020-02-24 17:48:21 -08:00
parent 8f5918942d
commit 1121f6e132
7 changed files with 26 additions and 9 deletions

View File

@@ -101,6 +101,7 @@ func (cr *containerReference) Copy(destPath string, files ...*FileEntry) common.
func (cr *containerReference) CopyDir(destPath string, srcPath string) common.Executor {
return common.NewPipelineExecutor(
common.NewInfoExecutor("%sdocker cp src=%s dst=%s", logPrefix, srcPath, destPath),
cr.connect(),
cr.find(),
cr.copyDir(destPath, srcPath),
@@ -310,13 +311,14 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string) common.Exe
}
log.Debugf("Writing tarball %s from %s", tarFile.Name(), srcPath)
defer tarFile.Close()
//defer os.Remove(tarFile.Name())
defer os.Remove(tarFile.Name())
tw := tar.NewWriter(tarFile)
srcPrefix := filepath.Dir(srcPath)
if !strings.HasSuffix(srcPrefix, string(filepath.Separator)) {
srcPrefix += string(filepath.Separator)
}
log.Debugf("Stripping prefix:%s src:%s", srcPrefix, srcPath)
err = filepath.Walk(srcPath, func(file string, fi os.FileInfo, err error) error {
if err != nil {
@@ -336,6 +338,7 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string) common.Exe
// update the name to correctly reflect the desired destination when untaring
header.Name = strings.TrimPrefix(file, srcPrefix)
log.Debugf("%s -> %s", file, header.Name)
// write the header
if err := tw.WriteHeader(header); err != nil {

View File

@@ -82,6 +82,13 @@ func (rc *RunContext) startJobContainer() common.Executor {
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", "/toolcache"))
binds := []string{
fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"),
}
if rc.Config.BindWorkdir {
binds = append(binds, fmt.Sprintf("%s:%s%s", rc.Config.Workdir, "/github/workspace", bindModifiers))
}
rc.JobContainer = container.NewContainer(&container.NewContainerInput{
Cmd: nil,
Entrypoint: []string{"/usr/bin/tail", "-f", "/dev/null"},
@@ -95,10 +102,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
"act-actions": "/actions",
},
Binds: []string{
fmt.Sprintf("%s:%s%s", rc.Config.Workdir, "/github/workspace", bindModifiers),
fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"),
},
Binds: binds,
Stdout: logWriter,
Stderr: logWriter,
})
@@ -108,6 +112,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
rc.JobContainer.Remove().IfBool(!rc.Config.ReuseContainers),
rc.JobContainer.Create(),
rc.JobContainer.Start(false),
rc.JobContainer.CopyDir("/github/workspace", rc.Config.Workdir+"/.").IfBool(!rc.Config.BindWorkdir),
rc.JobContainer.Copy("/github/", &container.FileEntry{
Name: "workflow/event.json",
Mode: 644,

View File

@@ -18,6 +18,7 @@ type Runner interface {
// Config contains the config for a new runner
type Config struct {
Workdir string // path to working directory
BindWorkdir bool // bind the workdir to the job container
EventName string // name of event to run
EventPath string // path to JSON file to use for event.json in containers
ReuseContainers bool // reuse containers to maintain state

View File

@@ -160,6 +160,13 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [
envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", "/toolcache"))
binds := []string{
fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"),
}
if rc.Config.BindWorkdir {
binds = append(binds, fmt.Sprintf("%s:%s%s", rc.Config.Workdir, "/github/workspace", bindModifiers))
}
stepContainer := container.NewContainer(&container.NewContainerInput{
Cmd: cmd,
Entrypoint: entrypoint,
@@ -172,10 +179,7 @@ func (sc *StepContext) newStepContainer(ctx context.Context, image string, cmd [
"act-toolcache": "/toolcache",
"act-actions": "/actions",
},
Binds: []string{
fmt.Sprintf("%s:%s%s", rc.Config.Workdir, "/github/workspace", bindModifiers),
fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"),
},
Binds: binds,
Stdout: logWriter,
Stderr: logWriter,
})

View File

@@ -5,6 +5,7 @@ jobs:
check:
runs-on: ubuntu-latest
steps:
- run: ls
- run: echo 'hello world'
- run: echo ${GITHUB_SHA} >> /github/sha.txt
- run: cat /github/sha.txt | grep ${GITHUB_SHA}