当前位置: 首页>>代码示例>>Golang>>正文


Golang Task.ContainerName方法代码示例

本文整理汇总了Golang中github.com/pulcy/j2/jobs.Task.ContainerName方法的典型用法代码示例。如果您正苦于以下问题:Golang Task.ContainerName方法的具体用法?Golang Task.ContainerName怎么用?Golang Task.ContainerName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/pulcy/j2/jobs.Task的用法示例。


在下文中一共展示了Task.ContainerName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: CreateProxyCmds

// CreateProxyCmds creates the commands needed for a proxy unit.
func (e *dockerEngine) CreateProxyCmds(t *jobs.Task, link jobs.Link, linkIndex int, env map[string]string, scalingGroup uint) (engine.Cmds, error) {
	containerName := fmt.Sprintf("%s-pr%d", t.ContainerName(scalingGroup), linkIndex)
	containerImage := images.Wormhole
	execStart, err := e.createProxyDockerCmdLine(t, containerName, containerImage, link, env, scalingGroup)
	if err != nil {
		return engine.Cmds{}, maskAny(err)
	}
	var cmds engine.Cmds
	cmds.Start = append(cmds.Start,
		e.pullCmd(containerImage),
		e.stopCmd(containerName),
		e.removeCmd(containerName),
		e.cleanupCmd(),
	)
	if e.options.EnvFile != "" {
		cmds.Start = append(cmds.Start, *cmdline.New(nil, e.touchPath, e.options.EnvFile))
	}
	cmds.Start = append(cmds.Start, execStart)

	cmds.Stop = append(cmds.Stop,
		e.stopCmd(containerName),
		e.removeCmd(containerName),
	)

	return cmds, nil
}
开发者ID:pulcy,项目名称:j2,代码行数:27,代码来源:docker_proxy.go

示例2: CreateMainCmds

// CreateMainCmds creates the commands needed for a main unit.
func (e *dockerEngine) CreateMainCmds(t *jobs.Task, env map[string]string, scalingGroup uint) (engine.Cmds, error) {
	containerName := t.ContainerName(scalingGroup)
	containerImage := t.Image.String()
	if t.Type == "proxy" {
		containerImage = images.Alpine
	}
	execStart, err := e.createMainDockerCmdLine(t, containerImage, env, scalingGroup)
	if err != nil {
		return engine.Cmds{}, maskAny(err)
	}

	var cmds engine.Cmds
	cmds.Start = append(cmds.Start,
		e.pullCmd(containerImage),
	)
	if e.options.EnvFile != "" {
		cmds.Start = append(cmds.Start, *cmdline.New(nil, e.touchPath, e.options.EnvFile))
	}
	// Add secret extraction commands
	secretsCmds, err := e.createSecretsExecStartPre(t, images.VaultMonkey, env, scalingGroup)
	if err != nil {
		return engine.Cmds{}, maskAny(err)
	}
	cmds.Start = append(cmds.Start, secretsCmds...)
	cmds.Start = append(cmds.Start,
		e.stopCmd(containerName),
		e.removeCmd(containerName),
		e.cleanupCmd(),
	)

	for _, v := range t.Volumes {
		if v.IsLocal() {
			cmds.Start = append(cmds.Start, e.createTestLocalVolumeCmd(v.HostPath))
		}
	}

	cmds.Start = append(cmds.Start, execStart)

	cmds.Stop = append(cmds.Stop,
		e.stopCmd(containerName),
		e.removeCmd(containerName),
	)

	return cmds, nil
}
开发者ID:pulcy,项目名称:j2,代码行数:46,代码来源:docker_main.go

示例3: createMainDockerCmdLine

// createMainDockerCmdLine creates the `ExecStart` line for
// the main unit.
func (e *dockerEngine) createMainDockerCmdLine(t *jobs.Task, image string, env map[string]string, scalingGroup uint) (cmdline.Cmdline, error) {
	serviceName := t.ServiceName()
	cmd, err := e.createDockerCmd(env, t.Network)
	if err != nil {
		return cmd, maskAny(err)
	}
	cmd.Add(nil, "run", "--rm", fmt.Sprintf("--name %s", t.ContainerName(scalingGroup)))
	if err := e.addDockerNetworkArgs(&cmd, env, t); err != nil {
		return cmd, maskAny(err)
	}
	if len(t.Ports) > 0 {
		for _, p := range t.Ports {
			cmd.Add(env, fmt.Sprintf("-p %s", p))
		}
	} else {
		cmd.Add(env, "-P")
	}
	for i, v := range t.Volumes {
		if v.IsLocal() {
			cmd.Add(env, fmt.Sprintf("-v %s", v))
		} else if !v.IsLocal() {
			cmd.Add(env, fmt.Sprintf("--volumes-from %s", createVolumeUnitContainerName(t, i, scalingGroup)))
		}
	}
	for _, secret := range t.Secrets {
		if ok, path := secret.TargetFile(); ok {
			hostPath, err := secretFilePath(t, scalingGroup, secret)
			if err != nil {
				return cmdline.Cmdline{}, maskAny(err)
			}
			cmd.Add(env, fmt.Sprintf("-v %s:%s:ro", hostPath, path))
		}
	}
	for _, name := range t.VolumesFrom {
		other, err := t.Task(name)
		if err != nil {
			return cmdline.Cmdline{}, maskAny(err)
		}
		for i, v := range other.Volumes {
			if !v.IsLocal() {
				cmd.Add(env, fmt.Sprintf("--volumes-from %s", createVolumeUnitContainerName(other, i, scalingGroup)))
			}
		}
		cmd.Add(env, fmt.Sprintf("--volumes-from %s", other.ContainerName(scalingGroup)))
	}
	envKeys := []string{}
	for k := range t.Environment {
		envKeys = append(envKeys, k)
	}
	sort.Strings(envKeys)
	if e.options.EnvFile != "" {
		cmd.Add(env, fmt.Sprintf("--env-file=%s", e.options.EnvFile))
	}
	for _, k := range envKeys {
		cmd.Add(env, "-e "+strconv.Quote(fmt.Sprintf("%s=%s", k, t.Environment[k])))
	}
	if t.Secrets.AnyTargetEnviroment() {
		cmd.Add(env, "--env-file="+secretEnvironmentPath(t, scalingGroup))
	}
	cmd.Add(env, fmt.Sprintf("-e SERVICE_NAME=%s", serviceName)) // Support registrator
	for _, cap := range t.Capabilities {
		cmd.Add(env, "--cap-add "+cap)
	}
	tcpLinkIndex := 0
	for _, l := range t.Links {
		targetName := l.Target.PrivateDomainName()
		if l.Type.IsHTTP() {
			cmd.Add(env, "--add-host")
			cmd.Add(env, fmt.Sprintf("%s:${COREOS_PRIVATE_IPV4}", targetName))
		} else {
			linkContainerName := fmt.Sprintf("%s-pr%d", t.ContainerName(scalingGroup), tcpLinkIndex)
			cmd.Add(env, fmt.Sprintf("--link %s:%s", linkContainerName, targetName))
			tcpLinkIndex++
		}
	}
	for _, arg := range t.LogDriver.CreateDockerLogArgs(e.options) {
		cmd.Add(env, arg)
	}
	for _, arg := range t.DockerArgs {
		cmd.Add(env, arg)
	}
	if t.User != "" {
		cmd.Add(env, fmt.Sprintf("--user %s", t.User))
	}

	cmd.Add(nil, image)
	if t.Type == "proxy" {
		cmd.Add(nil, "sleep 36500d")
	}
	for _, arg := range t.Args {
		cmd.Add(env, arg)
	}

	return cmd, nil
}
开发者ID:pulcy,项目名称:j2,代码行数:97,代码来源:docker_main.go

示例4: createVolumeUnitContainerName

// createVolumeUnitContainerName creates the name of the docker container that serves a volume with given index
func createVolumeUnitContainerName(t *jobs.Task, volIndex int, scalingGroup uint) string {
	return fmt.Sprintf("%s-vl%d", t.ContainerName(scalingGroup), volIndex)
}
开发者ID:pulcy,项目名称:j2,代码行数:4,代码来源:docker.go

示例5: secretsRootPath

// secretsRootPath returns the path of the root directory that will contain secret files for the given task.
func secretsRootPath(t *jobs.Task, scalingGroup uint) string {
	return filepath.Join(secretsPath, t.ContainerName(scalingGroup))
}
开发者ID:pulcy,项目名称:j2,代码行数:4,代码来源:docker_secrets.go


注:本文中的github.com/pulcy/j2/jobs.Task.ContainerName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。