fix(storage): mount a task's object mirror read-only into its container
This commit is contained in:
1 file changed
+24
-3
@@ -44,6 +44,7 @@ type Mount struct {
|
||||
Source string // host path (bind) or volume name (volume)
|
||||
Destination string // container path
|
||||
Shared bool // bind source is intentionally shared between containers
|
||||
ReadOnly bool
|
||||
}
|
||||
|
||||
// Mount type constants.
|
||||
@@ -280,6 +281,11 @@ func (d *DockerBackend) Setup(ctx context.Context, task TaskRef) ([]Mount, error
|
||||
Destination: WorktreeMountDir,
|
||||
},
|
||||
}
|
||||
// A worktree cloned from a shared mirror reads its objects through the
|
||||
// mirror's host path, so git in the container needs that path too.
|
||||
if mirror := alternatesSource(task.WorktreeDir); mirror != "" {
|
||||
mounts = append(mounts, Mount{Type: MountTypeBind, Source: mirror, Destination: mirror, Shared: true, ReadOnly: true})
|
||||
}
|
||||
|
||||
// Per-repo persistent volume.
|
||||
if task.PersistentStorage && task.Owner != "" && task.Repo != "" {
|
||||
@@ -361,10 +367,25 @@ func ConvertMounts(mounts []Mount) []mount.Mount {
|
||||
out := make([]mount.Mount, len(mounts))
|
||||
for i, m := range mounts {
|
||||
out[i] = mount.Mount{
|
||||
Type: mount.Type(m.Type),
|
||||
Source: m.Source,
|
||||
Target: m.Destination,
|
||||
Type: mount.Type(m.Type),
|
||||
Source: m.Source,
|
||||
Target: m.Destination,
|
||||
ReadOnly: m.ReadOnly,
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// alternatesSource returns the repository directory that the worktree's
|
||||
// alternates file borrows objects from, or "" when it borrows none.
|
||||
func alternatesSource(worktree string) string {
|
||||
data, err := os.ReadFile(filepath.Join(worktree, ".git", "objects", "info", "alternates"))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
objects := strings.TrimSpace(strings.SplitN(string(data), "\n", 2)[0])
|
||||
if !filepath.IsAbs(objects) {
|
||||
return ""
|
||||
}
|
||||
return filepath.Dir(objects)
|
||||
}
|
||||
Reference in new issue
Block a user