packer-cn/builder/docker/driver.go

84 lines
2.3 KiB
Go
Raw Normal View History

package docker
2013-11-09 16:15:51 -05:00
import (
"io"
2015-05-29 12:29:59 -04:00
"github.com/hashicorp/go-version"
2013-11-09 16:15:51 -05:00
)
// Driver is the interface that has to be implemented to communicate with
// Docker. The Driver interface also allows the steps to be tested since
// a mock driver can be shimmed in.
type Driver interface {
// Commit the container to a tag
Commit(id string, author string, changes []string, message string) (string, error)
// Delete an image that is imported into Docker
DeleteImage(id string) error
2013-11-09 16:15:51 -05:00
// Export exports the container with the given ID to the given writer.
Export(id string, dst io.Writer) error
// Import imports a container from a tar file
2018-12-17 23:13:40 -05:00
Import(path string, changes []string, repo string) (string, error)
// IPAddress returns the address of the container that can be used
// for external access.
IPAddress(id string) (string, error)
// Sha256 returns the sha256 id of the image
Sha256(id string) (string, error)
2014-09-05 18:06:07 -04:00
// Login. This will lock the driver from performing another Login
// until Logout is called. Therefore, any users MUST call Logout.
Login(repo, username, password string) error
2014-09-05 18:06:07 -04:00
// Logout. This can only be called if Login succeeded.
Logout(repo string) error
// Pull should pull down the given image.
Pull(image string) error
2013-11-09 16:03:01 -05:00
// Push pushes an image to a Docker index/registry.
Push(name string) error
2014-07-20 16:58:07 -04:00
// Save an image with the given ID to the given writer.
SaveImage(id string, dst io.Writer) error
2013-11-09 16:03:01 -05:00
// StartContainer starts a container and returns the ID for that container,
// along with a potential error.
StartContainer(*ContainerConfig) (string, error)
// KillContainer forcibly stops a container.
KillContainer(id string) error
// StopContainer gently stops a container.
2013-11-09 16:03:01 -05:00
StopContainer(id string) error
2014-07-20 14:58:03 -04:00
// TagImage tags the image with the given ID
2015-04-18 00:12:28 -04:00
TagImage(id string, repo string, force bool) error
2014-07-20 14:58:03 -04:00
// Verify verifies that the driver can run
Verify() error
2015-05-29 12:29:59 -04:00
// Version reads the Docker version
Version() (*version.Version, error)
2013-11-09 16:03:01 -05:00
}
// ContainerConfig is the configuration used to start a container.
type ContainerConfig struct {
Image string
RunCommand []string
Device []string
CapAdd []string
CapDrop []string
Volumes map[string]string
TmpFs []string
Privileged bool
}
// This is the template that is used for the RunCommand in the ContainerConfig.
type startContainerTemplate struct {
2014-09-08 13:28:21 -04:00
Image string
}