示例#1
0
文件: build.go 项目: ibmendoza/dgtk
func (b *Build) connectToDockerHost() (e error) {
	if b.client != nil {
		return nil
	}

	if b.DockerHostUser == "" {
		port := b.DockerPort
		if port == 0 {
			port = 4243
		}
		b.client = dockerclient.New(fmt.Sprintf("http://%s:%d", b.DockerHost, port))
		return nil
	}
	c := gossh.New(b.DockerHost, b.DockerHostUser)
	c.SetPassword(b.DockerHostPassword)
	con, err := c.Connection()
	if err != nil {
		return err
	}
	t := &http.Transport{}
	t.Dial = con.Dial
	cl := &http.Client{Transport: t}
	dc := dockerclient.New("http://" + b.DockerHost + ":4243")
	dc.Client = cl
	b.client = dc
	return nil
}
示例#2
0
func NewContainerManager(s3Bucket, s3Prefix, appname string, proxy *Proxy, cfgFile string, rport int) (*ContainerManager, error) {
	cm := &ContainerManager{
		S3Bucket:     s3Bucket,
		S3Prefix:     s3Prefix,
		AppName:      appname,
		Proxy:        proxy,
		RegistryPort: rport,
		s3client:     s3.NewFromEnv(),
		containers:   map[string]int{},
		containerEnv: map[string]string{},
	}

	if cfgFile != "" {
		err := cm.readConfigFile(cfgFile)
		if err != nil {
			return nil, err
		}
	}

	cm.dockerHost = dockerclient.New("http://127.0.0.1:4243")
	return cm, func() error {
		err := cm.runLatest()
		switch err {
		case nil, ErrorLaunchConfigNotFound:
			return nil
		default:
			return err
		}
	}()
}