Exemplo n.º 1
0
func NewDockerClient(context string) (*DockerRuntime, error) {
	Docker := new(DockerRuntime)
	Docker.Context = context
	Docker.Debug = dbg.Debug("Docker Runtime")
	Docker.Debug("Configuring Docker Runtime")
	tlsConfig := &tls.Config{}
	Docker.Builded.Results = make(map[string]chan bool)
	Docker.Started.Results = make(map[string]chan bool)
	Docker.Verified.Results = make(map[string]chan bool)
	var err error

	if os.Getenv("DOCKER_TLS_VERIFY") != "" && os.Getenv("DOCKER_TLS_VERIFY") != "0" {
		caFile := os.Getenv("DOCKER_CERT_PATH") + "/ca.pem"
		certFile := os.Getenv("DOCKER_CERT_PATH") + "/cert.pem"
		keyFile := os.Getenv("DOCKER_CERT_PATH") + "/key.pem"

		cert, _ := tls.LoadX509KeyPair(certFile, keyFile)
		pemCerts, _ := ioutil.ReadFile(caFile)

		tlsConfig.RootCAs = x509.NewCertPool()
		tlsConfig.ClientAuth = tls.RequireAndVerifyClientCert

		tlsConfig.Certificates = []tls.Certificate{cert}

		tlsConfig.RootCAs.AppendCertsFromPEM(pemCerts)
	} else {
		tlsConfig = nil
	}

	if os.Getenv("DOCKER_HOST") != "" {
		Docker.Api, err = DockerAPI.NewDockerClient(os.Getenv("DOCKER_HOST"), tlsConfig)
		if err != nil {
			fmt.Println(err)
			return nil, err
		}
		Docker.Debug("Ready Docker Runtime")
	} else {
		err := fmt.Errorf("DOCKER_HOST empty or not set")
		Docker.Debug("FATAL: %s", err)
		return nil, err
	}
	return Docker, nil
}
Exemplo n.º 2
0
package fs

import (
	"fmt"
	"io/ioutil"
	"os"
	"path"
	"path/filepath"
	"strings"

	"github.com/royvandewater/etcdsync/keyvalue"
	De "github.com/tj/go-debug"
)

var debug = De.Debug("etcdsync:fs")

// FS and represents the data on the file system
type FS struct {
	path string
}

// New creates a FS from the local etcd filesystem
func New(path string) *FS {
	return &FS{path}
}

// KeyValuePairs returns a list key value pairs
// recursively under the namespace. If includeDirs
// is true, then the results will include the directories
func (fs *FS) KeyValuePairs(namespace string, includeDirs bool) ([]keyvalue.KeyValue, error) {
	var keyValuePairs []keyvalue.KeyValue
Exemplo n.º 3
0
//	 5. TODO:  Test healthcheck. (maestre) (only http 200 checks)
//   6. TODO:  If the healthcheck works register container at the given LB. (cloudy)

import ( // standard deps
	"flag"
	"fmt"
	"os"
)

import ( // internal or vendors
	dbg "github.com/tj/go-debug"
	"maestre"
)

var (
	debug      = dbg.Debug("main")
	runtime    = flag.String("runtime", "docker", "Sets the container runtime to be used, defaults to docker")
	command    = flag.String("cmd", "", "Tell cloudme what step to run")
	configFile = flag.String("config", "", "Path to the config file to use")
	secrets    = flag.String("secret", "", "Path to the access config file to use")
)

// Init Validates the basic params cmd is empty then fails then it will initialize the runtime to be used (docker by default)
func Init() {
	flag.Parse()
	debug("Start Params: cmd: %s, config: %s, secrets: %s", *command, *configFile, *secrets)
	if *command == "" {
		os.Exit(1)
	}

	if *configFile == "" {
Exemplo n.º 4
0
	"net/url"
	"os"
	"os/signal"
	"strings"
	"syscall"
	"time"

	"github.com/codegangsta/cli"
	"github.com/coreos/go-semver/semver"
	"github.com/fatih/color"
	"github.com/octoblu/register-traefik/etcd"
	"github.com/octoblu/register-traefik/healthchecker"
	De "github.com/tj/go-debug"
)

var debug = De.Debug("register-traefik:main")

func main() {
	app := cli.NewApp()
	app.Name = "register-traefik"
	app.Version = version()
	app.Action = run
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:   "etcd-uri, e",
			EnvVar: "REGISTER_TRAEFIK_ETCD_URI",
			Usage:  "Etcd URI to register traefik server to",
		},
		cli.StringFlag{
			Name:   "server-key, s",
			EnvVar: "REGISTER_TRAEFIK_SERVER_KEY",
Exemplo n.º 5
0
	"io"
	"io/ioutil"
	"net/http"
	"net/url"
	"reflect"
	"time"

	"github.com/taskcluster/httpbackoff"
	hawk "github.com/tent/hawk-go"
	D "github.com/tj/go-debug"
)

var (
	// Used for logging based on DEBUG environment variable
	// See github.com/tj/go-debug
	debug = D.Debug("index")
)

// apiCall is the generic REST API calling method which performs all REST API
// calls for this library.  Each auto-generated REST API method simply is a
// wrapper around this method, calling it with specific specific arguments.
func (myIndex *Index) apiCall(payload interface{}, method, route string, result interface{}) (interface{}, *CallSummary) {
	callSummary := new(CallSummary)
	callSummary.HttpRequestObject = payload
	var jsonPayload []byte
	jsonPayload, callSummary.Error = json.Marshal(payload)
	if callSummary.Error != nil {
		return result, callSummary
	}
	callSummary.HttpRequestBody = string(jsonPayload)
Exemplo n.º 6
0
package sse

import (
	"net/http"

	dbg "github.com/tj/go-debug"
)

var (
	debug = dbg.Debug("hub/sse")
)

type Hub struct {
	connections map[*Connection]bool
	broadcast   chan []byte
	register    chan *Connection
	unregister  chan *Connection

	RegisterFunc   func(*Connection)
	UnregisterFunc func(*Connection)
}

func NewHub() *Hub {
	hub := &Hub{
		connections: make(map[*Connection]bool),
		broadcast:   make(chan []byte),
		register:    make(chan *Connection),
		unregister:  make(chan *Connection),
	}

	go hub.Run()
Exemplo n.º 7
0
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"

	"github.com/codegangsta/cli"
	"github.com/coreos/go-semver/semver"
	"github.com/dustin/go-humanize"
	"github.com/fatih/color"
	De "github.com/tj/go-debug"
)

var debug = De.Debug("add-bytes:main")

func main() {
	app := cli.NewApp()
	app.Name = "add-bytes"
	app.Usage = "cat file | add-bytes"
	app.Version = version()
	app.Action = run
	app.Flags = []cli.Flag{}
	app.Run(os.Args)
}

func run(context *cli.Context) {
	totalSize := uint64(0)
	scanner := bufio.NewScanner(os.Stdin)
Exemplo n.º 8
0
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"net/url"

	dg "github.com/tj/go-debug"
)

const (
	acceptHeader = "application/json"
	version      = 1
)

var (
	hd             = dg.Debug("hatena")
	defaultBaseURL = fmt.Sprintf("http://api.b.hatena.ne.jp/%d", version)
)

type Client struct {
	client    *http.Client
	BaseURL   *url.URL
	UserAgent string
	BookMarks *BookmarksService
	Entries   *EntriesService
	Tags      *TagsService
	Users     *UsersService
}

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error) {
	rel, err := url.Parse(urlStr)
Exemplo n.º 9
0
Arquivo: vips.go Projeto: greut/bimg
import "C"

import (
	"errors"
	"math"
	"os"
	"runtime"
	"strings"
	"sync"
	"unsafe"

	d "github.com/tj/go-debug"
)

// debug is internally used to
var debug = d.Debug("bimg")

// VipsVersion exposes the current libvips semantic version
const VipsVersion = string(C.VIPS_VERSION)

// VipsMajorVersion exposes the current libvips major version number
const VipsMajorVersion = int(C.VIPS_MAJOR_VERSION)

// VipsMinorVersion exposes the current libvips minor version number
const VipsMinorVersion = int(C.VIPS_MINOR_VERSION)

const (
	maxCacheMem  = 100 * 1024 * 1024
	maxCacheSize = 500
)
Exemplo n.º 10
0
	"path/filepath"
	"strconv"
	"strings"
	"time"

	docopt "github.com/docopt/docopt-go"
	"github.com/taskcluster/httpbackoff"
	"github.com/taskcluster/taskcluster-client-go/queue"
	D "github.com/tj/go-debug"
	"github.com/xeipuuv/gojsonschema"
)

var (
	// Used for logging based on DEBUG environment variable
	// See github.com/tj/go-debug
	debug = D.Debug("generic-worker")
	// General platform independent user settings, such as home directory, username...
	// Platform specific data should be managed in plat_<platform>.go files
	TaskUser OSUser
	// Queue is the object we will use for accessing queue api. See
	// http://docs.taskcluster.net/queue/api-docs/
	Queue *queue.Auth
	// See SignedURLsManager() for more information:
	// signedURsRequestChan is the channel you can pass a channel to, to get
	// back signed urls from the Task Cluster Queue, for querying Azure queues.
	signedURLsRequestChan chan chan *queue.PollTaskUrlsResponse
	// The *currently* one-and-only channel we request signedURLs to be written
	// to. In future we might require more channels to perform requests in
	// parallel, in which case we won't have a single global package var.
	signedURLsResponseChan chan *queue.PollTaskUrlsResponse
	// Channel to request task status updates to the TaskStatusHandler (from
Exemplo n.º 11
0
package hatena

import (
	"errors"
	"fmt"
	"net/url"

	dg "github.com/tj/go-debug"
)

const (
	bookmarkURL = "http://api.b.st-hatena.com/entry.count?url=%s"
)

var (
	bd = dg.Debug("boolmark")
)

type BookmarksService struct {
	client *Client
}

func (s *BookmarksService) Count(urlStr string) (count int, err error) {
	u, err := url.Parse(urlStr)
	if err != nil {
		return
	}

	reqURL := fmt.Sprintf(bookmarkURL, u)
	bd("reqURL %v", reqURL)
Exemplo n.º 12
0
	"io"
	"io/ioutil"
	"net/http"
	"net/url"
	"reflect"
	"time"

	"github.com/taskcluster/httpbackoff"
	hawk "github.com/tent/hawk-go"
	D "github.com/tj/go-debug"
)

var (
	// Used for logging based on DEBUG environment variable
	// See github.com/tj/go-debug
	debug = D.Debug("scheduler")
)

// apiCall is the generic REST API calling method which performs all REST API
// calls for this library.  Each auto-generated REST API method simply is a
// wrapper around this method, calling it with specific specific arguments.
func (myScheduler *Scheduler) apiCall(payload interface{}, method, route string, result interface{}) (interface{}, *CallSummary) {
	callSummary := new(CallSummary)
	callSummary.HttpRequestObject = payload
	var jsonPayload []byte
	jsonPayload, callSummary.Error = json.Marshal(payload)
	if callSummary.Error != nil {
		return result, callSummary
	}
	callSummary.HttpRequestBody = string(jsonPayload)
Exemplo n.º 13
0
	"io"
	"io/ioutil"
	"net/http"
	"net/url"
	"reflect"
	"time"

	"github.com/taskcluster/httpbackoff"
	hawk "github.com/tent/hawk-go"
	D "github.com/tj/go-debug"
)

var (
	// Used for logging based on DEBUG environment variable
	// See github.com/tj/go-debug
	debug = D.Debug("secrets")
)

// apiCall is the generic REST API calling method which performs all REST API
// calls for this library.  Each auto-generated REST API method simply is a
// wrapper around this method, calling it with specific specific arguments.
func (mySecrets *Secrets) apiCall(payload interface{}, method, route string, result interface{}) (interface{}, *CallSummary) {
	callSummary := new(CallSummary)
	callSummary.HttpRequestObject = payload
	var jsonPayload []byte
	jsonPayload, callSummary.Error = json.Marshal(payload)
	if callSummary.Error != nil {
		return result, callSummary
	}
	callSummary.HttpRequestBody = string(jsonPayload)
Exemplo n.º 14
0
	"io"
	"io/ioutil"
	"net/http"
	"net/url"
	"reflect"
	"time"

	"github.com/taskcluster/httpbackoff"
	hawk "github.com/tent/hawk-go"
	D "github.com/tj/go-debug"
)

var (
	// Used for logging based on DEBUG environment variable
	// See github.com/tj/go-debug
	debug = D.Debug("auth")
)

// apiCall is the generic REST API calling method which performs all REST API
// calls for this library.  Each auto-generated REST API method simply is a
// wrapper around this method, calling it with specific specific arguments.
func (myAuth *Auth) apiCall(payload interface{}, method, route string, result interface{}) (interface{}, *CallSummary) {
	callSummary := new(CallSummary)
	callSummary.HttpRequestObject = payload
	var jsonPayload []byte
	jsonPayload, callSummary.Error = json.Marshal(payload)
	if callSummary.Error != nil {
		return result, callSummary
	}
	callSummary.HttpRequestBody = string(jsonPayload)
Exemplo n.º 15
0
package bignum

import (
	"github.com/bmizerany/assert"
	"github.com/k0kubun/pp"
	godebug "github.com/tj/go-debug"
)

var print = pp.Print
var printf = pp.Printf
var println = pp.Println
var debug = godebug.Debug("bigNum")
var equal = assert.Equal
Exemplo n.º 16
0
package deployer

import (
	"encoding/json"
	"errors"
	"fmt"
	"net/http"
	"strings"
	"time"

	"github.com/garyburd/redigo/redis"
	De "github.com/tj/go-debug"
)

var debug = De.Debug("governator:deployer")

// Deployer watches a redis queue
// and deploys services using Etcd
type Deployer struct {
	etcdClient     EtcdClient
	redisConn      redis.Conn
	queueName      string
	deployStateUri string
	cluster        string
}

// RequestMetadata is the metadata of the request
type RequestMetadata struct {
	EtcdDir   string `json:"etcdDir"`
	DockerURL string `json:"dockerUrl"`
}
	"io"
	"io/ioutil"
	"net/http"
	"net/url"
	"reflect"
	"time"

	"github.com/taskcluster/httpbackoff"
	hawk "github.com/tent/hawk-go"
	D "github.com/tj/go-debug"
)

var (
	// Used for logging based on DEBUG environment variable
	// See github.com/tj/go-debug
	debug = D.Debug("awsprovisioner")
)

// apiCall is the generic REST API calling method which performs all REST API
// calls for this library.  Each auto-generated REST API method simply is a
// wrapper around this method, calling it with specific specific arguments.
func (awsProvisioner *AwsProvisioner) apiCall(payload interface{}, method, route string, result interface{}) (interface{}, *CallSummary) {
	callSummary := new(CallSummary)
	callSummary.HttpRequestObject = payload
	var jsonPayload []byte
	jsonPayload, callSummary.Error = json.Marshal(payload)
	if callSummary.Error != nil {
		return result, callSummary
	}
	callSummary.HttpRequestBody = string(jsonPayload)
Exemplo n.º 18
0
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/codegangsta/cli"
	"github.com/coreos/go-semver/semver"
	"github.com/fatih/color"
	"github.com/garyburd/redigo/redis"
	"github.com/octoblu/go-simple-etcd-client/etcdclient"
	"github.com/octoblu/governator/deployer"
	De "github.com/tj/go-debug"
)

var debug = De.Debug("governator:main")

func main() {
	app := cli.NewApp()
	app.Name = "governator"
	app.Version = version()
	app.Action = run
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:   "etcd-uri, e",
			EnvVar: "GOVERNATOR_ETCD_URI",
			Usage:  "Etcd server to deploy to",
		},
		cli.StringFlag{
			Name:   "redis-uri, r",
			EnvVar: "GOVERNATOR_REDIS_URI",
Exemplo n.º 19
0
package etcd

import (
	"github.com/octoblu/go-simple-etcd-client/etcdclient"
	"github.com/royvandewater/etcdsync/keyvalue"
	De "github.com/tj/go-debug"
)

var debug = De.Debug("etcdsync:etcd")

// Etcd and represents the data in a remote etcd server
type Etcd struct {
	client etcdclient.EtcdClient
}

// ClientDial dials up an etcd client
type ClientDial func(url string) (etcdclient.EtcdClient, error)

// Dial creates a Etcd from the remote etcd server. Leave clientDial
// nil to use the default etcd client
func Dial(etcdURI string, clientDial ClientDial) (*Etcd, error) {
	if clientDial == nil {
		clientDial = etcdclient.Dial
	}
	client, err := clientDial(etcdURI)
	return &Etcd{client}, err
}

// KeyValuePairs returns a list key value pairs
// recursively under the namespace
func (etcd *Etcd) KeyValuePairs(namespace string) ([]keyvalue.KeyValue, error) {
Exemplo n.º 20
0
	"io"
	"io/ioutil"
	"net/http"
	"net/url"
	"reflect"
	"time"

	"github.com/taskcluster/httpbackoff"
	hawk "github.com/tent/hawk-go"
	D "github.com/tj/go-debug"
)

var (
	// Used for logging based on DEBUG environment variable
	// See github.com/tj/go-debug
	debug = D.Debug("purgecache")
)

// apiCall is the generic REST API calling method which performs all REST API
// calls for this library.  Each auto-generated REST API method simply is a
// wrapper around this method, calling it with specific specific arguments.
func (purgeCache *PurgeCache) apiCall(payload interface{}, method, route string, result interface{}) (interface{}, *CallSummary) {
	callSummary := new(CallSummary)
	callSummary.HttpRequestObject = payload
	var jsonPayload []byte
	jsonPayload, callSummary.Error = json.Marshal(payload)
	if callSummary.Error != nil {
		return result, callSummary
	}
	callSummary.HttpRequestBody = string(jsonPayload)