diff --git a/engine/convert.go b/engine/convert.go index 77c2188..e7a0e14 100644 --- a/engine/convert.go +++ b/engine/convert.go @@ -33,21 +33,16 @@ func toSpec(spec *Spec, step *Step) *specgen.SpecGenerator { } volume := specgen.ContainerStorageConfig{ + Image: step.Image, WorkDir: step.WorkingDir, CreateWorkingDir: true, ShmSize: toPtr(step.ShmSize), } - volumeSet := toVolumeSet(spec, step) - for path := range volumeSet { - volume.Volumes = append(volume.Volumes, &specgen.NamedVolume{ - Dest: path, - }) - } - if len(step.Volumes) != 0 { volume.Devices = toLinuxDeviceSlice(spec, step) volume.Mounts = toLinuxVolumeMounts(spec, step) + volume.Volumes = toLinuxVolumeSlice(spec, step) } security := specgen.ContainerSecurityConfig{ @@ -140,35 +135,9 @@ func toLinuxDeviceSlice(spec *Spec, step *Step) []specs.LinuxDevice { return to } -// helper function that converts a slice of volume paths to a set -// of unique volume names. -func toVolumeSet(spec *Spec, step *Step) map[string]struct{} { - set := map[string]struct{}{} - for _, mount := range step.Volumes { - volume, ok := lookupVolume(spec, mount.Name) - if !ok { - continue - } - if isDevice(volume) { - continue - } - if isNamedPipe(volume) { - continue - } - if isBindMount(volume) == false { - continue - } - set[mount.Path] = struct{}{} - } - return set -} - // helper function returns a slice of volume mounts. -func toVolumeSlice(spec *Spec, step *Step) []string { - // this entire function should be deprecated in - // favor of toVolumeMounts, however, I am unable - // to get it working with data volumes. - var to []string +func toLinuxVolumeSlice(spec *Spec, step *Step) []*specgen.NamedVolume { + var to []*specgen.NamedVolume for _, mount := range step.Volumes { volume, ok := lookupVolume(spec, mount.Name) if !ok { @@ -178,14 +147,19 @@ func toVolumeSlice(spec *Spec, step *Step) []string { continue } if isDataVolume(volume) { - path := volume.EmptyDir.ID + ":" + mount.Path - to = append(to, path) + to = append(to, &specgen.NamedVolume{ + Name: volume.EmptyDir.ID, + Dest: mount.Path, + }) } if isBindMount(volume) { - path := volume.HostPath.Path + ":" + mount.Path - to = append(to, path) + to = append(to, &specgen.NamedVolume{ + Name: volume.HostPath.Path, + Dest: mount.Path, + }) } } + return to } @@ -231,12 +205,11 @@ func toLinuxMount(source *Volume, target *VolumeMount) specs.Mount { // options defaults = rw, suid, dev, exec, auto, nouser, and async to.Options = append(to.Options, "ro") } - // to.ReadOnly = source.HostPath.ReadOnly } if isTempfs(source) { - // NOTE: not sure if this is translatable - // probably part of resource struct + // NOTE: specs.Mount might not be the right structure + // maybe ImageVolume is suitable here // to.TmpfsOptions = &mount.TmpfsOptions{ // SizeBytes: source.EmptyDir.SizeLimit, diff --git a/engine/engine.go b/engine/engine.go index db7d39d..9ce722b 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -102,6 +102,7 @@ func (e *Podman) Setup(ctx context.Context, specv runtime.Spec) error { logger.FromContext(ctx).Tracef("setup networks...") _, err := network.Create(e.conn, &types.Network{ Driver: driver, + Name: spec.Network.ID, Options: spec.Network.Options, Labels: spec.Network.Labels, }) @@ -238,19 +239,14 @@ func (e *Podman) Run(ctx context.Context, specv runtime.Spec, stepv runtime.Step } defer logs.Close() } else { - var buf bytes.Buffer - multiWriter := io.MultiWriter(output, &buf) - logger.FromContext(ctx).Tracef("tail logging...") - err = e.tail(ctx, step.ID, multiWriter) + err = e.tail(ctx, step.ID, output) if err != nil { logger.FromContext(ctx). WithError(err). Errorf("failed to tail logs") return nil, errors.TrimExtraInfo(err) } - - logger.FromContext(ctx).Debugf("[tail_logs=%s]", buf.String()) } // wait for the response @@ -364,6 +360,10 @@ func (e *Podman) waitRetry(ctx context.Context, id string) (*runtime.State, erro // helper function emulates the `docker wait` command, blocking // until the container stops and returning the exit code. func (e *Podman) wait(ctx context.Context, id string) (*runtime.State, error) { + logger.FromContext(ctx). + WithField("container", id). + Debug("waiting for container") + containers.Wait(e.conn, id, &containers.WaitOptions{ Conditions: []string{"created", "exited", "dead", "removing", "removed"}, })