// publishContainer publishes the docker container to etcd.
762734
func (s *Server) publishContainer(container *docker.APIContainers, ttl time.Duration) {
	r := regexp.MustCompile(appNameRegex)
	for _, name := range container.Names {
		// HACK: remove slash from container name
		// see https://github.com/docker/docker/issues/7519
		containerName := name[1:]
		match := r.FindStringSubmatch(containerName)
		if match == nil {
			continue
		}
		appName := match[1]
		appPath := fmt.Sprintf("%s/%s", appName, containerName)
		keyPath := fmt.Sprintf("/deis/services/%s", appPath)
		for _, p := range container.Ports {
			var delay int
			var timeout int
			var err error
			// lowest port wins (docker sorts the ports)
			// TODO (bacongobbler): support multiple exposed ports
			port := strconv.Itoa(int(p.PublicPort))
			hostAndPort := s.host + ":" + port
			if s.IsPublishableApp(containerName) && s.IsPortOpen(hostAndPort) {
				configKey := fmt.Sprintf("/deis/config/%s/", appName)
				// check if the user specified a healthcheck URL
				healthcheckURL := s.getEtcd(configKey + "healthcheck_url")
				initialDelay := s.getEtcd(configKey + "healthcheck_initial_delay")
				if initialDelay != "" {
					delay, err = strconv.Atoi(initialDelay)
					if err != nil {
						log.Println(err)
						delay = 0
					}
				} else {
					delay = 0
				}
				healthcheckTimeout := s.getEtcd(configKey + "healthcheck_timeout")
				if healthcheckTimeout != "" {
					timeout, err = strconv.Atoi(healthcheckTimeout)
					if err != nil {
						log.Println(err)
						timeout = 1
					}
				} else {
					timeout = 1
				}
				if healthcheckURL != "" {
					if !s.HealthCheckOK("http://"+hostAndPort+healthcheckURL, delay, timeout) {
						continue
					}
				}
				s.setEtcd(keyPath, hostAndPort, uint64(ttl.Seconds()))
				safeMap.Lock()
				safeMap.data[container.ID] = appPath
				safeMap.Unlock()
			}
			break
		}
	}
}
549347
func (d *stiDocker) UploadToContainer(fs fs.FileSystem, src, dest, container string) error {
	makeWorldWritable := func(writer io.Writer) s2itar.Writer {
		return s2itar.ChmodAdapter{Writer: tar.NewWriter(writer), NewFileMode: 0666, NewExecFileMode: 0666, NewDirMode: 0777}
	}

	return d.UploadToContainerWithTarWriter(fs, src, dest, container, makeWorldWritable)
}
537351
func (r *Runtime) ExecContainer(c *Container, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error {
	impl, err := r.RuntimeImpl(c)
	if err != nil {
		return err
	}

	return impl.ExecContainer(c, cmd, stdin, stdout, stderr, tty, resize)
}
319078
func (c *Client) UpdateContainer(id string, opts UpdateContainerOptions) error {
	resp, err := c.do("POST", fmt.Sprintf("/containers/"+id+"/update"), doOptions{
		data:      opts,
		forceJSON: true,
		context:   opts.Context,
	})
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	return nil
}
1174993
func (s *CreatePresetInput) SetContainer(v string) *CreatePresetInput {
	s.Container = &v
	return s
}
325053
func (Pipe) Publish(ctx *context.Context) error {
	if len(ctx.Config.S3) == 0 {
		return pipe.Skip("s3 section is not configured")
	}
	var g = semerrgroup.New(ctx.Parallelism)
	for _, conf := range ctx.Config.S3 {
		conf := conf
		g.Go(func() error {
			return upload(ctx, conf)
		})
	}
	return g.Wait()
}
1186266
func (f FPublisher) Publish(mts []plugin.Metric, cfg plugin.Config) error {
	file, err := cfg.GetString("file")
	if err != nil {
		return err
	}
	if val, err := cfg.GetBool("return_error"); err == nil && val {
		return errors.New("Houston we have a problem")
	}
	fileHandle, _ := os.Create(file)
	writer := bufio.NewWriter(fileHandle)
	defer fileHandle.Close()

	for _, m := range mts {
		fmt.Fprintf(writer, "%s|%v|%d|%s|%s|%s|%v|%v\n",
			m.Namespace.Strings(),
			m.Data,
			m.Version,
			m.Unit,
			m.Description,
			m.Timestamp,
			m.Tags,
			m.Config,
		)
	}
	writer.Flush()

	return nil
}
865555
func (s *NodeRangeProperty) SetContainer(v *ContainerProperties) *NodeRangeProperty {
	s.Container = v
	return s
}
273707
func (t *Transport) Publish(eventKind string, eventObject interface{}) error {
	event, err := newEvent(t.identity, eventKind, eventObject)
	if err != nil {
		return err
	}

	t.exchange.Publish(event)
	return nil
}
489298
func publish(pcc *PubControlClient, channel string, item *Item) error {
	export, err := item.Export()
	if err != nil {
		return err
	}
	export["channel"] = channel
	uri := ""
	auth := ""
	pcc.lock.Lock()
	uri = pcc.uri
	auth, err = pcc.generateAuthHeader()
	pcc.lock.Unlock()
	if err != nil {
		return err
	}
	err = pcc.pubCall(pcc, uri, auth, [](map[string]interface{}){export})
	if err != nil {
		return err
	}
	return nil
}
645507
func (fn LogPublisherFunc) Publish(ctx context.Context, message api.LogMessage) error {
	return fn(ctx, message)
}
554569
func (s *ResourceDetails) SetContainer(v *ContainerDetails) *ResourceDetails {
	s.Container = v
	return s
}
637104
func (r *Runtime) AttachContainer(c *Container, inputStream io.Reader, outputStream, errorStream io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error {
	impl, err := r.RuntimeImpl(c)
	if err != nil {
		return err
	}

	return impl.AttachContainer(c, inputStream, outputStream, errorStream, tty, resize)
}
32169
func (s *AttemptDetail) SetContainer(v *AttemptContainerDetail) *AttemptDetail {
	s.Container = v
	return s
}
987192
func (e *ClientExecutor) CopyContainer(container *docker.Container, excludes []string, copies ...imagebuilder.Copy) error {
	for _, c := range copies {
		// TODO: reuse source
		for _, src := range c.Src {
			glog.V(4).Infof("Archiving %s download=%t fromFS=%t from=%s", src, c.Download, c.FromFS, c.From)
			var r io.Reader
			var closer io.Closer
			var err error
			if len(c.From) > 0 {
				r, closer, err = e.archiveFromContainer(c.From, src, c.Dest)
			} else {
				r, closer, err = e.Archive(c.FromFS, src, c.Dest, c.Download, excludes)
			}
			if err != nil {
				return err
			}

			glog.V(5).Infof("Uploading to %s at %s", container.ID, c.Dest)
			if glog.V(6) {
				logArchiveOutput(r, "Archive file for %s")
			}
			err = e.Client.UploadToContainer(container.ID, docker.UploadToContainerOptions{
				InputStream: r,
				Path:        "/",
			})
			if err := closer.Close(); err != nil {
				glog.Errorf("Error while closing stream container copy stream %s: %v", container.ID, err)
			}
			if err != nil {
				return err
			}
		}
	}
	return nil
}
19217
func NewPublisher(etcdHost string, etcdPort int, etcdPath string, publishInterval int,
	publishTTL int, logHost string, logPort int) (*Publisher, error) {
	etcdClient := etcd.NewClient([]string{fmt.Sprintf("http://%s:%d", etcdHost, etcdPort)})
	ticker := time.NewTicker(time.Duration(publishInterval) * time.Second)
	return &Publisher{
		etcdClient: etcdClient,
		etcdPath:   etcdPath,
		publishTTL: uint64(time.Duration(publishTTL) * time.Second),
		logHost:    logHost,
		logPort:    logPort,
		ticker:     ticker,
	}, nil
}
1330008
func (p *Pod) AddContainer(container *PodContainer) *Pod {
	p.Containers = append(p.Containers, container)
	return p
}