sandbox

package
v0.0.0-...-884cfb1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2019 License: GPL-3.0 Imports: 11 Imported by: 1

Documentation

Overview

Package sandbox contains code related to the worker of moolinet. It will compile, analyze and execute the code in a sandbox.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Timeout time.Duration
	Network bool
}

Config is the structure used as a parameter for sandboxed commands.

type DockerSandbox

type DockerSandbox struct {
	// contains filtered or unexported fields
}

DockerSandbox is the Docker implementation of the Sandbox interface.

func NewDockerSandbox

func NewDockerSandbox(c DockerSandboxConfig) (*DockerSandbox, error)

NewDockerSandbox returns a new DockerSandbox from an image name.

We should use a design pattern such as Fabric or Builder, or somethng similar In order to split the creation logic and the command logic. BUG(#2) We should not try to download the image every time we start a new container. We should check if it exists locally.

func (*DockerSandbox) Destroy

func (s *DockerSandbox) Destroy()

Destroy removes the current container.

func (*DockerSandbox) GetLogs

func (s *DockerSandbox) GetLogs() string

GetLogs returns currently saved logs.

func (*DockerSandbox) Run

func (s *DockerSandbox) Run(command []string, config Config) (string, error)

Run runs the provided command in the Docker Sandbox.

type DockerSandboxConfig

type DockerSandboxConfig struct {
	Image  string
	Memory int64
	Disk   int64 //@FIXME deprecated
	Procs  int64
}

DockerSandboxConfig contains parameters related to the initialization of a Docker Sandbox.

type Sandbox

type Sandbox interface {
	// Destroy the sandbox on the main system.
	// Usually just after its creation with defer.
	Destroy()

	// Run a command in the sandbox and get its outputs
	// (output, error)
	Run(command []string, config Config) (string, error)

	// Get logs linked to the Sandbox
	// Useful for debugging
	GetLogs() string
}

Sandbox is the interface which enable you to run your program independently of the implementation of the sandbox.

Notes

Bugs

  • We should not try to download the image every time we start a new container. We should check if it exists locally.

  • Logs are not checked for error when pulling an image

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL