Esempio n. 1
0
File: pod.go Progetto: Ablu/drone
// Pod transforms the containers in the Yaml to use Pod networking, where every
// container shares the localhost connection.
func Pod(c *yaml.Config) error {

	rand := base64.RawURLEncoding.EncodeToString(
		securecookie.GenerateRandomKey(8),
	)

	ambassador := &yaml.Container{
		ID:          fmt.Sprintf("drone_ambassador_%s", rand),
		Name:        "ambassador",
		Image:       "busybox:latest",
		Detached:    true,
		Entrypoint:  []string{"/bin/sleep"},
		Command:     []string{"86400"},
		Volumes:     []string{c.Workspace.Path, c.Workspace.Base},
		Environment: map[string]string{},
	}
	network := fmt.Sprintf("container:%s", ambassador.ID)

	var containers []*yaml.Container
	containers = append(containers, c.Pipeline...)
	containers = append(containers, c.Services...)

	for _, container := range containers {
		container.VolumesFrom = append(container.VolumesFrom, ambassador.ID)
		if container.Network == "" {
			container.Network = network
		}
	}

	c.Services = append([]*yaml.Container{ambassador}, c.Services...)
	return nil
}
Esempio n. 2
0
// Clone transforms the Yaml to include a clone step.
func Clone(c *yaml.Config, plugin string) error {
	switch plugin {
	case "", "git":
		plugin = "plugins/git:latest"
	case "hg":
		plugin = "plugins/hg:latest"
	}

	for _, p := range c.Pipeline {
		if p.Name == clone {
			if p.Image == "" {
				p.Image = plugin
			}
			return nil
		}
	}

	s := &yaml.Container{
		Image: plugin,
		Name:  clone,
	}

	c.Pipeline = append([]*yaml.Container{s}, c.Pipeline...)
	return nil
}
Esempio n. 3
0
// Pod transforms the containers in the Yaml to use Pod networking, where every
// container shares the localhost connection.
func Pod(c *yaml.Config, platform string) error {

	rand := base64.RawURLEncoding.EncodeToString(
		securecookie.GenerateRandomKey(8),
	)

	// choose the ambassador configuration based on os and architecture
	conf, ok := lookupAmbassador[platform]
	if !ok {
		conf = defaultAmbassador
	}

	ambassador := &yaml.Container{
		ID:          fmt.Sprintf("drone_ambassador_%s", rand),
		Name:        "ambassador",
		Image:       conf.image,
		Detached:    true,
		Entrypoint:  conf.entrypoint,
		Command:     conf.command,
		Volumes:     []string{c.Workspace.Path, c.Workspace.Base},
		Environment: map[string]string{},
	}
	network := fmt.Sprintf("container:%s", ambassador.ID)

	var containers []*yaml.Container
	containers = append(containers, c.Pipeline...)
	containers = append(containers, c.Services...)

	for _, container := range containers {
		container.VolumesFrom = append(container.VolumesFrom, ambassador.ID)
		if container.Network == "" {
			container.Network = network
		}
	}

	c.Services = append([]*yaml.Container{ambassador}, c.Services...)
	return nil
}
Esempio n. 4
0
// WorkspaceTransform transforms ...
func WorkspaceTransform(c *yaml.Config, base, path string) error {
	if c.Workspace == nil {
		c.Workspace = &yaml.Workspace{}
	}

	if c.Workspace.Base == "" {
		c.Workspace.Base = base
	}
	if c.Workspace.Path == "" {
		c.Workspace.Path = path
	}
	if !filepath.IsAbs(c.Workspace.Path) {
		c.Workspace.Path = filepath.Join(
			c.Workspace.Base,
			c.Workspace.Path,
		)
	}

	for _, p := range c.Pipeline {
		p.WorkingDir = c.Workspace.Path
	}
	return nil
}