helper

package
v0.0.0-...-cb986fb Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2018 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AuxContainerConfig = container.Config{
	Hostname: AuxContainerName,
	Env: []string{
		GetEnvByKey("STAGE"),
		GetEnvByKey("LOGLEVEL"),
	},
	ExposedPorts: GetPortSet(DefaultPorts),
	Image: ConcatString(
		"ramrodpcp/auxiliary-services",
		":",
		GetTagFromEnv(),
	),
}

AuxContainerConfig ...

View Source
var AuxContainerName = "aux-services"

AuxContainerName ...

View Source
var AuxHostConfig = container.HostConfig{
	NetworkMode: "default",
	PortBindings: GetPortMap(
		GetIP(),
		GetPorts([][]string{
			[]string{"tcp", "20"},
			[]string{"tcp", "21"},
			[]string{"tcp", "80"},
			[]string{"udp", "53"},
			[]string{"tcp", "10090"},
			[]string{"tcp", "10091"},
			[]string{"tcp", "10092"},
			[]string{"tcp", "10093"},
			[]string{"tcp", "10094"},
			[]string{"tcp", "10095"},
			[]string{"tcp", "10096"},
			[]string{"tcp", "10097"},
			[]string{"tcp", "10098"},
			[]string{"tcp", "10099"},
			[]string{"tcp", "10100"},
		}),
	),
	AutoRemove:  true,
	CapAdd:      strslice.StrSlice{"SYS_ADMIN"},
	SecurityOpt: []string{"apparmor:unconfined"},
	Resources: container.Resources{
		Devices: []container.DeviceMapping{
			container.DeviceMapping{
				PathOnHost:        "/dev/fuse",
				PathInContainer:   "/dev/fuse",
				CgroupPermissions: "mrw",
			},
		},
	},
}

AuxHostConfig ...

View Source
var AuxNetConfig = network.NetworkingConfig{
	EndpointsConfig: map[string]*network.EndpointSettings{
		"pcp": &network.EndpointSettings{
			Aliases:   []string{"auxiliary-services"},
			NetworkID: Net.ID,
		},
	},
}

AuxNetConfig ...

View Source
var AuxServiceSpec = swarm.ServiceSpec{
	Annotations: swarm.Annotations{
		Name: "AuxiliaryServices",
	},
	TaskTemplate: swarm.TaskSpec{
		ContainerSpec: swarm.ContainerSpec{
			DNSConfig: &swarm.DNSConfig{},
			Image:     getImage("ramrodpcp/auxiliary-wrapper"),
			Mounts: []mount.Mount{
				mount.Mount{
					Type:   mount.TypeBind,
					Source: "/var/run/docker.sock",
					Target: "/var/run/docker.sock",
				},
			},
			Env: []string{
				getEnvStage(),
				GetEnvByKey("TAG"),
			},
		},
		Networks: []swarm.NetworkAttachmentConfig{
			swarm.NetworkAttachmentConfig{
				Target: "pcp",
			},
		},
		RestartPolicy: &swarm.RestartPolicy{
			Condition: "on-failure",
		},
	},
	EndpointSpec: &swarm.EndpointSpec{
		Mode: swarm.ResolutionModeVIP,
	},
}

AuxServiceSpec is a spec used for testing the aux service

View Source
var DefaultPorts = [][]string{
	[]string{"tcp", "20"},
	[]string{"tcp", "21"},
	[]string{"tcp", "80"},
	[]string{"udp", "53"},
	[]string{"tcp", "10090"},
	[]string{"tcp", "10091"},
	[]string{"tcp", "10092"},
	[]string{"tcp", "10093"},
	[]string{"tcp", "10094"},
	[]string{"tcp", "10095"},
	[]string{"tcp", "10096"},
	[]string{"tcp", "10097"},
	[]string{"tcp", "10098"},
	[]string{"tcp", "10099"},
	[]string{"tcp", "10100"},
}

DefaultPorts is the set of default ports the aux services container uses.

View Source
var Net = func() types.NetworkResource {
	ctx, cancel := context.WithCancel(context.Background())
	dockerClient, err := client.NewEnvClient()
	if err != nil {
		panic(err)
	}

	defer cancel()

	netFilter := filters.NewArgs()
	netFilter.Add("name", "pcp")

	nets, err := dockerClient.NetworkList(ctx, types.NetworkListOptions{
		Filters: netFilter,
	})
	if err != nil {
		panic(err)
	}
	if len(nets) == 1 {
		return nets[0]
	}
	return types.NetworkResource{}
}()

Net ...

Functions

func ConcatString

func ConcatString(k string, sep string, v string) string

ConcatString returns a new string from two strings and a separator.

func GetAuxID

func GetAuxID() string

GetAuxID gets the ID of the aux-services container.

func GetContainerFilterArgs

func GetContainerFilterArgs(name string) filters.Args

GetContainerFilterArgs gets a filters.GetContainerFilterArgs object that filters for a specific container by name.

func GetEnvByKey

func GetEnvByKey(k string) string

GetEnvByKey gets environment variables by key and returns them in the form KEY=VALUE. It tries to pull from the default envs if there is nothing set.

func GetIP

func GetIP() string

GetIP gets the IP address of the swarm manager

func GetPortMap

func GetPortMap(ip string, ports []nat.Port) nat.PortMap

GetPortMap gets a nat.PortMap from an IP address and a slice of nat.Ports.

func GetPortSet

func GetPortSet(ports [][]string) nat.PortSet

GetPortSet creates the default port set for the auxiliary services container

func GetPorts

func GetPorts(in [][]string) []nat.Port

GetPorts returns a []nat.Port from a slice of string slices in the format ["proto", "port"].

func GetTagFromEnv

func GetTagFromEnv() string

GetTagFromEnv gets the Docker tag (dev, qa, latest) from the environment variable TAG.

func KillAux

func KillAux(ctx context.Context, dockerClient *client.Client, id string) error

KillAux kills the aux services container

func KillNet

func KillNet(netid string) error

KillNet removes the test network

func StartAux

func StartAux(ctx context.Context, dockerClient *client.Client) (container.ContainerCreateCreatedBody, error)

StartAux starts the test auxiliary services container

Types

This section is empty.

Jump to

Keyboard shortcuts

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