feat: self-update of master and agents (#15)
This commit is contained in:
@@ -177,20 +177,35 @@ var errNoRoots = errors.New("refused: no stack directory is mounted into the age
|
||||
// path inside the container. Compose labels hold host paths, so only those
|
||||
// mounts make a label path usable as is.
|
||||
func MountRoots(ctx context.Context, cli SelfInspector, selfID string) ([]string, error) {
|
||||
insp, err := inspectSelf(ctx, cli, selfID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rootsOf(insp), nil
|
||||
}
|
||||
|
||||
// inspectSelf inspects the agent's own container.
|
||||
func inspectSelf(ctx context.Context, cli SelfInspector, selfID string) (container.InspectResponse, error) {
|
||||
if selfID == "" {
|
||||
return nil, errNoRoots
|
||||
return container.InspectResponse{}, errNoRoots
|
||||
}
|
||||
insp, err := cli.ContainerInspect(ctx, selfID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("inspect own container %s: %w", selfID, err)
|
||||
return container.InspectResponse{}, fmt.Errorf("inspect own container %s: %w", selfID, err)
|
||||
}
|
||||
return insp, nil
|
||||
}
|
||||
|
||||
// rootsOf returns the directories MountRoots describes, from an inspected
|
||||
// container.
|
||||
func rootsOf(insp container.InspectResponse) []string {
|
||||
var roots []string
|
||||
for _, m := range insp.Mounts {
|
||||
if m.Type == mount.TypeBind && m.RW && filepath.Clean(m.Source) == filepath.Clean(m.Destination) {
|
||||
roots = append(roots, filepath.Clean(m.Destination))
|
||||
}
|
||||
}
|
||||
return roots, nil
|
||||
return roots
|
||||
}
|
||||
|
||||
// composeFiles returns the -f arguments for a job: the stack's config files
|
||||
|
||||
Reference in New Issue
Block a user