// NewEnv returns a new Docker engine from the DOCKER_HOST and DOCKER_CERT_PATH // environment variables. func NewEnv() (runner.Engine, error) { config, err := dockerclient.TLSConfigFromCertPath(dockerCert) if err == nil && dockerTLS != "1" { config.InsecureSkipVerify = true } client, err := dockerclient.NewDockerClient(dockerHost, config) if err != nil { return nil, err } return New(client), nil }
// New returns a new Docker engine from the provided DOCKER_HOST and // DOCKER_CERT_PATH environment variables. func New(host, cert string, tls bool) (build.Engine, error) { config, err := dockerclient.TLSConfigFromCertPath(cert) if err == nil && tls { config.InsecureSkipVerify = true } client, err := dockerclient.NewDockerClient(host, config) if err != nil { return nil, err } return NewClient(client), nil }
func start(c *cli.Context) { // debug level if requested by user if c.Bool("debug") { logrus.SetLevel(logrus.DebugLevel) } else { logrus.SetLevel(logrus.WarnLevel) } client := client.NewClientToken( c.String("drone-server"), c.String("drone-token"), ) tls, err := dockerclient.TLSConfigFromCertPath(c.String("docker-cert-path")) if err == nil { tls.InsecureSkipVerify = c.Bool("docker-tls-verify") } docker, err := dockerclient.NewDockerClient(c.String("docker-host"), tls) if err != nil { logrus.Fatal(err) } var wg sync.WaitGroup for i := 0; i < c.Int("docker-max-procs"); i++ { wg.Add(1) go func() { r := pipeline{ drone: client, docker: docker, config: config{ whitelist: c.StringSlice("whitelist"), namespace: c.String("namespace"), privileged: c.StringSlice("privileged"), netrc: c.StringSlice("netrc-plugin"), pull: c.Bool("pull"), }, } for { if err := r.run(); err != nil { dur := c.Duration("backoff") logrus.Warnf("reconnect in %v. %s", dur, err.Error()) time.Sleep(dur) } } }() } wg.Wait() }
func start(c *cli.Context) { // debug level if requested by user if c.Bool("debug") { logrus.SetLevel(logrus.DebugLevel) } else { logrus.SetLevel(logrus.WarnLevel) } var accessToken string if c.String("drone-secret") != "" { secretToken := c.String("drone-secret") accessToken, _ = token.New(token.AgentToken, "").Sign(secretToken) } else { accessToken = c.String("drone-token") } logrus.Infof("Connecting to %s with token %s", c.String("drone-server"), accessToken, ) client := client.NewClientToken( c.String("drone-server"), accessToken, ) tls, err := dockerclient.TLSConfigFromCertPath(c.String("docker-cert-path")) if err == nil { tls.InsecureSkipVerify = c.Bool("docker-tls-verify") } docker, err := dockerclient.NewDockerClient(c.String("docker-host"), tls) if err != nil { logrus.Fatal(err) } go func() { for { if err := client.Ping(); err != nil { logrus.Warnf("unable to ping the server. %s", err.Error()) } time.Sleep(c.Duration("ping")) } }() var wg sync.WaitGroup for i := 0; i < c.Int("docker-max-procs"); i++ { wg.Add(1) go func() { r := pipeline{ drone: client, docker: docker, config: config{ platform: c.String("docker-os") + "/" + c.String("docker-arch"), timeout: c.Duration("timeout"), namespace: c.String("namespace"), privileged: c.StringSlice("privileged"), pull: c.BoolT("pull"), logs: int64(c.Int("max-log-size")) * 1000000, }, } for { if err := r.run(); err != nil { dur := c.Duration("backoff") logrus.Warnf("reconnect in %v. %s", dur, err.Error()) time.Sleep(dur) } } }() } handleSignals() wg.Wait() }
func start(c *cli.Context) { log := redlog.New(os.Stderr) log.SetLevel(0) logger.SetLogger(log) // debug level if requested by user if c.Bool("debug") { logrus.SetLevel(logrus.DebugLevel) log.SetLevel(1) } else { logrus.SetLevel(logrus.WarnLevel) } var accessToken string if c.String("drone-secret") != "" { // secretToken := c.String("drone-secret") accessToken = c.String("drone-secret") // accessToken, _ = token.New(token.AgentToken, "").Sign(secretToken) } else { accessToken = c.String("drone-token") } logger.Noticef("connecting to server %s", c.String("drone-server")) server := strings.TrimRight(c.String("drone-server"), "/") tls, err := dockerclient.TLSConfigFromCertPath(c.String("docker-cert-path")) if err == nil { tls.InsecureSkipVerify = c.Bool("docker-tls-verify") } docker, err := dockerclient.NewDockerClient(c.String("docker-host"), tls) if err != nil { logrus.Fatal(err) } var client *stomp.Client handler := func(m *stomp.Message) { running.Add(1) defer func() { running.Done() client.Ack(m.Ack) }() r := pipeline{ drone: client, docker: docker, config: config{ platform: c.String("docker-os") + "/" + c.String("docker-arch"), timeout: c.Duration("timeout"), namespace: c.String("namespace"), privileged: c.StringSlice("privileged"), pull: c.BoolT("pull"), logs: int64(c.Int("max-log-size")) * 1000000, }, } work := new(model.Work) m.Unmarshal(work) r.run(work) } handleSignals() backoff := c.Duration("backoff") for { // dial the drone server to establish a TCP connection. client, err = stomp.Dial(server) if err != nil { logger.Warningf("connection failed, retry in %v. %s", backoff, err) <-time.After(backoff) continue } opts := []stomp.MessageOption{ stomp.WithCredentials("x-token", accessToken), } // initialize the stomp session and authenticate. if err = client.Connect(opts...); err != nil { logger.Warningf("session failed, retry in %v. %s", backoff, err) <-time.After(backoff) continue } opts = []stomp.MessageOption{ stomp.WithAck("client"), stomp.WithPrefetch( c.Int("docker-max-procs"), ), } if filter := c.String("filter"); filter != "" { opts = append(opts, stomp.WithSelector(filter)) } // subscribe to the pending build queue. client.Subscribe("/queue/pending", stomp.HandlerFunc(func(m *stomp.Message) { go handler(m) // HACK until we a channel based Subscribe implementation }), opts...) logger.Noticef("connection established, ready to process builds.") <-client.Done() logger.Warningf("connection interrupted, attempting to reconnect.") } }