Documentation
¶
Index ¶
- type Client
- func (Client) ContainerConfig(image string, virtualhost string) *container.Config
- func (cli *Client) ContainerCreate(ctx context.Context, opts *CreateOpts) (string, error)
- func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
- func (cli *Client) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
- func (cli *Client) ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error
- func (Client) GenerateContainerName() string
- func (client *Client) NetworkConnect(ctx context.Context, preffix string, name string) (*network.NetworkingConfig, error)
- func (client *Client) NetworkingConfig(networkID string) *network.NetworkingConfig
- type Container
- type CreateOpts
- type Docker
- type DockerMock
- func (mock *DockerMock) ContainerConfig(image string, virtualhost string) *container.Config
- func (mock *DockerMock) ContainerConfigCalls() []struct{ ... }
- func (mock *DockerMock) ContainerCreate(ctx context.Context, opts *CreateOpts) (string, error)
- func (mock *DockerMock) ContainerCreateCalls() []struct{ ... }
- func (mock *DockerMock) ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
- func (mock *DockerMock) ContainerExecAttachCalls() []struct{ ... }
- func (mock *DockerMock) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
- func (mock *DockerMock) ContainerExecCreateCalls() []struct{ ... }
- func (mock *DockerMock) ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error
- func (mock *DockerMock) ContainerStartCalls() []struct{ ... }
- func (mock *DockerMock) GenerateContainerName() string
- func (mock *DockerMock) GenerateContainerNameCalls() []struct{}
- func (mock *DockerMock) NetworkConnect(ctx context.Context, preffix string, name string) (*network.NetworkingConfig, error)
- func (mock *DockerMock) NetworkConnectCalls() []struct{ ... }
- func (mock *DockerMock) NetworkingConfig(networkID string) *network.NetworkingConfig
- func (mock *DockerMock) NetworkingConfigCalls() []struct{ ... }
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
Conn *dockerClient.Client
ProxyContainerID string
}
Client handles all docker-related tasks (implementation of Docker interface).
func (Client) ContainerConfig ¶
ContainerConfig generates a configuration for creating a container.
func (*Client) ContainerCreate ¶
ContainerCreate creates a new container.
func (*Client) ContainerExecAttach ¶
func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
ContainerExecAttach attaches a connection to an exec process in the server
func (*Client) ContainerExecCreate ¶
func (cli *Client) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
ContainerExecCreate runs a new command in a running container.
func (*Client) ContainerStart ¶
func (cli *Client) ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error
ContainerStart starts a container.
func (Client) GenerateContainerName ¶
GenerateContainerName creates a new name for a container.
func (*Client) NetworkConnect ¶
func (client *Client) NetworkConnect(ctx context.Context, preffix string, name string) (*network.NetworkingConfig, error)
NetworkConnect handles networking of the containers.
A build might have several containers, so this method creates a network for to allow communication among them. It also connects the nginx proxy to the new for auto-proxying.
For instance, the preffix can be the build id and the name the container id.
func (*Client) NetworkingConfig ¶
func (client *Client) NetworkingConfig(networkID string) *network.NetworkingConfig
NetworkingConfig generates a network configuration for a container.
type Container ¶
type Container struct {
ID string // The container ID (assigned at creation by Docker).
Name string
Host string // The virtualhost where the live site is accessible from (used by nginx-proxy).
Network string
}
Container describes a new container.
type CreateOpts ¶
type CreateOpts struct {
Config *container.Config
HostConfig *container.HostConfig
NetworkingConfig *network.NetworkingConfig
ContainerName string
}
CreateOpts are the parameter to ContainerCreate
type Docker ¶
type Docker interface {
GenerateContainerName() string
ContainerCreate(ctx context.Context, opts *CreateOpts) (string, error)
ContainerConfig(image string, virtualhost string) *container.Config
ContainerStart(ctx context.Context, containerID string, options dockerTypes.ContainerStartOptions) error
ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
NetworkConnect(ctx context.Context, preffix string, name string) (*network.NetworkingConfig, error)
NetworkingConfig(networkID string) *network.NetworkingConfig
}
Docker describes a handler for docker-related tasks.
type DockerMock ¶
type DockerMock struct {
// ContainerConfigFunc mocks the ContainerConfig method.
ContainerConfigFunc func(image string, virtualhost string) *container.Config
// ContainerCreateFunc mocks the ContainerCreate method.
ContainerCreateFunc func(ctx context.Context, opts *CreateOpts) (string, error)
// ContainerExecAttachFunc mocks the ContainerExecAttach method.
ContainerExecAttachFunc func(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
// ContainerExecCreateFunc mocks the ContainerExecCreate method.
ContainerExecCreateFunc func(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
// ContainerStartFunc mocks the ContainerStart method.
ContainerStartFunc func(ctx context.Context, containerID string, options types.ContainerStartOptions) error
// GenerateContainerNameFunc mocks the GenerateContainerName method.
GenerateContainerNameFunc func() string
// NetworkConnectFunc mocks the NetworkConnect method.
NetworkConnectFunc func(ctx context.Context, preffix string, name string) (*network.NetworkingConfig, error)
// NetworkingConfigFunc mocks the NetworkingConfig method.
NetworkingConfigFunc func(networkID string) *network.NetworkingConfig
// contains filtered or unexported fields
}
DockerMock is a mock implementation of Docker.
func TestSomethingThatUsesDocker(t *testing.T) {
// make and configure a mocked Docker
mockedDocker := &DockerMock{
ContainerConfigFunc: func(image string, virtualhost string) *container.Config {
panic("mock out the ContainerConfig method")
},
ContainerCreateFunc: func(ctx context.Context, opts *CreateOpts) (string, error) {
panic("mock out the ContainerCreate method")
},
ContainerExecAttachFunc: func(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error) {
panic("mock out the ContainerExecAttach method")
},
ContainerExecCreateFunc: func(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error) {
panic("mock out the ContainerExecCreate method")
},
ContainerStartFunc: func(ctx context.Context, containerID string, options types.ContainerStartOptions) error {
panic("mock out the ContainerStart method")
},
GenerateContainerNameFunc: func() string {
panic("mock out the GenerateContainerName method")
},
NetworkConnectFunc: func(ctx context.Context, preffix string, name string) (*network.NetworkingConfig, error) {
panic("mock out the NetworkConnect method")
},
NetworkingConfigFunc: func(networkID string) *network.NetworkingConfig {
panic("mock out the NetworkingConfig method")
},
}
// use mockedDocker in code that requires Docker
// and then make assertions.
}
func (*DockerMock) ContainerConfig ¶
func (mock *DockerMock) ContainerConfig(image string, virtualhost string) *container.Config
ContainerConfig calls ContainerConfigFunc.
func (*DockerMock) ContainerConfigCalls ¶
func (mock *DockerMock) ContainerConfigCalls() []struct { Image string Virtualhost string }
ContainerConfigCalls gets all the calls that were made to ContainerConfig. Check the length with:
len(mockedDocker.ContainerConfigCalls())
func (*DockerMock) ContainerCreate ¶
func (mock *DockerMock) ContainerCreate(ctx context.Context, opts *CreateOpts) (string, error)
ContainerCreate calls ContainerCreateFunc.
func (*DockerMock) ContainerCreateCalls ¶
func (mock *DockerMock) ContainerCreateCalls() []struct { Ctx context.Context Opts *CreateOpts }
ContainerCreateCalls gets all the calls that were made to ContainerCreate. Check the length with:
len(mockedDocker.ContainerCreateCalls())
func (*DockerMock) ContainerExecAttach ¶
func (mock *DockerMock) ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
ContainerExecAttach calls ContainerExecAttachFunc.
func (*DockerMock) ContainerExecAttachCalls ¶
func (mock *DockerMock) ContainerExecAttachCalls() []struct { Ctx context.Context ExecID string Config types.ExecConfig }
ContainerExecAttachCalls gets all the calls that were made to ContainerExecAttach. Check the length with:
len(mockedDocker.ContainerExecAttachCalls())
func (*DockerMock) ContainerExecCreate ¶
func (mock *DockerMock) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
ContainerExecCreate calls ContainerExecCreateFunc.
func (*DockerMock) ContainerExecCreateCalls ¶
func (mock *DockerMock) ContainerExecCreateCalls() []struct { Ctx context.Context Container string Config types.ExecConfig }
ContainerExecCreateCalls gets all the calls that were made to ContainerExecCreate. Check the length with:
len(mockedDocker.ContainerExecCreateCalls())
func (*DockerMock) ContainerStart ¶
func (mock *DockerMock) ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error
ContainerStart calls ContainerStartFunc.
func (*DockerMock) ContainerStartCalls ¶
func (mock *DockerMock) ContainerStartCalls() []struct { Ctx context.Context ContainerID string Options types.ContainerStartOptions }
ContainerStartCalls gets all the calls that were made to ContainerStart. Check the length with:
len(mockedDocker.ContainerStartCalls())
func (*DockerMock) GenerateContainerName ¶
func (mock *DockerMock) GenerateContainerName() string
GenerateContainerName calls GenerateContainerNameFunc.
func (*DockerMock) GenerateContainerNameCalls ¶
func (mock *DockerMock) GenerateContainerNameCalls() []struct { }
GenerateContainerNameCalls gets all the calls that were made to GenerateContainerName. Check the length with:
len(mockedDocker.GenerateContainerNameCalls())
func (*DockerMock) NetworkConnect ¶
func (mock *DockerMock) NetworkConnect(ctx context.Context, preffix string, name string) (*network.NetworkingConfig, error)
NetworkConnect calls NetworkConnectFunc.
func (*DockerMock) NetworkConnectCalls ¶
func (mock *DockerMock) NetworkConnectCalls() []struct { Ctx context.Context Preffix string Name string }
NetworkConnectCalls gets all the calls that were made to NetworkConnect. Check the length with:
len(mockedDocker.NetworkConnectCalls())
func (*DockerMock) NetworkingConfig ¶
func (mock *DockerMock) NetworkingConfig(networkID string) *network.NetworkingConfig
NetworkingConfig calls NetworkingConfigFunc.
func (*DockerMock) NetworkingConfigCalls ¶
func (mock *DockerMock) NetworkingConfigCalls() []struct { NetworkID string }
NetworkingConfigCalls gets all the calls that were made to NetworkingConfig. Check the length with:
len(mockedDocker.NetworkingConfigCalls())