[ARVADOS] created: 2.1.0-622-g7400a1c82
Git user
git at public.arvados.org
Thu Apr 8 18:38:54 UTC 2021
at 7400a1c821c4bb3a8e3c87e9369da4b72b87c75e (commit)
commit 7400a1c821c4bb3a8e3c87e9369da4b72b87c75e
Author: Nico Cesar <nico at nicocesar.com>
Date: Thu Apr 8 14:33:52 2021 -0400
interface definition
Arvados-DCO-1.1-Signed-off-by: Nico Cesar <nico at curii.com>
diff --git a/lib/crunchrun/container_exec.go b/lib/crunchrun/container_exec.go
new file mode 100644
index 000000000..6dc87ec84
--- /dev/null
+++ b/lib/crunchrun/container_exec.go
@@ -0,0 +1,127 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+package crunchrun
+
+import (
+ "io"
+)
+
+// ContainerID is either Docker Container ID or Singularity something that can
+// be tracked down with singularity instance list or anything that casn be
+// referenced as "instance://instance1"
+type ContainerID string
+
+// ImageID is Docker Image ID or a "unique reference" in Singularity like a path
+// to the image. This is used to remove the image from disk.
+type ImageID string
+
+// ContainerStateStatus represents the status of our container
+type ContainerStateStatus int
+
+const (
+ Created ContainerStateStatus = iota
+ Running
+ Paused
+ Restarting
+ Removing
+ Exited
+ Dead
+ OOMKilled
+)
+
+func (c ContainerStateStatus) String() string {
+ return [...]string{"Created",
+ "Running",
+ "Paused",
+ "Restarting",
+ "Removing",
+ "Exited",
+ "Dead",
+ "OOMKilled",
+ }[c]
+}
+
+// ContainerState stores container's running state. In Docker is a subset of
+// ContainerJSONBase returned by ContainerInspect. In Singularity TBD how we'll
+// get the state of a running/dead container.
+type ContainerState struct {
+ Status ContainerStateStatus
+ Pid int
+ ExitCode int
+ Error string
+ StartedAt string
+ FinishedAt string
+}
+
+type ContainerConfig struct {
+ Env []string // List of environment variable to set in the container "VALUE=KEY" format
+ Cmd []string // Command to run when starting the container
+ Mounts []volumeMounts // List of Mounts used for the container.
+
+}
+
+// ContainerExecuter interface will implement all the methods needed for Docker,
+// Singularity, and others to load images, run containers, get thier outputs,
+// etc.
+type ContainerExecuter interface {
+ CheckImageIsLoaded(imageID ImageID) bool
+ LoadImage(containerImage io.Reader) error
+ ImageRemove(imageID ImageID) error
+
+ ContainerState() (ContainerState, error)
+
+ // CreateContainer will prepare anything in the creation on the container
+ // env is an array of string "KEY=VALUE" that represents the environment variables
+ // containerConfig has all the parameters needed to start the container
+ // in the past we also had
+ // - volumes: Now this is ExecOptions.mounts
+ // - hostConfig: Now this is ExecOptions.enableNetwork and others
+ // this are called when StartContainer() is executed.
+ CreateContainer(env []string) error
+
+ // StartContainer
+ StartContainer(execOptions ExecOptions, containerConfig ContainerConfig) error
+ RemoveContainer() error
+
+ // this is similar how https://golang.org/pkg/os/exec/#Cmd does it.
+ StdinPipe() (io.WriteCloser, error)
+ StdoutPipe() (io.ReadCloser, error)
+ StderrPipe() (io.ReadCloser, error)
+
+ // this is another option
+ Stdin() (io.ReadCloser, error)
+ Stdout() (io.WriteCloser, error)
+ Stderr() (io.WriteCloser, error)
+
+ // Wait for the container to finish
+ Wait()
+ // Kill the container and optionally remove the underlying image
+ Kill(removeImage bool)
+ ExitCode() (int, error)
+}
+
+// ContainerExec is a helper that implements ContainerExecuter interface and is
+// meant be be composed into the implementation as in:
+//<
+// type DockerExec struct {
+// ContainerExec
+//
+// newDockerExec() *ContainerExecuter
+//}
+type ContainerExec struct {
+ // TODO: add anything that could be useful for all ContainerExecs to
+ // minimize the boilerplate for creating new ones.
+}
+
+// ExecOptions are the options used in StartContainer()
+type ExecOptions struct {
+ enableNetworking bool
+ mounts []volumeMounts
+}
+
+type volumeMounts struct {
+ hostPath string
+ containerPath string
+ readonly bool
+}
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list