diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-01-06 23:34:43 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-01-06 23:45:08 +0900 |
| commit | 0df87ab1117bf4da5163ad486a82628f1bada7ed (patch) | |
| tree | 48745fe27c4c3694c1313bb9030188458fbdd328 /internal/pkg/exec.go | |
| parent | aa0a949cefd8c1a1519d892f87aac3119389e271 (diff) | |
internal/pkg: automatic overlay mount on tmp
This sets up the last Artifact to target /tmp as a writable overlay mount backed by the host side temp directory. This is useful for an Artifact containing source code to be built for another Artifact for example.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/exec.go')
| -rw-r--r-- | internal/pkg/exec.go | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/internal/pkg/exec.go b/internal/pkg/exec.go index c1e0cc34..8b12694f 100644 --- a/internal/pkg/exec.go +++ b/internal/pkg/exec.go @@ -89,7 +89,9 @@ func (a *execNetArtifact) Cure(c *CureContext) error { // A private instance of /proc and /dev is made available to the container. // // The working and temporary directories are both created and mounted writable -// on /work and /tmp respectively. +// on /work and /tmp respectively. If one or more paths target [fhs.AbsTmp], the +// final entry is set up as a writable overlay mount on /tmp backed by the host +// side temporary directory. // // If the first path targets [fhs.AbsRoot], it is made writable via an overlay // mount with writes going to an ephemeral tmpfs bound to the lifetime of the @@ -273,18 +275,46 @@ func (a *execArtifact) cure(c *CureContext, hostNet bool) (err error) { z.OverlayEphemeral(fhs.AbsRoot, paths[0][0]) paths = paths[1:] } + var overlayTemp *check.Absolute for _, b := range paths { + if b[1].Is(fhs.AbsTmp) { + if overlayTemp != nil { + z.Bind(overlayTemp, fhs.AbsTmp, 0) + } + overlayTemp = b[0] + continue + } z.Bind(b[0], b[1], 0) } z.Bind( c.GetWorkDir(), fhs.AbsRoot.Append("work"), std.BindWritable|std.BindEnsure, - ).Bind( - c.GetTempDir(), - fhs.AbsTmp, - std.BindWritable|std.BindEnsure, - ).Proc(fhs.AbsProc).Dev(fhs.AbsDev, true) + ) + if overlayTemp == nil { + z.Bind( + c.GetTempDir(), + fhs.AbsTmp, + std.BindWritable|std.BindEnsure, + ) + } else { + temp := c.GetTempDir() + tempUpper := temp.Append("upper") + if err = os.MkdirAll(tempUpper.String(), 0700); err != nil { + return + } + tempWork := temp.Append("work") + if err = os.MkdirAll(tempWork.String(), 0700); err != nil { + return + } + z.Overlay( + fhs.AbsTmp, + tempUpper, + tempWork, + overlayTemp, + ) + } + z.Proc(fhs.AbsProc).Dev(fhs.AbsDev, true) if err = z.Start(); err != nil { return |
