Add json storage for container storage
This is just a temporary storage solution to get containers running on the new code. Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
@@ -3,6 +3,9 @@ package main
|
||||
import (
|
||||
gocontext "context"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
|
||||
containersapi "github.com/containerd/containerd/api/services/containers"
|
||||
"github.com/containerd/containerd/api/services/execution"
|
||||
"github.com/pkg/errors"
|
||||
@@ -43,7 +46,11 @@ var deleteCommand = cli.Command{
|
||||
ContainerID: id,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to delete container")
|
||||
// Ignore error if task has already been removed, task is
|
||||
// removed by default after run
|
||||
if grpc.Code(errors.Cause(err)) != codes.NotFound {
|
||||
return errors.Wrap(err, "failed to task container")
|
||||
}
|
||||
}
|
||||
|
||||
if err := snapshotter.Remove(ctx, id); err != nil {
|
||||
|
||||
@@ -65,18 +65,23 @@ var listCommand = cli.Command{
|
||||
w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0)
|
||||
fmt.Fprintln(w, "ID\tIMAGE\tPID\tSTATUS")
|
||||
for _, c := range response.Containers {
|
||||
var status string
|
||||
var (
|
||||
status string
|
||||
pid uint32
|
||||
)
|
||||
task, ok := tasksByContainerID[c.ID]
|
||||
if ok {
|
||||
status = task.Status.String()
|
||||
pid = task.Pid
|
||||
} else {
|
||||
status = "STOPPED" // TODO(stevvooe): Is this assumption correct?
|
||||
pid = 0
|
||||
}
|
||||
|
||||
if _, err := fmt.Fprintf(w, "%s\t%s\t%d\t%s\n",
|
||||
c.ID,
|
||||
c.Image,
|
||||
task.Pid,
|
||||
pid,
|
||||
status,
|
||||
); err != nil {
|
||||
return err
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/containerd/console"
|
||||
containersapi "github.com/containerd/containerd/api/services/containers"
|
||||
"github.com/containerd/containerd/api/services/execution"
|
||||
"github.com/containerd/containerd/images"
|
||||
"github.com/containerd/containerd/mount"
|
||||
@@ -294,6 +295,11 @@ var runCommand = cli.Command{
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if context.Bool("rm") {
|
||||
if _, err := containers.Delete(ctx, &containersapi.DeleteContainerRequest{ID: id}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if status != 0 {
|
||||
return cli.NewExitError("", int(status))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user