示例#1
0
func main() {
	v := struct {
		Path  string `json:"path"`
		Depth int    `json:"depth"`
	}{}

	c := new(plugin.Clone)
	plugin.Param("clone", c)
	plugin.Param("vargs", &v)
	if err := plugin.Parse(); err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	if v.Depth == 0 {
		v.Depth = 50
	}
	if len(v.Path) != 0 {
		c.Dir = filepath.Join("/drone/src", v.Path)
	}

	err := os.MkdirAll(c.Dir, 0777)
	if err != nil {
		fmt.Printf("Error creating directory %s. %s\n", c.Dir, err)
		os.Exit(2)
	}

	// generate the .netrc file
	if err := writeNetrc(c); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(3)
	}

	// write the rsa private key if provided
	if err := writeKey(c); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(4)
	}

	var cmds []*exec.Cmd
	if isPR(c) {
		cmds = append(cmds, clone(c))
		cmds = append(cmds, fetch(c))
		cmds = append(cmds, checkoutHead(c))
	} else {
		cmds = append(cmds, cloneBranch(c))
		cmds = append(cmds, checkoutSha(c))
	}

	for _, cmd := range cmds {
		cmd.Dir = c.Dir
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		trace(cmd)
		err := cmd.Run()
		if err != nil {
			os.Exit(1)
		}
	}
}
示例#2
0
func main() {
	log.SetFlags(0)
	plugin.Param("workspace", &workspace)
	plugin.Param("build", &build)
	plugin.Param("repo", &repo)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()
	sort.Strings(vargs.Gzip) // need for matchGzip

	// context for all clients
	ctx := context.Background()
	// GitHub client
	gts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: vargs.GitHubToken})
	client.ghub = github.NewClient(oauth2.NewClient(ctx, gts))
	// GCS client
	auth, err := google.JWTConfigFromJSON([]byte(vargs.AuthKey), storage.ScopeFullControl)
	if err != nil {
		fatalf("auth: %v", err)
	}
	tsrc := auth.TokenSource(ctx)
	client.gcs, err = storage.NewClient(ctx, cloud.WithTokenSource(auth.TokenSource(ctx)))
	if err != nil {
		fatalf("storage client: %v", err)
	}
	// http client with service account authorization
	client.http = oauth2.NewClient(ctx, tsrc)

	run()
	if ecode != 0 {
		msg := fmt.Sprintf("exited with code %d", ecode)
		updateStatus("error", msg, stagingURL)
	}
	os.Exit(ecode)
}
示例#3
0
func main() {
	c := new(plugin.Clone)
	v := new(Rsync)
	plugin.Param("clone", c)
	plugin.Param("vargs", v)
	plugin.Parse()

	// write the rsa private key if provided
	if err := writeKey(c); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	// create the rsync command
	rs := buildRsync(v)
	rs.Dir = c.Dir
	rs.Stderr = os.Stderr
	rs.Stdout = os.Stdout
	trace(rs)
	err := rs.Run()
	if err != nil {
		os.Exit(1)
		return
	}

	// and execute

	// create remote command script

	// and execute
}
示例#4
0
func main() {
	var repo = plugin.Repo{}
	var build = plugin.Build{}
	var vargs = struct {
		Urls []string `json:"urls"`
	}{}

	plugin.Param("repo", &repo)
	plugin.Param("build", &build)
	plugin.Param("vargs", &vargs)
	plugin.Parse()

	// post build and repo data to webhook urls
	data := struct {
		Repo  plugin.Repo  `json:"repo"`
		Build plugin.Build `json:"build"`
	}{repo, build}

	payload, _ := json.Marshal(&data)

	for _, url := range vargs.Urls {
		resp, _ := http.Post(url, "application/json", bytes.NewBuffer(payload))
		resp.Body.Close()
	}
}
示例#5
0
func main() {
	fmt.Println("starting drone-cowpoke...")

	workspace := plugin.Workspace{}
	vargs := Cowpoke{}

	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()

	if len(vargs.Url) == 0 {
		fmt.Println("no cowpoke url was specified")
		os.Exit(1)
	}

	if vargs.Port == 0 {
		fmt.Println("no cowpoke port was specified")
		os.Exit(1)
	}

	fmt.Println("loading image data from", filepath.Join(workspace.Path, ".docker.json"))
	image := GetImageName(filepath.Join(workspace.Path, ".docker.json"))

	if len(image) <= 0 {
		fmt.Println("image load failed from .docker.json")
		os.Exit(1)
	}

	var cowpokeUrl = fmt.Sprintf("%s:%d/api/environment/", vargs.Url, vargs.Port)
	fmt.Println("cowpoke url set to:", cowpokeUrl)
	fmt.Println(".docker.json value being posted:", image)
	ExecutePut(cowpokeUrl + url.QueryEscape(image))

	fmt.Println("finished drone-cowpoke.")
}
示例#6
0
func main() {
	log.SetFlags(0)
	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()

	script := strings.Join(vargs.Script, "\n")
	if err := ioutil.WriteFile(scriptName, []byte(script), 0644); err != nil {
		log.Fatalf("WriteFile(%q): %v", script, err)
	}

	c := vargs.Cmd
	if c == "" {
		c = defaultCmd
	}
	cmd := exec.Command(c, scriptName)
	cmd.Dir = workspace.Path
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	cmd.Env = append(os.Environ(), vargs.Env...)

	fmt.Println("$", strings.Join(cmd.Args, " "))
	if err := cmd.Run(); err != nil {
		log.Fatal(err)
	}
}
示例#7
0
func main() {
	var repo = plugin.Repo{}
	var build = plugin.Build{}
	var vargs = struct {
		Urls []string `json:"urls"`
	}{}

	plugin.Param("repo", &repo)
	plugin.Param("build", &build)
	plugin.Param("vargs", &vargs)
	plugin.Parse()

	// data structure
	data := struct {
		Repo  plugin.Repo  `json:"repo"`
		Build plugin.Build `json:"build"`
	}{repo, build}

	// json payload that will be posted
	payload, err := json.Marshal(&data)
	if err != nil {
		os.Exit(1)
	}

	// post payload to each url
	for _, url := range vargs.Urls {
		resp, err := http.Post(url, "application/json", bytes.NewBuffer(payload))
		if err != nil {
			os.Exit(1)
		}
		resp.Body.Close()
	}
}
示例#8
0
func main() {
	fmt.Printf("Drone Terraform Plugin built from %s\n", buildCommit)

	workspace := plugin.Workspace{}
	vargs := terraform{}

	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()

	if vargs.RoleARN != "" {
		assumeRole(vargs.RoleARN)
	}

	var commands []*exec.Cmd
	remote := vargs.Remote
	if vargs.Cacert != "" {
		commands = append(commands, installCaCert(vargs.Cacert))
	}
	if remote.Backend != "" {
		commands = append(commands, deleteCache())
		commands = append(commands, remoteConfigCommand(remote))
	}
	commands = append(commands, getModules())
	commands = append(commands, planCommand(vargs.Vars, vargs.Parallelism))
	if !vargs.Plan {
		commands = append(commands, applyCommand(vargs.Parallelism))
	}
	commands = append(commands, deleteCache())

	for _, c := range commands {
		c.Env = os.Environ()
		c.Dir = workspace.Path
		if c.Dir == "" {
			wd, err := os.Getwd()
			if err == nil {
				c.Dir = wd
			}
		}
		if vargs.RootDir != "" {
			c.Dir = c.Dir + "/" + vargs.RootDir
		}
		c.Stdout = os.Stdout
		c.Stderr = os.Stderr
		if !vargs.Sensitive {
			trace(c)
		}

		err := c.Run()
		if err != nil {
			fmt.Println("Error!")
			fmt.Println(err)
			os.Exit(1)
		}
		fmt.Println("Command completed successfully")
	}

}
示例#9
0
func main() {
	workspace := plugin.Workspace{}
	vargs := S3{}

	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()

	// skip if AWS key or SECRET are empty. A good example for this would
	// be forks building a project. S3 might be configured in the source
	// repo, but not in the fork
	if len(vargs.Key) == 0 || len(vargs.Secret) == 0 {
		return
	}

	// make sure a default region is set
	if len(vargs.Region) == 0 {
		vargs.Region = "us-east-1"
	}

	// make sure a default access is set
	// let's be conservative and assume private
	if len(vargs.Access) == 0 {
		vargs.Access = "private"
	}

	// if the target starts with a "/" we need
	// to remove it, otherwise we might adding
	// a 3rd slash to s3://
	if strings.HasPrefix(vargs.Target, "/") {
		vargs.Target = vargs.Target[1:]
	}

	cmd := command(vargs)
	cmd.Env = os.Environ()
	if len(vargs.Key) > 0 {
		cmd.Env = append(cmd.Env, "AWS_ACCESS_KEY_ID="+vargs.Key)
	}
	if len(vargs.Secret) > 0 {
		cmd.Env = append(cmd.Env, "AWS_SECRET_ACCESS_KEY="+vargs.Secret)
	}
	cmd.Dir = workspace.Path
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	trace(cmd)

	// run the command and exit if failed.
	err := cmd.Run()
	if err != nil {
		os.Exit(1)
	}
}
示例#10
0
func main() {
	var vargs = struct {
		ReplicationControllers []string `json:replicationcontrollers`
		Services               []string `json:services`
		ApiServer              string   `json:apiserver`
		Token                  string   `json:token`
		Namespace              string   `json:namespace`
		Debug                  string   `json:debug`
		Webhook                string   `json:webhook`
		Source                 string   `json:source`
		WebHookToken           string   `json:webhook_token`
	}{}

	workspace := plugin.Workspace{}
	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)
	plugin.Parse()

	// Iterate over rcs and svcs
	for _, rc := range vargs.ReplicationControllers {
		artifact, err := readArtifactFromFile(workspace.Path, rc, vargs.ApiServer, vargs.Namespace)
		if err != nil {
			log.Panic(err)
			return
		}
		if b, _ := existsArtifact(artifact, vargs.Token); b {
			deleteArtifact(artifact, vargs.Token)
			time.Sleep(time.Second * 5)
		}
		createArtifact(artifact, vargs.Token)
	}
	for _, rc := range vargs.Services {
		artifact, err := readArtifactFromFile(workspace.Path, rc, vargs.ApiServer, vargs.Namespace)
		if err != nil {
			log.Panic(err)
			return
		}
		createArtifact(artifact, vargs.Token)
	}
	wh := &WebHook{
		Timestamp: makeTimestamp(),
		Images:    deployments,
		Namespace: vargs.Namespace,
		Source:    vargs.Source,
		Target:    vargs.ApiServer,
		Url:       vargs.Webhook,
		Token:     vargs.WebHookToken,
	}
	sendWebhook(wh)
}
示例#11
0
func main() {
	v := new(Params)
	r := new(plugin.Repo)
	b := new(plugin.Build)
	w := new(plugin.Workspace)
	plugin.Param("repo", r)
	plugin.Param("build", b)
	plugin.Param("workspace", w)
	plugin.Param("vargs", &v)
	plugin.MustParse()

	err := clone(r, b, w, v)
	if err != nil {
		os.Exit(1)
	}
}
示例#12
0
文件: main.go 项目: cedk/drone-hg
func main() {
	fmt.Printf("Drone Mercurial Plugin built at %s\n", buildDate)

	v := new(Params)
	r := new(plugin.Repo)
	b := new(plugin.Build)
	w := new(plugin.Workspace)
	plugin.Param("repo", r)
	plugin.Param("build", b)
	plugin.Param("workspace", w)
	plugin.Param("vargs", &v)
	plugin.MustParse()

	err := run(r, b, w, v)
	if err != nil {
		os.Exit(1)
	}
}
示例#13
0
func main() {
	fmt.Printf("Drone DockerHub Plugin built at %s\n", buildDate)

	vargs := DockerHub{}
	build := plugin.Build{}

	plugin.Param("vargs", &vargs)
	plugin.Param("build", &build)

	if err := plugin.Parse(); err != nil {
		println(err.Error())
		os.Exit(1)
	}

	endpoint := fmt.Sprintf("https://registry.hub.docker.com/u/%s/trigger/%s/", vargs.Repo, vargs.Token)
	values := DockerHubValues{SourceType: "Branch", SourceName: build.Branch}
	values_json, err := json.Marshal(values)

	req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(values_json))

	if err != nil {
		fmt.Println(re.ReplaceAllString(err.Error(), "${1}HIDDEN"))

		os.Exit(1)
	}

	req.Header.Set("Content-Type", "application/json")
	client := &http.Client{}

	var resp *http.Response
	err = try.Do(func(attempt int) (bool, error) {
		var err error

		resp, err = client.Do(req)
		return attempt < 5, err
	})

	if err != nil {
		fmt.Println(re.ReplaceAllString(err.Error(), "${1}HIDDEN"))

		os.Exit(1)
	}
	resp.Body.Close()
}
示例#14
0
func main() {
	log.SetFlags(0)
	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()
	sort.Strings(vargs.Gzip) // need for matchGzip

	auth, err := google.JWTConfigFromJSON([]byte(vargs.AuthKey), storage.ScopeFullControl)
	if err != nil {
		fatalf("auth: %v", err)
	}
	ctx := context.Background()
	client, err := storage.NewClient(ctx, cloud.WithTokenSource(auth.TokenSource(ctx)))
	if err != nil {
		fatalf("storage client: %v", err)
	}
	run(client)
	os.Exit(ecode)
}
示例#15
0
文件: main.go 项目: cheif/drone-slack
func main() {
	repo := plugin.Repo{}
	build := plugin.Build{}
	system := plugin.System{}
	vargs := Slack{}

	plugin.Param("build", &build)
	plugin.Param("repo", &repo)
	plugin.Param("system", &system)
	plugin.Param("vargs", &vargs)

	// parse the parameters
	if err := plugin.Parse(); err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	client.SetUrl(vargs.Webhook)

	// generate the Slack message
	msg := Message{}
	msg.Username = vargs.Username
	msg.Channel = vargs.Recipient

	if len(vargs.Recipient) != 0 {
		msg.Channel = Prepend("@", vargs.Recipient)
	} else {
		msg.Channel = Prepend("#", vargs.Channel)
	}

	attach := msg.NewAttachment()
	attach.Text = GetMessage(repo, build, system, vargs)
	attach.Fallback = GetFallback(&repo, &build)
	attach.Color = GetColor(&build)
	attach.MrkdwnIn = []string{"text", "fallback"}

	// sends the message
	if err := client.SendMessage(&msg); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
示例#16
0
文件: main.go 项目: thomasf/drone-mvn
func main() {
	testExpressions()
	workspace := plugin.Workspace{}
	repo := plugin.Repo{}
	build := plugin.Build{}
	vargs := mavendeploy.Maven{}

	plugin.Param("repo", &repo)
	plugin.Param("build", &build)
	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()

	vargs.WorkspacePath(workspace.Path)

	err := vargs.Publish()
	if err != nil {
		panic(err)
	}
}
func main() {
	fmt.Printf("Drone Google Cloud Storage Plugin built from %s\n", buildCommit)

	log.SetFlags(0)
	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()
	sort.Strings(vargs.Gzip) // need for matchGzip
	rand.Seed(time.Now().UnixNano())

	auth, err := google.JWTConfigFromJSON([]byte(vargs.AuthKey), storage.ScopeFullControl)
	if err != nil {
		fatalf("auth: %v", err)
	}
	ctx := context.Background()
	client, err := storage.NewClient(ctx, cloud.WithTokenSource(auth.TokenSource(ctx)))
	if err != nil {
		fatalf("storage client: %v", err)
	}
	run(client)
	os.Exit(ecode)
}
示例#18
0
func main() {
	workspace := plugin.Workspace{}
	build := plugin.Build{}
	vargs := Ansible{}

	plugin.Param("workspace", &workspace)
	plugin.Param("build", &build)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()

	vargs = setDefaults(vargs)

	// write the rsa private key
	if err := writeKey(workspace); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// write ansible configuration
	if err := writeAnsibleConf(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// Run ansible
	cmd := command(vargs, workspace)
	trace(cmd)

	cmd.Env = os.Environ()
	cmd.Dir = workspace.Path
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	err := cmd.Run()
	if err != nil {
		fmt.Printf("Failed to deploy playbook %s with inventory %s: %s", vargs.Playbook, vargs.Inventory, err)
		os.Exit(1)
	}
}
示例#19
0
func main() {
	d := new(deployer)
	w := new(plugin.Workspace)

	plugin.Param("vargs", d)
	plugin.Param("workspace", w)
	plugin.MustParse()

	// Save ssh keys
	if err := os.MkdirAll("/root/.ssh", 0700); err != nil {
		log.Fatal(err)
	}

	if err := ioutil.WriteFile("/root/.ssh/config", []byte(SSHConfig), 0644); err != nil {
		log.Fatal(err)
	}

	if err := ioutil.WriteFile("/root/.ssh/id_rsa", []byte(w.Keys.Private), 0600); err != nil {
		log.Fatal(err)
	}

	if err := ioutil.WriteFile("/root/.ssh/id_rsa.pub", []byte(w.Keys.Public), 0644); err != nil {
		log.Fatal(err)
	}

	c := exec.Command("/bin/dep", "-n", d.Task, d.Stage)
	c.Dir = w.Path
	c.Stdout = os.Stdout
	c.Stderr = os.Stderr

	err := c.Run()
	if err != nil {
		log.Fatal(err)
	}

	log.Println("Command completed successfully")
}
示例#20
0
func main() {
	workspace := plugin.Workspace{}
	vargs := Fabric{}

	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)

	// parse the parameters
	if err := plugin.Parse(); err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	if err := writeKey(&workspace); err != nil {
		log.Println("Unable to write private key")
		log.Println(err)
		os.Exit(1)
	}

	if err := os.Chdir(workspace.Path); err != nil {
		log.Println("Unable to dc into workspace.Path")
		os.Exit(1)
	}

	for _, c := range vargs.Commands {
		fabArgs := strings.Split(c, " ")
		c := exec.Command("fab", fabArgs...)
		c.Stdout = os.Stdout
		c.Stderr = os.Stderr
		err := c.Run()
		if err != nil {
			log.Println(err)
			os.Exit(101)
		}
	}
}
示例#21
0
func main() {

	workspace := plugin.Workspace{}
	vargs := terraform{}

	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()

	var commands []*exec.Cmd
	remote := vargs.Remote
	if remote.Backend != "" {
		commands = append(commands, remoteConfigCommand(remote))
	}
	commands = append(commands, planCommand(vargs.Vars))
	if !vargs.DryRun {
		commands = append(commands, applyCommand())
	}

	for _, c := range commands {
		c.Env = os.Environ()
		c.Dir = workspace.Path
		c.Stdout = os.Stdout
		c.Stderr = os.Stderr
		trace(c)

		err := c.Run()
		if err != nil {
			fmt.Println("Error!")
			fmt.Println(err)
			os.Exit(1)
		}
		fmt.Println("Command completed successfully")
	}

}
示例#22
0
func main() {
	repo := plugin.Repo{}
	build := plugin.Build{}
	vargs := Slack{}

	plugin.Param("build", &build)
	plugin.Param("repo", &repo)
	plugin.Param("vargs", &vargs)

	// parse the parameters
	if err := plugin.Parse(); err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	// create the Slack client
	client := Client{}
	client.Url = vargs.Webhook

	// generate the Slack message
	msg := Message{}
	msg.Channel = vargs.Channel
	msg.Username = vargs.Username

	attach := msg.NewAttachment()
	attach.Text = GetMessage(&repo, &build)
	attach.Fallback = GetFallback(&repo, &build)
	attach.Color = GetColor(&build)
	attach.MrkdwnIn = []string{"text", "fallback"}

	// sends the message
	if err := client.SendMessage(&msg); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
示例#23
0
func main() {
	workspace := plugin.Workspace{}
	build := plugin.Build{}
	vargs := Docker{}

	plugin.Param("workspace", &workspace)
	plugin.Param("build", &build)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()

	// in case someone uses the shorthand repository name
	// with a custom registry, we should concatinate so that
	// we have the fully qualified image name.
	if strings.Count(vargs.Repo, "/") == 1 && len(vargs.Registry) != 0 {
		vargs.Repo = fmt.Sprintf("%s/%s", vargs.Registry, vargs.Repo)
	}

	// Set the Registry value
	if len(vargs.Registry) == 0 {
		vargs.Registry = "https://index.docker.io/v1/"
	}
	// Set the Dockerfile path
	if len(vargs.File) == 0 {
		vargs.File = "."
	}
	// Set the Tag value
	if len(vargs.Tag) == 0 {
		vargs.Tag = "latest"
	}
	vargs.Repo = fmt.Sprintf("%s:%s", vargs.Repo, vargs.Tag)

	go func() {
		args := []string{"-d"}

		if len(vargs.Storage) != 0 {
			args = append(args, "-s", vargs.Storage)
		}
		if vargs.Insecure && len(vargs.Registry) != 0 {
			args = append(args, "--insecure-registry", vargs.Registry)
		}

		for _, value := range vargs.Dns {
			args = append(args, "--dns", value)
		}

		cmd := exec.Command("/usr/bin/docker", args...)
		if os.Getenv("DOCKER_LAUNCH_DEBUG") == "true" {
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr
		} else {
			cmd.Stdout = ioutil.Discard
			cmd.Stderr = ioutil.Discard
		}
		trace(cmd)
		cmd.Run()
	}()

	// ping Docker until available
	for i := 0; i < 3; i++ {
		cmd := exec.Command("/usr/bin/docker", "info")
		cmd.Stdout = ioutil.Discard
		cmd.Stderr = ioutil.Discard
		err := cmd.Run()
		if err == nil {
			break
		}
		time.Sleep(time.Second * 5)
	}

	// Login to Docker
	if len(vargs.Username) != 0 {
		cmd := exec.Command("/usr/bin/docker", "login", "-u", vargs.Username, "-p", vargs.Password, "-e", vargs.Email, vargs.Registry)
		cmd.Dir = workspace.Path
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		err := cmd.Run()
		if err != nil {
			fmt.Println("Login failed.")
			os.Exit(1)
		}
	} else {
		fmt.Printf("A username was not specified. Assuming anoynmous publishing.\n")
	}

	// Docker environment info
	cmd := exec.Command("/usr/bin/docker", "version")
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	trace(cmd)
	cmd.Run()
	cmd = exec.Command("/usr/bin/docker", "info")
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	trace(cmd)
	cmd.Run()

	// Build the container
	cmd = exec.Command("/usr/bin/docker", "build", "--pull=true", "--rm=true", "-t", vargs.Repo, vargs.File)
	cmd.Dir = workspace.Path
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	trace(cmd)
	err := cmd.Run()
	if err != nil {
		os.Exit(1)
	}

	// Push the container
	cmd = exec.Command("/usr/bin/docker", "push", vargs.Repo)
	cmd.Dir = workspace.Path
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	trace(cmd)
	err = cmd.Run()
	if err != nil {
		os.Exit(1)
	}
}
示例#24
0
func main() {
	repo := plugin.Repo{}
	build := plugin.Build{}
	workspace := plugin.Workspace{}
	vargs := Npm{}

	plugin.Param("build", &build)
	plugin.Param("repo", &repo)
	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)

	// parse the parameters
	if err := plugin.Parse(); err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	// check for required parameters
	if len(vargs.Username) == 0 {
		fmt.Println("Username not provided")
		os.Exit(1)
	}

	if len(vargs.Password) == 0 {
		fmt.Println("Password not provided")
		os.Exit(1)
	}

	if len(vargs.Email) == 0 {
		fmt.Println("Email not provided")
		os.Exit(1)
	}

	// set defaults
	var globalRegistry bool

	if len(vargs.Registry) == 0 {
		vargs.Registry = "https://registry.npmjs.org"
		globalRegistry = true
	} else {
		globalRegistry = false
	}

	// get the package info
	var packagePath string

	if len(vargs.Folder) == 0 {
		packagePath = path.Join(workspace.Path)
	} else {
		packagePath = path.Join(workspace.Path, vargs.Folder)
	}

	packageFile := path.Join(packagePath, "package.json")

	npmPackage, err := readPackageFile(packageFile)

	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	// see if the package should be published
	publish, err := shouldPublishPackage(vargs, npmPackage)

	if publish {
		fmt.Println("Attempting to publish package")

		// write the npmrc file
		npmrcPath := path.Join(packagePath, ".npmrc")
		err := writeNpmrcFile(vargs, npmrcPath)

		if err != nil {
			fmt.Println(err.Error())
			os.Exit(1)
		}

		var cmds []*exec.Cmd

		// write registry command
		if !globalRegistry {
			cmds = append(cmds, registryCommand(vargs))
		}

		// write auth command
		if vargs.AlwaysAuth {
			cmds = append(cmds, alwaysAuthCommand())
		}

		// write the publish command
		cmds = append(cmds, publishCommand())

		// run the commands
		for _, cmd := range cmds {
			cmd.Dir = packagePath
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr
			trace(cmd)
			err := cmd.Run()
			if err != nil {
				os.Exit(1)
			}
		}
	} else {
		fmt.Println("Package already published")
	}
}
示例#25
0
func main() {
	fmt.Println("starting drone-rancher-catalog...")

	var catalog = catalog{}
	plugin.Param("workspace", &catalog.workspace)
	plugin.Param("repo", &catalog.repo)
	plugin.Param("build", &catalog.build)
	plugin.Param("vargs", &catalog.vargs)
	plugin.MustParse()

	check(catalog.vargs.DockerRepo, "ERROR: docker_repo: Docker Registry Repo to read tags from, not specified")
	check(catalog.vargs.DockerUsername, "ERROR: docker_username: Docker Registry Username not specified")
	check(catalog.vargs.DockerPassword, "ERROR: docker_password: Docker Registry Password not specified")
	check(catalog.vargs.CatalogRepo, "ERROR: catalog_repo: GitHub Catalog Repo not specified")
	check(catalog.vargs.GitHubToken, "ERROR: github_token: GitHub User Token not specified")
	check(catalog.vargs.CowpokeURL, "ERROR: cowpoke_url: cowpoke url not specified")
	check(catalog.vargs.RancherCatalogName, "ERROR: rancher_catalog_name: catalog name in rancher is not specified")

	if len(catalog.vargs.DockerURL) == 0 {
		catalog.vargs.DockerURL = "https://registry.hub.docker.com/"
	}
	if len(catalog.vargs.GitHubUser) == 0 {
		catalog.vargs.GitHubUser = catalog.build.Author
	}
	if len(catalog.vargs.GitHubEmail) == 0 {
		catalog.vargs.GitHubEmail = catalog.build.Email
	}

	// create a dir outside the workspace
	if !exists(baseDir) {
		os.Mkdir(baseDir, 0755)
	}

	catalog.cloneCatalogRepo()
	os.Chdir(repoDir)
	catalog.gitConfigureEmail()
	catalog.gitConfigureUser()

	if !exists("./templates") {
		os.Mkdir("./templates", 0755)
	}

	dockerComposeTmpl := catalog.parseTemplateFile(dockerComposeTemplateFile)
	rancherComposeTmpl := catalog.parseTemplateFile(rancherComposeTemplateFile)
	configTmpl := catalog.parseTemplateFile(configTemplateFile)
	upgradeTags := getTagsFromYaml(catalog.workspace)
	tags := catalog.getTags()
	tbb := catalog.TagsByBranch(tags)

	var cowpokeRequests []*http.Request
	var catalogCreationCheckRequests []*http.Request

	fmt.Println("Creating Catalog Templates for:")
	for branch := range tbb.branches {
		var count int
		var last *Tag

		// create branch dir
		branchDir := fmt.Sprintf("./templates/%s", branch)
		if !exists(branchDir) {
			os.Mkdir(branchDir, 0755)
		}

		// sort semver so we can count builds in a feature branch
		var vKeys []semver.Version
		for k := range tbb.branches[branch].versions {
			version, err := semver.Parse(k)
			if err != nil {
				fmt.Printf("Error parsing version %v \n", err)
				continue
			}
			vKeys = append(vKeys, version)
		}
		semver.Sort(vKeys)
		for _, version := range vKeys {
			// sort builds to count in order
			var bKeys []int
			ver := version.String()
			for k := range tbb.branches[branch].versions[ver].builds {
				bKeys = append(bKeys, k)
			}
			sort.Ints(bKeys)

			for _, build := range bKeys {
				tbb.branches[branch].versions[ver].builds[build].Count = count

				// create dir structure
				buildDir := fmt.Sprintf("%s/%d", branchDir, count)
				if !exists(buildDir) {
					fmt.Printf("  %d:%s %s-%d\n", count, branch, ver, build)
					os.Mkdir(buildDir, 0755)
				}

				// create docker-compose.yml and rancher-compose.yml from template
				// don't generate files if they already exist
				dockerComposeTarget := fmt.Sprintf("%s/docker-compose.yml", buildDir)
				if !exists(dockerComposeTarget) {
					catalog.executeTemplate(dockerComposeTarget, dockerComposeTmpl, tbb.branches[branch].versions[ver].builds[build])
				}
				rancherComposeTarget := fmt.Sprintf("%s/rancher-compose.yml", buildDir)
				if !exists(rancherComposeTarget) {
					catalog.executeTemplate(rancherComposeTarget, rancherComposeTmpl, tbb.branches[branch].versions[ver].builds[build])
				}

				last = tbb.branches[branch].versions[ver].builds[build]
				count++
			}
			if stringInSlice(last.Tag, upgradeTags) {
				//count was already incremented so it needs to be decremented for the cowpoke request.
				//it is important for iteration that there be the same number of elements in both of these arrays
				//Therefore even if buildCatalogCheckRequest returns nil we add it to the slice. The nil check happens doRequest
				catalogCreationCheckRequests = append(catalogCreationCheckRequests, buildCatalogCreationCheckRequest(catalog.vargs.CatalogRepo, branch, count-1, catalog.vargs.GitHubToken))
				cowpokeRequests = append(cowpokeRequests, cowpokeRequest(count-1, branch, catalog.vargs.CatalogRepo, catalog.vargs.RancherCatalogName, catalog.vargs.GitHubToken, catalog.vargs.CowpokeURL, catalog.vargs.BearerToken))
			}

		}

		// create config.yml from temlplate
		configTarget := fmt.Sprintf("%s/config.yml", branchDir)
		catalog.executeTemplate(configTarget, configTmpl, last)

		// Icon file
		copyIcon(iconFileBase, branchDir)
	}
	// TODO: Delete dir/files if tags don't exist anymore. Need to maintian build dir numbering

	if catalog.gitChanged() {
		catalog.addCatalogRepo()
		catalog.commitCatalogRepo()
		catalog.pushCatalogRepo()
	}
	client := &http.Client{
		Timeout: time.Second * 60,
	}
	time.Sleep(3000 * time.Millisecond) //give github time to be consisitent
	for index, request := range cowpokeRequests {
		doRequest(catalogCreationCheckRequests[index], request, client)
	}
	fmt.Println("... Finished drone-rancher-catalog")
}
示例#26
0
func main() {
	workspace := plugin.Workspace{}
	build := plugin.Build{}
	vargs := Docker{}

	plugin.Param("workspace", &workspace)
	plugin.Param("build", &build)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()

	// in case someone uses the shorthand repository name
	// with a custom registry, we should concatinate so that
	// we have the fully qualified image name.
	if strings.Count(vargs.Repo, "/") <= 1 && len(vargs.Registry) != 0 && !strings.HasPrefix(vargs.Repo, vargs.Registry) {
		vargs.Repo = fmt.Sprintf("%s/%s", vargs.Registry, vargs.Repo)
	}

	// Set the Registry value
	if len(vargs.Registry) == 0 {
		vargs.Registry = "https://index.docker.io/v1/"
	}
	// Set the Dockerfile name
	if len(vargs.File) == 0 {
		vargs.File = "Dockerfile"
	}
	// Set the Context value
	if len(vargs.Context) == 0 {
		vargs.Context = "."
	}
	// Set the Tag value
	if vargs.Tag.Len() == 0 {
		vargs.Tag = StrSlice{[]string{"latest"}}
	}
	// Get absolute path for 'save' file
	if len(vargs.Save.File) != 0 {
		if !filepath.IsAbs(vargs.Save.File) {
			vargs.Save.File = filepath.Join(workspace.Path, vargs.Save.File)
		}
	}
	// Get absolute path for 'load' file
	if len(vargs.Load) != 0 {
		if !filepath.IsAbs(vargs.Load) {
			vargs.Load = filepath.Join(workspace.Path, vargs.Load)
		}
	}

	go func() {
		args := []string{"-d"}

		if len(vargs.Storage) != 0 {
			args = append(args, "-s", vargs.Storage)
		}
		if vargs.Insecure && len(vargs.Registry) != 0 {
			args = append(args, "--insecure-registry", vargs.Registry)
		}
		if len(vargs.Mirror) != 0 {
			args = append(args, "--registry-mirror", vargs.Mirror)
		}

		for _, value := range vargs.Dns {
			args = append(args, "--dns", value)
		}

		cmd := exec.Command("/usr/bin/docker", args...)
		if os.Getenv("DOCKER_LAUNCH_DEBUG") == "true" {
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr
		} else {
			cmd.Stdout = ioutil.Discard
			cmd.Stderr = ioutil.Discard
		}
		trace(cmd)
		cmd.Run()
	}()

	// ping Docker until available
	for i := 0; i < 3; i++ {
		cmd := exec.Command("/usr/bin/docker", "info")
		cmd.Stdout = ioutil.Discard
		cmd.Stderr = ioutil.Discard
		err := cmd.Run()
		if err == nil {
			break
		}
		time.Sleep(time.Second * 5)
	}

	// Login to Docker
	if len(vargs.Username) != 0 {
		cmd := exec.Command("/usr/bin/docker", "login", "-u", vargs.Username, "-p", vargs.Password, "-e", vargs.Email, vargs.Registry)
		cmd.Dir = workspace.Path
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		err := cmd.Run()
		if err != nil {
			fmt.Println("Login failed.")
			os.Exit(1)
		}
	} else {
		fmt.Printf("A username was not specified. Assuming anoynmous publishing.\n")
	}

	// Docker environment info
	cmd := exec.Command("/usr/bin/docker", "version")
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	trace(cmd)
	cmd.Run()
	cmd = exec.Command("/usr/bin/docker", "info")
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	trace(cmd)
	cmd.Run()

	// Restore from tarred image repository
	if len(vargs.Load) != 0 {
		if _, err := os.Stat(vargs.Load); err != nil {
			fmt.Printf("Archive %s does not exist. Building from scratch.\n", vargs.Load)
		} else {
			cmd := exec.Command("/usr/bin/docker", "load", "-i", vargs.Load)
			cmd.Dir = workspace.Path
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr
			trace(cmd)
			err := cmd.Run()
			if err != nil {
				os.Exit(1)
			}
		}
	}

	// Build the container
	name := fmt.Sprintf("%s:%s", vargs.Repo, vargs.Tag.Slice()[0])
	cmd = exec.Command("/usr/bin/docker", "build", "--pull=true", "--rm=true", "-f", vargs.File, "-t", name, vargs.Context)
	cmd.Dir = workspace.Path
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	trace(cmd)
	err := cmd.Run()
	if err != nil {
		os.Exit(1)
	}

	// Creates image tags
	for _, tag := range vargs.Tag.Slice()[1:] {
		name_ := fmt.Sprintf("%s:%s", vargs.Repo, tag)
		cmd = exec.Command("/usr/bin/docker", "tag", name, name_)
		cmd.Dir = workspace.Path
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		trace(cmd)
		err = cmd.Run()
		if err != nil {
			os.Exit(1)
		}
	}

	// Push the image and tags to the registry
	for _, tag := range vargs.Tag.Slice() {
		name_ := fmt.Sprintf("%s:%s", vargs.Repo, tag)
		cmd = exec.Command("/usr/bin/docker", "push", name_)
		cmd.Dir = workspace.Path
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		trace(cmd)
		err = cmd.Run()
		if err != nil {
			os.Exit(1)
		}
	}

	// Save to tarred image repository
	if len(vargs.Save.File) != 0 {
		// if the destination directory does not exist, create it
		dir := filepath.Dir(vargs.Save.File)
		os.MkdirAll(dir, 0755)

		cmd = exec.Command("/usr/bin/docker", "save", "-o", vargs.Save.File)

		// Limit saving to the given tags
		if vargs.Save.Tags.Len() != 0 {
			for _, tag := range vargs.Save.Tags.Slice() {
				name_ := fmt.Sprintf("%s:%s", vargs.Repo, tag)
				cmd.Args = append(cmd.Args, name_)
			}
		} else {
			cmd.Args = append(cmd.Args, vargs.Repo)
		}

		cmd.Dir = workspace.Path
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		trace(cmd)
		err := cmd.Run()
		if err != nil {
			os.Exit(1)
		}
	}
}
示例#27
0
func main() {
	var err error
	var path, wd string

	repo := plugin.Repo{}
	build := plugin.Build{}
	workspace := plugin.Workspace{}
	cmds := ComposerCommands{}

	plugin.Param("repo", &repo)
	plugin.Param("build", &build)
	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &cmds)
	err = plugin.Parse()

	if err != nil {
		fmt.Printf("Error while attempting to parse input: %s\n", err)
		os.Exit(1)
	}

	fmt.Printf("Got commands list:\n")
	for _, c := range cmds.Commands {
		fmt.Printf("- %s\n", c)
	}

	// let's try to find the Rancher Compose executable
	path, err = exec.LookPath("rancher-compose")
	if err != nil {
		fmt.Printf("Could not find rancher-compose executable on path: %s\n", err)
		os.Exit(1)
	}

	// chdir to the repo path
	if workspace.Path != "" {
		fmt.Printf("Using working directory: %s\n", workspace.Path)
		os.Chdir(workspace.Path)
	} else {
		wd, err = os.Getwd()
		if err != nil {
			fmt.Printf("Using working directory: %s\n", wd)
		} else {
			fmt.Printf("WARNING: Error while attempting to get working dir: %s\n", err)
		}
	}

	// execute each of our Rancher Compose commands in sequence
	for _, c := range cmds.Commands {
		args := CleanSlice(strings.Split(c, " "))
		fmt.Printf("Executing Rancher Compose: %s %s\n", path, strings.Join(args[:], " "))

		cmd := exec.Command(path, args...)
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		err := cmd.Run()

		// exit if any command fails
		if err != nil {
			fmt.Printf("Error while executing command: %s\n", err)
			os.Exit(1)
		}
	}

	fmt.Printf("Successfully executed commands\n")

}
示例#28
0
func main() {
	workspace := plugin.Workspace{}
	build := plugin.Build{}
	vargs := Docker{}

	plugin.Param("workspace", &workspace)
	plugin.Param("build", &build)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()

	// Repository name should have gcr prefix
	if len(vargs.Registry) == 0 {
		vargs.Registry = "gcr.io"
	}
	// Set the Dockerfile name
	if len(vargs.File) == 0 {
		vargs.File = "Dockerfile"
	}
	// Set the Context value
	if len(vargs.Context) == 0 {
		vargs.Context = "."
	}
	// Set the Tag value
	if vargs.Tag.Len() == 0 {
		vargs.Tag = StrSlice{[]string{"latest"}}
	}
	// Concat the Registry URL and the Repository name if necessary
	if strings.Count(vargs.Repo, "/") == 1 {
		vargs.Repo = fmt.Sprintf("%s/%s", vargs.Registry, vargs.Repo)
	}
	// Trim any spaces or newlines from the token
	vargs.Token = strings.TrimSpace(vargs.Token)

	go func() {
		args := []string{"-d"}

		if len(vargs.Storage) != 0 {
			args = append(args, "-s", vargs.Storage)
		}

		cmd := exec.Command("/usr/bin/docker", args...)
		if os.Getenv("DOCKER_LAUNCH_DEBUG") == "true" {
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr
		} else {
			cmd.Stdout = ioutil.Discard
			cmd.Stderr = ioutil.Discard
		}
		trace(cmd)
		cmd.Run()
	}()

	// ping Docker until available
	for i := 0; i < 3; i++ {
		cmd := exec.Command("/usr/bin/docker", "info")
		cmd.Stdout = ioutil.Discard
		cmd.Stderr = ioutil.Discard
		err := cmd.Run()
		if err == nil {
			break
		}
		time.Sleep(time.Second * 5)
	}

	// Login to Docker
	cmd := exec.Command("/usr/bin/docker", "login", "-u", "_json_key", "-p", vargs.Token, "-e", "*****@*****.**", vargs.Registry)
	cmd.Dir = workspace.Path
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	err := cmd.Run()
	if err != nil {
		fmt.Println("Login failed.")
		os.Exit(1)
	}

	// Build the container
	cmd = exec.Command("/usr/bin/docker", "build", "--pull=true", "--rm=true", "-f", vargs.File, "-t", build.Commit, vargs.Context)
	cmd.Dir = workspace.Path
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	trace(cmd)
	err = cmd.Run()
	if err != nil {
		os.Exit(1)
	}

	// Creates image tags
	for _, tag := range vargs.Tag.Slice() {
		// create the full tag name
		tag_ := fmt.Sprintf("%s:%s", vargs.Repo, tag)
		if tag == "latest" {
			tag_ = vargs.Repo
		}

		// tag the build image sha
		cmd = exec.Command("/usr/bin/docker", "tag", build.Commit, tag_)
		cmd.Dir = workspace.Path
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		trace(cmd)
		err = cmd.Run()
		if err != nil {
			os.Exit(1)
		}
	}

	// Push the image and tags to the registry
	cmd = exec.Command("/usr/bin/docker", "push", vargs.Repo)
	cmd.Dir = workspace.Path
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	trace(cmd)
	err = cmd.Run()
	if err != nil {
		os.Exit(1)
	}
}
示例#29
0
func main() {
	clone := plugin.Clone{}
	vargs := Docker{}

	plugin.Param("clone", &clone)
	plugin.Param("vargs", &vargs)
	if err := plugin.Parse(); err != nil {
		println(err.Error())
		os.Exit(1)
	}

	// Set the storage driver
	if len(vargs.Storage) == 0 {
		vargs.Storage = "aufs"
	}

	stop := func() {
		cmd := exec.Command("start-stop-daemon", "--stop", "--pidfile", "/var/run/docker.pid")
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		trace(cmd)
		cmd.Run()
	}
	defer stop()

	// Starts the Docker daemon
	go func() {
		cmd := exec.Command("/bin/bash", "/bin/wrapdocker")
		cmd.Stdout = ioutil.Discard
		cmd.Stderr = ioutil.Discard
		cmd.Run()

		cmd = exec.Command("docker", "-d", "-s", vargs.Storage)
		cmd.Stdout = ioutil.Discard
		cmd.Stderr = ioutil.Discard
		trace(cmd)
		cmd.Run()
	}()

	// Sleep for a few seconds
	time.Sleep(5 * time.Second)

	// Set the Registry value
	if len(vargs.Registry) == 0 {
		vargs.Registry = "https://index.docker.io/v1/"
	}
	// Set the Dockerfile path
	if len(vargs.File) == 0 {
		vargs.File = "."
	}
	// Set the Tag value
	switch vargs.Tag {
	case "$DRONE_BRANCH":
		vargs.Tag = clone.Branch
	case "$DRONE_COMMIT":
		vargs.Tag = clone.Sha
	case "":
		vargs.Tag = "latest"
	}
	vargs.Repo = fmt.Sprintf("%s:%s", vargs.Repo, vargs.Tag)

	// Login to Docker
	cmd := exec.Command("docker", "login", "-u", vargs.Username, "-p", vargs.Password, "-e", vargs.Email, vargs.Registry)
	cmd.Dir = clone.Dir
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	err := cmd.Run()
	if err != nil {
		stop()
		os.Exit(1)
	}

	// Docker environment info
	cmd = exec.Command("docker", "version")
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	trace(cmd)
	cmd.Run()
	cmd = exec.Command("docker", "info")
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	trace(cmd)
	cmd.Run()

	// Build the container
	cmd = exec.Command("docker", "build", "--pull=true", "--rm=true", "-t", vargs.Repo, vargs.File)
	cmd.Dir = clone.Dir
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	trace(cmd)
	err = cmd.Run()
	if err != nil {
		stop()
		os.Exit(1)
	}

	// Push the container
	cmd = exec.Command("docker", "push", vargs.Repo)
	cmd.Dir = clone.Dir
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	trace(cmd)
	err = cmd.Run()
	if err != nil {
		stop()
		os.Exit(1)
	}
}
示例#30
0
func main() {
	fmt.Printf("Drone Slack Blame Plugin built at %s\n", buildDate)

	repo := plugin.Repo{}
	build := plugin.Build{}
	system := plugin.System{}
	vargs := Slack{}

	plugin.Param("build", &build)
	plugin.Param("system", &system)
	plugin.Param("repo", &repo)
	plugin.Param("vargs", &vargs)

	// parse the parameters
	if err := plugin.Parse(); err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	// setup the message
	buildLink := fmt.Sprintf("%s/%s/%d", system.Link, repo.FullName, build.Number)
	var messageOptions MessageOptions
	var color string
	var messageText string
	var channelText string

	// Determine if the build was a success
	if build.Status == "success" {
		messageOptions = vargs.Success
		color = "good"
		messageText = fmt.Sprintf("Build succeeded at %s", buildLink)
		channelText = "Thanks"
	} else {
		messageOptions = vargs.Failure
		color = "danger"
		messageText = fmt.Sprintf("Build failed at %s", buildLink)
		channelText = "Blame"
	}

	// set default values
	if len(messageOptions.Username) == 0 {
		messageOptions.Username = "******"
	}

	if len(messageOptions.Icon) == 0 {
		messageOptions.Icon = ":drone:"
	}

	if len(messageOptions.ImageAttachments) == 0 {
		messageOptions.ImageAttachments = []string{""}
	}

	// setup the message
	messageParams := slack.PostMessageParameters{
		Username:  messageOptions.Username,
		IconEmoji: messageOptions.Icon,
	}

	imageCount := len(messageOptions.ImageAttachments)
	rand.Seed(time.Now().UTC().UnixNano())

	attachment := slack.Attachment{
		Color:    color,
		Text:     messageText,
		ImageURL: messageOptions.ImageAttachments[rand.Intn(imageCount)],
	}

	messageParams.Attachments = []slack.Attachment{attachment}

	// get the commit author
	commitAuthor := build.Email

	// create the slack api
	api := slack.New(vargs.Token)

	// get the users
	//
	// Slack doesn't let you search by email so just need to get
	// everything and find the user in question
	var blameUser *slack.User

	users, _ := api.GetUsers()

	for _, user := range users {
		if user.Profile.Email == commitAuthor {
			fmt.Printf("%s\n", user.Name)
			fmt.Printf("%s\n", user.Profile.Email)
			blameUser = &user
			break
		}
	}

	// notify the user if possible
	var userAt string

	if blameUser != nil {
		userAt = fmt.Sprintf("@%s", blameUser.Name)

		// send the message to the user's channel
		//
		// this will appear through slackbot
		_, _, err := api.PostMessage(userAt, messageOptions.Message, messageParams)

		if err == nil {
			fmt.Printf("User %s notified\n", userAt)
		} else {
			fmt.Printf("Could not notify user %s!\n", userAt)
		}
	} else {
		userAt = build.Author
		fmt.Print("User could not be found")
	}

	// notify the channel if requested
	if len(vargs.Channel) != 0 {
		if !strings.HasPrefix(vargs.Channel, "#") {
			vargs.Channel = "#" + vargs.Channel
		}

		_, _, err := api.PostMessage(vargs.Channel, fmt.Sprintf("%s %s %s", messageOptions.Message, channelText, userAt), messageParams)

		if err == nil {
			fmt.Printf("Channel notified\n")
		} else {
			fmt.Printf("Could not notify channel!\n")
		}
	}
}