Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

Commit

Permalink
experimental symlink support
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Feb 21, 2020
1 parent 0e3e72a commit b6719f2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Config struct {
EnvFile string `envconfig:"DRONE_RUNNER_ENVFILE"`
Path string `envconfig:"DRONE_RUNNER_PATH"`
Root string `envconfig:"DRONE_RUNNER_ROOT"`
Symlinks map[string]string `envconfig:"DRONE_RUNNER_SYMLINKS"`
}

Limit struct {
Expand Down
1 change: 1 addition & 0 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func Run(ctx context.Context, config Config) error {
Environ: config.Runner.Environ,
Machine: config.Runner.Name,
Root: config.Runner.Root,
Symlinks: config.Runner.Symlinks,
Reporter: tracer,
Match: match.Func(
config.Limit.Repos,
Expand Down
15 changes: 14 additions & 1 deletion engine/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ type Compiler struct {
// into the pipeline step.
Secret secret.Provider

// Root defines the option build root path, defaults to temp directory.
// Root defines the optional build root path, defaults to
// temp directory.
Root string

// Symlinks provides an optional list of symlinks that are
// created and linked to the pipeline workspace.
Symlinks map[string]string
}

// Compile compiles the configuration file.
Expand Down Expand Up @@ -140,6 +145,14 @@ func (c *Compiler) Compile(ctx context.Context) *engine.Spec {
})
}

// create symbolic links
for source, target := range c.Symlinks {
spec.Links = append(spec.Links, &engine.Link{
Source: source,
Target: filepath.Join(spec.Root, target),
})
}

// create the default environment variables.
envs := environ.Combine(
hostEnviron(),
Expand Down
12 changes: 12 additions & 0 deletions engine/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ func (e *engine) Setup(ctx context.Context, spec *Spec) error {
}
}

// create symlinks
for _, link := range spec.Links {
if err := os.Symlink(link.Source, link.Target); err != nil {
logger.FromContext(ctx).
WithError(err).
WithField("source", link.Source).
WithField("target", link.Target).
Error("cannot create symlink")
return err
}
}

// creates step files
for _, step := range spec.Steps {
for _, file := range step.Files {
Expand Down
7 changes: 7 additions & 0 deletions engine/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type (
Platform Platform `json:"platform,omitempty"`
Root string `json:"root,omitempty"`
Files []*File `json:"files,omitempty"`
Links []*Link `json:"links,omitempty"`
Steps []*Step `json:"steps,omitempty"`
}

Expand Down Expand Up @@ -43,6 +44,12 @@ type (
IsDir bool `json:"is_dir,omitempty"`
}

// Link defines a symbolic link.
Link struct {
Source string `json:"source,omitempty"`
Target string `json:"target,omitempty"`
}

// Platform defines the target platform.
Platform struct {
OS string `json:"os,omitempty"`
Expand Down
8 changes: 7 additions & 1 deletion runtime/runner.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b6719f2

Please sign in to comment.