From 0df87ab1117bf4da5163ad486a82628f1bada7ed Mon Sep 17 00:00:00 2001 From: Ophestra Date: Tue, 6 Jan 2026 23:34:43 +0900 Subject: 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 --- internal/pkg/exec.go | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'internal/pkg/exec.go') 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 -- cgit v1.3.1