// NewBuilder creates a new instance of DockerBuilder func NewBuilder(host string, tls bool, certPath string, registryURL string, auth *Authentication, brokerConf *pubsub.Config) (*Builder, error) { var client *docker.Client var err error if tls { cert := fmt.Sprintf("%s/cert.pem", certPath) key := fmt.Sprintf("%s/key.pem", certPath) ca := fmt.Sprintf("%s/ca.pem", certPath) client, err = docker.NewTLSClient(host, cert, key, ca) } else { client, err = docker.NewClient(host) } if err != nil { return nil, err } authConf := docker.AuthConfiguration{ Username: auth.Username, Password: auth.Password, Email: auth.Email, ServerAddress: registryURL, } log.Printf("[INFO] [docker] Check Docker authentication: %v", authConf) if client.AuthCheck(&authConf) != nil { return nil, ErrDockerAuthentication } msgChan := make(chan *pubsub.Message) pub, err := pubsub.NewBroker(brokerConf, msgChan) if err != nil { return nil, err } builder := &Builder{ Client: client, RegistryURL: registryURL, AuthConfig: authConf, BuildChan: make(chan *Project), PushChan: make(chan *Project), Broker: pub, MsgChan: msgChan, } log.Printf("[DEBUG] [docker] Creating Docker builder : %#v", builder) env, err := builder.Client.Version() if err != nil { return nil, err } log.Printf("[INFO] [docker] %v", env) builder.Broker.Publish(pubsub.Channel, fmt.Sprintf("Docker: %v", env)) return builder, nil }
// NewPublisher creates a new IRC bot publisher func NewPublisher(config *Config, brokerConf *pubsub.Config, debug bool) (*Publisher, error) { msgChan := make(chan *pubsub.Message) sub, err := pubsub.NewBroker(brokerConf, msgChan) if err != nil { return nil, err } return &Publisher{ Config: &bot.Config{ Server: config.Server, Channels: []string{config.Channel}, User: config.Username, Nick: config.Nickname, Password: config.Password, UseTLS: true, Debug: debug, }, Broker: sub, MsgChan: msgChan, }, nil }