Exemple #1
0
func main() {
	var repo = drone.Repo{}
	var build = drone.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  drone.Repo  `json:"repo"`
		Build drone.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()
	}
}
Exemple #2
0
func main() {
	fmt.Printf("Drone Rubygems Plugin built from %s\n", buildCommit)

	workspace := drone.Workspace{}
	repo := drone.Repo{}
	build := drone.Build{}
	vargs := Params{}

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

	if (len(vargs.Username) == 0 || len(vargs.Password) == 0) && len(vargs.APIKey) == 0 {
		fmt.Println("Please provide an API key or username/password credentials")

		os.Exit(1)
		return
	}

	dpl := buildDpl(&workspace, &repo, &build, &vargs)

	dpl.Dir = workspace.Path
	dpl.Stderr = os.Stderr
	dpl.Stdout = os.Stdout

	if err := dpl.Run(); err != nil {
		fmt.Println(err)

		os.Exit(1)
		return
	}
}
func main() {
	var (
		repo      = new(drone.Repo)
		build     = new(drone.Build)
		sys       = new(drone.System)
		workspace = new(drone.Workspace)
		vargs     = new(Vargs)
	)

	plugin.Param("build", build)
	plugin.Param("repo", repo)
	plugin.Param("system", sys)
	plugin.Param("workspace", workspace)
	plugin.Param("vargs", vargs)

	err := plugin.Parse()
	if err != nil {
		log.Fatal(err)
	}

	vargs.TerraformVarsFile = strings.Join([]string{vargs.TerraformVarsFile, "\nbuild_number = \"", strconv.Itoa(build.Number), "\""}, "")

	err = CheckDeploy(vargs)
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	} else {
		os.Exit(0)
	}

}
Exemple #4
0
func main() {
	fmt.Printf("Drone Deis Plugin built from %s\n", buildCommit)

	workspace := drone.Workspace{}
	repo := drone.Repo{}
	build := drone.Build{}
	vargs := Params{}

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

	if len(vargs.Controller) == 0 {
		fmt.Println("Please provide a controller")

		os.Exit(1)
		return
	}

	if len(vargs.Application) == 0 {
		vargs.Application = repo.Name
	}

	err := run(&workspace, &build, &vargs)

	if err != nil {
		fmt.Println(err)

		os.Exit(1)
		return
	}
}
Exemple #5
0
func main() {
	fmt.Printf("Drone Heroku Plugin built at %s\n", buildDate)

	workspace := drone.Workspace{}
	repo := drone.Repo{}
	build := drone.Build{}
	vargs := Params{}

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

	if len(vargs.Application) == 0 {
		vargs.Application = repo.Name
	}

	err := run(&workspace, &build, &vargs)

	if err != nil {
		fmt.Println(err)

		os.Exit(1)
		return
	}
}
Exemple #6
0
func main() {
	fmt.Printf("\nDrone Bintray plugin version %s %s\n", version, buildDate)
	var workspace = drone.Workspace{}

	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &bintray)
	if err := plugin.Parse(); err != nil {
		fmt.Printf("ERROR Can't parse yaml config: %s", err.Error())
		os.Exit(1)
	}

	if bintray.Host == "" {
		bintray.Host = defaultHost
	}

	if bintray.Debug {
		saveApikey := bintray.APIKey
		bintray.APIKey = "******"
		fmt.Printf("DEBUG plugin input:\n%#v\n%#v\n", workspace, bintray)
		bintray.APIKey = saveApikey
	}
	if len(bintray.Branch) == 0 || bintray.Branch == "master" {
		fmt.Printf("\nPublishing %d artifacts to Bintray for user %s\n", len(bintray.Artifacts), bintray.Username)
	} else {
		fmt.Printf("\nPublishing %d artifacts on branch %s to Bintray for user %s\n", len(bintray.Artifacts), bintray.Branch, bintray.Username)
	}
	for i, artifact := range bintray.Artifacts {
		artifact.Version = fmt.Sprintf("%v", artifact.Versioni)
		fmt.Printf("\nUploading file %d %s to %s\n", i+1,
			artifact.File, artifact.getEndpoint())
		artifact.Upload(workspace.Path)
	}
}
func main() {
	fmt.Printf("Drone Cloud Foundry Plugin built from %s\n", buildCommit)

	workspace := drone.Workspace{}
	cfargs := CloudFoundry{}

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

	cli := cfcli{
		Dir: workspace.Path,
	}

	cli.Exec(
		api(cfargs.API)...)
	cli.Exec(
		login(cfargs.Credentials)...)
	cli.Exec(
		target(cfargs.Target)...)
	cli.Exec(
		push(
			workspace,
			cfargs.App,
			cfargs.Route,
			cfargs.Flags)...)
}
Exemple #8
0
func main() {
	fmt.Printf("Drone Pushover Plugin built from %s\n", buildCommit)

	system := drone.System{}
	repo := drone.Repo{}
	build := drone.Build{}
	vargs := Params{}

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

	if vargs.Retry == 0 {
		vargs.Retry = 60 * time.Second
	}

	if vargs.Expire == 0 {
		vargs.Expire = 3600 * time.Second
	}

	if vargs.Token == "" {
		fmt.Println("Please provide a app token")
		os.Exit(1)
	}

	if vargs.User == "" {
		fmt.Println("Please provide a user token")
		os.Exit(1)
	}

	client := pushover.New(vargs.Token)

	resp, err := client.SendMessage(
		&pushover.Message{
			Title:      BuildTitle(system, repo, build, vargs.Title),
			Message:    BuildBody(system, repo, build, vargs.Body),
			URL:        fmt.Sprintf("%s/%s/%d", system.Link, repo.FullName, build.Number),
			URLTitle:   "Link to the Build",
			DeviceName: vargs.Device,
			Sound:      vargs.Sound,
			Priority:   vargs.Priority,
			Retry:      vargs.Retry,
			Expire:     vargs.Expire,
			Timestamp:  time.Now().Unix(),
		},
		pushover.NewRecipient(
			vargs.User,
		),
	)

	fmt.Println(resp)

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
Exemple #9
0
func main() {
	fmt.Printf("Drone Anynines Plugin built from %s\n", buildCommit)

	workspace := drone.Workspace{}
	repo := drone.Repo{}
	build := drone.Build{}
	vargs := Params{}

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

	if len(vargs.Username) == 0 {
		fmt.Println("Please provide a username")

		os.Exit(1)
		return
	}

	if len(vargs.Password) == 0 {
		fmt.Println("Please provide a password")

		os.Exit(1)
		return
	}

	if len(vargs.Organization) == 0 {
		fmt.Println("Please provide an organization")

		os.Exit(1)
		return
	}

	if len(vargs.Space) == 0 {
		fmt.Println("Please provide a space")

		os.Exit(1)
		return
	}

	dpl := buildDpl(&workspace, &repo, &build, &vargs)

	dpl.Dir = workspace.Path
	dpl.Stderr = os.Stderr
	dpl.Stdout = os.Stdout

	trace(dpl)

	if err := dpl.Run(); err != nil {
		fmt.Println(err)

		os.Exit(1)
		return
	}
}
Exemple #10
0
func main() {
	repo := drone.Repo{}
	build := drone.Build{}
	workspace := drone.Workspace{}
	vargs := Nonstop{}

	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.Index) == 0 {
		fmt.Println("Index Host/IP not provided")
		os.Exit(1)
	}

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

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

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

	//set up commands
	var cmd *exec.Cmd
	cmd = publishCommand(vargs)
	cmd.Dir = workspace.Path
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	if vargs.Secure {
		c := []string{"ns", "upload", "--latest", "--secure", "--index", vargs.Index, "--port", vargs.Port, "--url", vargs.Url, "--token", "***********"}
		fmt.Println("$", strings.Join(c, " "))
	} else {
		c := []string{"ns", "upload", "--latest", "--index", vargs.Index, "--port", vargs.Port, "--url", vargs.Url, "--token", "***********"}
		fmt.Println("$", strings.Join(c, " "))
	}
	err := cmd.Run()
	if err != nil {
		os.Exit(1)
	}
}
Exemple #11
0
func main() {
	w := drone.Workspace{}
	v := Params{}
	plugin.Param("workspace", &w)
	plugin.Param("vargs", &v)
	plugin.MustParse()

	err := v.Deploy(&w)
	if err != nil {
		log.Fatal(err)
	}
}
Exemple #12
0
func main() {
	w := new(drone.Workspace)
	v := new(Rsync)
	plugin.Param("workspace", w)
	plugin.Param("vargs", v)
	if err := plugin.Parse(); err != nil {
		fmt.Println("Rsync: unable to parse invalid plugin input.")
		os.Exit(1)
	}

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

	// default values
	if v.Port == 0 {
		v.Port = 22
	}
	if len(v.User) == 0 {
		v.User = "******"
	}
	if len(v.Source) == 0 {
		v.Source = "./"
	}

	// execute for each host
	for _, host := range v.Hosts.Slice() {
		// sync the files on the remote machine
		rs := v.buildRsync(host, w.Path)
		rs.Stderr = os.Stderr
		rs.Stdout = os.Stdout
		trace(rs)
		err := rs.Run()
		if err != nil {
			os.Exit(1)
			return
		}

		// continue if no commands
		if len(v.Commands) == 0 {
			continue
		}

		// execute commands on remote server (reboot instance, etc)
		if err := v.run(w.Keys, host); err != nil {
			os.Exit(1)
			return
		}
	}
}
Exemple #13
0
func main() {
	w := new(drone.Workspace)
	v := new(Rsync)
	plugin.Param("workspace", w)
	plugin.Param("vargs", v)
	if err := plugin.Parse(); err != nil {
		fmt.Println("Rsync: unable to parse invalid plugin input.")
		os.Exit(1)
	}
	if err := rsync(w, v); err != nil {
		fmt.Printf("Rsync: %s\n", err)
		os.Exit(1)
	}
}
Exemple #14
0
func main() {
	v := new(Params)
	b := new(drone.Build)
	w := new(drone.Workspace)
	plugin.Param("build", b)
	plugin.Param("workspace", w)
	plugin.Param("vargs", &v)
	plugin.MustParse()

	err := run(b, w, v)
	if err != nil {
		os.Exit(1)
	}
}
Exemple #15
0
func main() {

	system := drone.System{}
	repo := drone.Repo{}
	build := drone.Build{}
	vargs := Params{}
	workspace := drone.Workspace{}

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

	if vargs.Debug {
		debug = true
	}

	if debug {
		log.Println("Workspace Root: " + workspace.Root)
		log.Println("Workspace Path: " + workspace.Path)

		log.Println("Tag: " + vargs.Tag)
	}

	// Iterate over rcs and svcs
	for _, rc := range vargs.ReplicationControllers {
		artifact, err := readArtifactFromFile(workspace.Path, rc, vargs.ApiServer, vargs.Namespace, vargs.Tag)
		if err != nil {
			log.Fatal(err)
		}
		if debug {
			log.Println("Artifact loaded: " + artifact.Url)
		}
		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, vargs.Tag)
		if err != nil {
			log.Fatal(err)
		}
		createArtifact(artifact, vargs.Token)
	}
}
Exemple #16
0
func main() {
	fmt.Printf("Drone Capistrano Plugin built at %s\n", buildDate)

	workspace := drone.Workspace{}
	vargs := Params{}

	dw := DeployWorkspace{workspace}

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

	log("Installing Drone's ssh key")
	if err := repo.WriteKey(&workspace); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	os.Setenv("BUILD_PATH", workspace.Path)
	os.Setenv("GIT_SSH_KEY", privateKeyPath)

	tasks := strings.Fields(vargs.Tasks)

	if len(tasks) == 0 {
		fmt.Println("Please provide Capistrano tasks to execute")
		os.Exit(1)
		return
	}

	log("Running Bundler")
	bundle := dw.bundle(bundlerArgs(vargs)...)
	if err := bundle.Run(); err != nil {
		fmt.Println(err)
		os.Exit(1)
		return
	}

	log("Running Capistrano")
	capistrano := dw.cap(tasks...)
	if err := capistrano.Run(); err != nil {
		fmt.Println(err)
		os.Exit(1)
		return
	}
}
func main() {
	fmt.Printf("Drone Azure Web Apps Plugin built from %s\n", buildCommit)

	workspace := drone.Workspace{}
	repo := drone.Repo{}
	build := drone.Build{}
	vargs := Params{}

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

	if len(vargs.Username) == 0 {
		fmt.Println("Please provide an username")

		os.Exit(1)
		return
	}

	if len(vargs.Password) == 0 {
		fmt.Println("Please provide a password")

		os.Exit(1)
		return
	}

	if len(vargs.Site) == 0 {
		vargs.Site = repo.Name
	}

	if len(vargs.Slot) == 0 {
		vargs.Slot = vargs.Site
	}

	err := run(&workspace, &build, &vargs)

	if err != nil {
		fmt.Println(err)

		os.Exit(1)
		return
	}
}
func main() {
	fmt.Printf("Drone cloudControl Plugin built from %s\n", buildCommit)

	workspace := drone.Workspace{}
	repo := drone.Repo{}
	build := drone.Build{}
	vargs := Params{}

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

	if len(vargs.Email) == 0 {
		fmt.Println("Please provide an email")

		os.Exit(1)
		return
	}

	if len(vargs.Password) == 0 {
		fmt.Println("Please provide a password")

		os.Exit(1)
		return
	}

	if len(vargs.Application) == 0 {
		vargs.Application = repo.Name
	}

	if len(vargs.Deployment) == 0 {
		vargs.Deployment = "default"
	}

	err := run(&workspace, &build, &vargs)

	if err != nil {
		fmt.Println(err)

		os.Exit(1)
		return
	}
}
Exemple #19
0
func main() {
	repo := drone.Repo{}
	build := drone.Build{}
	system := drone.System{}
	email := Email{}

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

	err := Send(&Context{
		Email: email,
		Build: build,
		Repo:  repo,
	})
	if err != nil {
		println(err.Error())
		os.Exit(1)
	}
}
Exemple #20
0
func main() {

	// plugin settings
	repo := drone.Repo{}
	build := drone.Build{}
	system := drone.System{}
	vargs := HipChat{}

	// set plugin parameters
	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)
		os.Exit(1)
	}

	// create the HipChat client
	client := NewClient(vargs.Room.String(), vargs.Token)

	// build the HipChat message
	msg := Message{
		From:    vargs.From,
		Notify:  vargs.Notify,
		Color:   Color(&build),
		Message: BuildMessage(&repo, &build, &system),
	}

	// sends the HipChat message
	if err := client.Send(&msg); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
Exemple #21
0
func main() {
	fmt.Printf("Drone AWS OpsWorks Plugin built from %s\n", buildCommit)

	repo := drone.Repo{}
	build := drone.Build{}
	vargs := Params{}

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

	if vargs.AccessKey == "" {
		fmt.Println("Please provide an access key id")
		os.Exit(1)
	}

	if vargs.SecretKey == "" {
		fmt.Println("Please provide a secret access key")
		os.Exit(1)
	}

	if aws.StringValue(vargs.Region) == "" {
		fmt.Println("Please provide a region")
		os.Exit(1)
	}

	if aws.StringValue(vargs.StackID) == "" {
		fmt.Println("Please provide a stack ID")
		os.Exit(1)
	}

	if aws.StringValue(vargs.Command) == "" {
		fmt.Println("Please provide a deploy command")
		os.Exit(1)
	}

	svc := opsworks.New(
		session.New(&aws.Config{
			Region: vargs.Region,
			Credentials: credentials.NewStaticCredentials(
				vargs.AccessKey,
				vargs.SecretKey,
				"",
			),
		}),
	)

	_, err := svc.CreateDeployment(
		&opsworks.CreateDeploymentInput{
			Command: &opsworks.DeploymentCommand{
				Name: vargs.Command,
				Args: vargs.Arguments,
			},
			StackId:     vargs.StackID,
			AppId:       vargs.AppID,
			Comment:     vargs.Comment,
			CustomJson:  vargs.CustomJSON,
			InstanceIds: vargs.Instances,
		},
	)

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

	fmt.Println("Successfully deployed")
}
func main() {
	fmt.Printf("Drone GitHub Release Plugin built at %s\n", buildDate)

	workspace := drone.Workspace{}
	repo := drone.Repo{}
	build := drone.Build{}
	vargs := Params{}

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

	if build.Event != "tag" {
		fmt.Printf("The GitHub Release plugin is only available for tags\n")
		os.Exit(0)
	}

	if vargs.BaseURL == "" {
		vargs.BaseURL = "https://api.github.com/"
	} else if !strings.HasSuffix(vargs.BaseURL, "/") {
		vargs.BaseURL = vargs.BaseURL + "/"
	}

	if vargs.UploadURL == "" {
		vargs.UploadURL = "https://uploads.github.com/"
	} else if !strings.HasSuffix(vargs.UploadURL, "/") {
		vargs.UploadURL = vargs.UploadURL + "/"
	}

	if vargs.APIKey == "" {
		fmt.Printf("You must provide an API key\n")
		os.Exit(1)
	}

	if workspace.Path != "" {
		os.Chdir(workspace.Path)
	}

	var files []string
	for _, glob := range vargs.Files.Slice() {
		globed, err := filepath.Glob(glob)
		if err != nil {
			fmt.Printf("Failed to glob %s\n", glob)
			os.Exit(1)
		}
		if globed != nil {
			files = append(files, globed...)
		}
	}

	if vargs.Checksum.Len() > 0 {
		var err error
		files, err = writeChecksums(files, vargs.Checksum.Slice())
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
	}

	baseURL, err := url.Parse(vargs.BaseURL)
	if err != nil {
		fmt.Printf("Failed to parse base URL\n")
		os.Exit(1)
	}

	uploadURL, err := url.Parse(vargs.UploadURL)
	if err != nil {
		fmt.Printf("Failed to parse upload URL\n")
		os.Exit(1)
	}

	ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: vargs.APIKey})
	tc := oauth2.NewClient(oauth2.NoContext, ts)

	client := github.NewClient(tc)
	client.BaseURL = baseURL
	client.UploadURL = uploadURL

	release, err := buildRelease(client, repo.Owner, repo.Name, filepath.Base(build.Ref))
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if err := uploadFiles(client, repo.Owner, repo.Name, *release.ID, files); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
func main() {
	fmt.Printf("Drone AWS CodeDeploy Plugin built from %s\n", buildCommit)

	repo := drone.Repo{}
	build := drone.Build{}
	vargs := Params{}

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

	if vargs.Application == "" {
		vargs.Application = repo.Name
	}

	if vargs.RevisionType == "" {
		vargs.RevisionType = codedeploy.RevisionLocationTypeGitHub
	}

	if vargs.AccessKey == "" {
		fmt.Println("Please provide an access key id")
		os.Exit(1)
	}

	if vargs.SecretKey == "" {
		fmt.Println("Please provide a secret access key")
		os.Exit(1)
	}

	if vargs.Region == "" {
		fmt.Println("Please provide a region")
		os.Exit(1)
	}

	if vargs.DeploymentGroup == "" {
		fmt.Println("Please provide a deployment group")
		os.Exit(1)
	}

	var location *codedeploy.RevisionLocation

	switch vargs.RevisionType {
	case codedeploy.RevisionLocationTypeGitHub:
		location = &codedeploy.RevisionLocation{
			RevisionType: aws.String(vargs.RevisionType),
			GitHubLocation: &codedeploy.GitHubLocation{
				CommitId:   aws.String(build.Commit),
				Repository: aws.String(repo.FullName),
			},
		}
	case codedeploy.RevisionLocationTypeS3:
		if vargs.BundleType == "" {
			fmt.Println("Please provide a bundle type")
			os.Exit(1)
		}

		if vargs.BucketName == "" {
			fmt.Println("Please provide a bucket name")
			os.Exit(1)
		}

		if vargs.BucketKey == "" {
			fmt.Println("Please provide a bucket key")
			os.Exit(1)
		}

		switch vargs.BundleType {
		case codedeploy.BundleTypeTar:
		case codedeploy.BundleTypeTgz:
		case codedeploy.BundleTypeZip:
		default:
			fmt.Println("Invalid bundle type")
			os.Exit(1)
		}

		s3location := &codedeploy.S3Location{
			BundleType: aws.String(vargs.BundleType),
			Bucket:     aws.String(vargs.BucketName),
			Key:        aws.String(vargs.BucketKey),
		}

		if vargs.BucketEtag != "" {
			s3location.ETag = aws.String(vargs.BucketEtag)
		}

		if vargs.BucketVersion != "" {
			s3location.Version = aws.String(vargs.BucketVersion)
		}

		location = &codedeploy.RevisionLocation{
			RevisionType: aws.String(vargs.RevisionType),
			S3Location:   s3location,
		}
	default:
		fmt.Println("Invalid revision type")
		os.Exit(1)
	}

	svc := codedeploy.New(
		session.New(&aws.Config{
			Region: aws.String(vargs.Region),
			Credentials: credentials.NewStaticCredentials(
				vargs.AccessKey,
				vargs.SecretKey,
				"",
			),
		}),
	)

	_, err := svc.CreateDeployment(
		&codedeploy.CreateDeploymentInput{
			ApplicationName:               aws.String(vargs.Application),
			DeploymentConfigName:          aws.String(vargs.DeploymentConfig),
			DeploymentGroupName:           aws.String(vargs.DeploymentGroup),
			Description:                   aws.String(vargs.Description),
			IgnoreApplicationStopFailures: aws.Bool(vargs.IgnoreStopFailures),
			Revision:                      location,
		},
	)

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

	fmt.Println("Successfully deployed")
}
Exemple #24
0
func main() {
	fmt.Printf("Drone AWS ECR Plugin built from %s\n", buildCommit)

	workspace := drone.Workspace{}
	build := drone.Build{}
	vargs := ECR{}

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

	//Perform ECR credential lookup and parse out username, password, registry
	if vargs.AccessKey == "" {
		fmt.Println("Please provide an access key id")
		os.Exit(1)
	}

	if vargs.SecretKey == "" {
		fmt.Println("Please provide a secret access key")
		os.Exit(1)
	}

	if vargs.Region == "" {
		fmt.Println("Please provide a region")
		os.Exit(1)
	}
	svc := ecr.New(session.New(&aws.Config{
		Region:      aws.String(vargs.Region),
		Credentials: credentials.NewStaticCredentials(vargs.AccessKey, vargs.SecretKey, ""),
	}))

	resp, err := svc.GetAuthorizationToken(&ecr.GetAuthorizationTokenInput{})
	if err != nil {
		fmt.Println("Unable to retrieve Registry credentials from AWS")
		fmt.Println(err.Error())
		os.Exit(1)
	}

	if len(resp.AuthorizationData) < 1 {
		fmt.Println("Request did not return authorization data")
		os.Exit(1)
	}

	bytes, err := base64.StdEncoding.DecodeString(*resp.AuthorizationData[0].AuthorizationToken)
	if err != nil {
		fmt.Printf("Error decoding authorization token: %s", err)
		os.Exit(1)
	}
	token := string(bytes[:len(bytes)])

	authTokens := strings.Split(token, ":")
	if len(authTokens) != 2 {
		fmt.Printf("Authorization token does not contain data in <user>:<password> format: %s", token)
		os.Exit(1)
	}

	registryURL, err := url.Parse(*resp.AuthorizationData[0].ProxyEndpoint)
	if err != nil {
		fmt.Printf("Error parsing registry URL: %s", err)
		os.Exit(1)
	}

	username := authTokens[0]
	password := authTokens[1]
	registry := registryURL.Host

	shortRepoName := vargs.Repo

	// 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(registry) != 0 && !strings.HasPrefix(vargs.Repo, registry) {
		vargs.Repo = fmt.Sprintf("%s/%s", registry, vargs.Repo)
	}

	// 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.UnmarshalJSON([]byte("[\"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{"daemon", "-g", "/drone/docker"}

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

		if len(vargs.Mirror) != 0 {
			args = append(args, "--registry-mirror", vargs.Mirror)
		}
		if len(vargs.Bip) != 0 {
			args = append(args, "--bip", vargs.Bip)
		}

		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

	cmd := exec.Command("/usr/bin/docker", "login", "-u", username, "-p", password, "-e", "none", 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)
	}
	// 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)
	for _, value := range vargs.BuildArgs {
		cmd.Args = append(cmd.Args, "--build-arg", value)
	}
	cmd.Args = append(cmd.Args, 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 repository on AWS ECR
	if vargs.CreateRepository {
		ri := &ecr.CreateRepositoryInput{
			RepositoryName: &shortRepoName,
		}

		_, err := svc.CreateRepository(ri)
		if err != nil && !strings.HasPrefix(err.Error(), "RepositoryAlreadyExistsException") {
			fmt.Printf("Error creating repository: %s", err.Error())
			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")
		if vargs.ForceTag {
			cmd.Args = append(cmd.Args, "--force=true")
		}
		cmd.Args = append(cmd.Args, 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)
		}
	}

	// Remove untagged images, if any
	var outbuf bytes.Buffer
	cmd = exec.Command("docker", "images", "-q", "-f", "dangling=true")
	cmd.Stdout = &outbuf
	cmd.Stderr = os.Stderr
	trace(cmd)
	err = cmd.Run()
	if err != nil {
		os.Exit(1)
	}

	if outbuf.Len() > 0 {
		images := strings.Split(strings.TrimSpace(outbuf.String()), "\n")
		cmd = exec.Command("docker", append([]string{"rmi"}, images...)...)
		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)
		}
	}
}
Exemple #25
0
func main() {
	fmt.Printf("Drone Cache Plugin built from %s\n", buildCommit)

	workspace := drone.Workspace{}
	repo := drone.Repo{}
	build := drone.Build{}
	job := drone.Job{}
	vargs := Cache{}

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

	// mount paths are relative to the workspace.
	// if the workspace doesn't exist, create it
	os.MkdirAll(workspace.Path, 0755)
	os.Chdir(workspace.Path)

	// if the job is running we should restore
	// the cache
	if isRunning(&job) {

		for _, mount := range vargs.Mount {
			// unique hash for the file
			hash_ := hash(mount, build.Branch, job.Environment)
			fmt.Println("Restoring cache", mount)

			// restore
			err := restore(hash_, mount, vargs.Archive)
			if err != nil {
				fmt.Printf("Unable to restore %s. %s\n", mount, err)

				// if a cached file is corrupted we should remove it immediately
				// so that subsequent builds don't try to extract.
				purge(hash_, vargs.Archive, 0)
			}

			// restore from repository default branch if possible
			if err != nil && build.Branch != repo.Branch {

				// recalulate the hash using the default branch
				hash_ = hash(mount, repo.Branch, job.Environment)
				fmt.Printf("Restoring cache from %s branch\n", repo.Branch)

				err = restore(hash_, mount, vargs.Archive) // second time is the charm
				if err != nil {
					fmt.Printf("Unable to restore %s from %s branch.\n", mount, repo.Branch)

					// if a cached file is corrupted we should remove it immediately
					// so that subsequent builds don't try to extract.
					purge(hash_, vargs.Archive, 0)
				}
			}
		}
	}

	// if the job is complete and is NOT a pull
	// request we should re-build the cache.
	if isSuccess(&job) && build.Event == drone.EventPush {

		for _, mount := range vargs.Mount {
			// unique hash for the file
			hash_ := hash(mount, build.Branch, job.Environment)
			fmt.Println("Building cache", mount)

			// rebuild
			err := rebuild(hash_, mount, vargs.Archive)
			if err != nil {
				fmt.Printf("Unable to rebuild cache for %s. %s\n", mount, err)
			}
			// purges previously cached files
			purge(hash_, vargs.Archive, 1)
		}
	}
}
Exemple #26
0
func main() {
	fmt.Printf("Drone Downstream Plugin built at %s\n", buildDate)

	v := new(Params)
	s := new(drone.System)
	plugin.Param("system", s)
	plugin.Param("vargs", v)
	plugin.MustParse()

	// if no server url is provided we can default
	// to the hosted Drone service.
	if len(v.Token) == 0 {
		fmt.Println("Error: you must provide your Drone access token.")
		os.Exit(1)
	}

	if v.Server == "" {
		v.Server = s.Link
	}

	// create the drone client
	client := drone.NewClientToken(v.Server, v.Token)

	for _, entry := range v.Repos {

		// parses the repository name in owner/name@branch format
		owner, name, branch := parseRepoBranch(entry)
		if len(owner) == 0 || len(name) == 0 {
			fmt.Printf("Error: unable to parse repository name %s.\n", entry)
			os.Exit(1)
		}
		if v.Fork {
			// get the latest build for the specified repository
			build, err := client.BuildLast(owner, name, branch)
			if err != nil {
				fmt.Printf("Error: unable to get latest build for %s.\n", entry)
				os.Exit(1)
			}
			// start a new  build
			_, err = client.BuildFork(owner, name, build.Number)
			if err != nil {
				fmt.Printf("Error: unable to trigger a new build for %s.\n", entry)
				os.Exit(1)
			}

			fmt.Printf("Starting new build %d for %s\n", build.Number, entry)

		} else {
			// get the latest build for the specified repository
			build, err := client.BuildLast(owner, name, branch)
			if err != nil {
				fmt.Printf("Error: unable to get latest build for %s.\n", entry)
				os.Exit(1)
			}

			// rebuild the latest build
			_, err = client.BuildStart(owner, name, build.Number)
			if err != nil {
				fmt.Printf("Error: unable to trigger build for %s.\n", entry)
				os.Exit(1)
			}

			fmt.Printf("Restarting build %d for %s\n", build.Number, entry)
		}
	}
}
Exemple #27
0
func main() {
	vargs := Rancher{StartFirst: true}

	plugin.Param("vargs", &vargs)
	err := plugin.Parse()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if len(vargs.Url) == 0 || len(vargs.AccessKey) == 0 || len(vargs.SecretKey) == 0 || len(vargs.Service) == 0 {
		return
	}

	if !strings.HasPrefix(vargs.Image, "docker:") {
		vargs.Image = fmt.Sprintf("docker:%s", vargs.Image)
	}

	var wantedService, wantedStack string
	if strings.Contains(vargs.Service, "/") {
		parts := strings.SplitN(vargs.Service, "/", 2)
		wantedStack = parts[0]
		wantedService = parts[1]
	} else {
		wantedService = vargs.Service
	}

	rancher, err := client.NewRancherClient(&client.ClientOpts{
		Url:       vargs.Url,
		AccessKey: vargs.AccessKey,
		SecretKey: vargs.SecretKey,
	})

	if err != nil {
		fmt.Printf("Failed to create rancher client: %s\n", err)
		os.Exit(1)
	}

	var stackId string
	if wantedStack != "" {
		environments, err := rancher.Environment.List(&client.ListOpts{})
		if err != nil {
			fmt.Printf("Failed to list rancher environments: %s\n", err)
			os.Exit(1)
		}

		for _, env := range environments.Data {
			if env.Name == wantedStack {
				stackId = env.Id
			}
		}

		if stackId == "" {
			fmt.Printf("Unable to find stack %s\n", wantedStack)
			os.Exit(1)
		}
	}

	services, err := rancher.Service.List(&client.ListOpts{})
	if err != nil {
		fmt.Printf("Failed to list rancher services: %s\n", err)
		os.Exit(1)
	}

	found := false
	var service client.Service
	for _, svc := range services.Data {
		if svc.Name == wantedService && ((wantedStack != "" && svc.EnvironmentId == stackId) || wantedStack == "") {
			service = svc
			found = true
		}
	}

	if !found {
		fmt.Printf("Unable to find service %s\n", vargs.Service)
		os.Exit(1)
	}

	service.LaunchConfig.ImageUuid = vargs.Image
	upgrade := &client.ServiceUpgrade{}
	upgrade.InServiceStrategy = &client.InServiceUpgradeStrategy{
		LaunchConfig:           service.LaunchConfig,
		SecondaryLaunchConfigs: service.SecondaryLaunchConfigs,
		StartFirst:             vargs.StartFirst,
	}
	upgrade.ToServiceStrategy = &client.ToServiceUpgradeStrategy{}

	_, err = rancher.Service.ActionUpgrade(&service, upgrade)
	if err != nil {
		fmt.Printf("Unable to upgrade service %s\n", vargs.Service)
		os.Exit(1)
	}

	fmt.Printf("Upgraded %s to %s\n", vargs.Service, vargs.Image)
}
func main() {
	fmt.Printf("Drone ContainerShip Plugin built from %s\n", buildCommit)

	repo := drone.Repo{}
	vargs := Params{}

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

	if vargs.Application == "" {
		vargs.Application = repo.Name
	}

	if vargs.Image == "" {
		vargs.Image = repo.FullName + ":latest"
	}

	if vargs.ApiKey == "" {
		fmt.Println("Error: ContainerShip Cloud API Key is required!")
		os.Exit(1)
	}

	if vargs.ClusterId == "" {
		fmt.Println("Error: ContainerShip Cloud Cluster ID is required!")
		os.Exit(1)
	}

	if vargs.Organization == "" {
		fmt.Println("Error: ContainerShip Cloud Organization is required!")
		os.Exit(1)
	}

	client := client.NewContainerShipCloudClient(vargs.Organization, vargs.ApiKey)

	response, err := client.GetApplication(vargs.ClusterId, vargs.Application)

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

	application := map[string]interface{}{
		"id":    vargs.Application,
		"image": vargs.Image,
	}

	switch response.StatusCode {
	case 404:
		create_response, err := client.CreateApplication(vargs.ClusterId, vargs.Application, application)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		switch create_response.StatusCode {
		case 201:
			fmt.Printf("Success: ContainerShip Cloud created %s\n", vargs.Application)
		default:
			fmt.Printf("Error: ContainerShip Cloud returned a %d response when creating %s\n", create_response.StatusCode, vargs.Application)
		}
	case 200:
		update_response, err := client.UpdateApplication(vargs.ClusterId, vargs.Application, application)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		switch update_response.StatusCode {
		case 200:
			fmt.Printf("Success: ContainerShip Cloud updated %s\n", vargs.Application)
		default:
			fmt.Printf("Error: ContainerShip Cloud returned a %d response when updating %s\n", update_response.StatusCode, vargs.Application)
		}
	default:
		fmt.Printf("Error: ContainerShip Cloud returned a %d response when fetching %s\n", response.StatusCode, vargs.Application)
		os.Exit(1)
	}
}
func main() {
	fmt.Printf("Drone AWS Elastic Beanstalk Plugin built from %s\n", buildCommit)

	repo := drone.Repo{}
	build := drone.Build{}
	vargs := Params{}

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

	if vargs.Application == "" {
		vargs.Application = repo.Name
	}

	if vargs.AccessKey == "" {
		fmt.Println("Please provide an access key id")
		os.Exit(1)
	}

	if vargs.SecretKey == "" {
		fmt.Println("Please provide a secret access key")
		os.Exit(1)
	}

	if vargs.Region == "" {
		fmt.Println("Please provide a region")
		os.Exit(1)
	}

	if vargs.VersionLabel == "" {
		fmt.Println("Please provide a version label")
		os.Exit(1)
	}

	if vargs.BucketName == "" {
		fmt.Println("Please provide a bucket name")
		os.Exit(1)
	}

	if vargs.BucketKey == "" {
		fmt.Println("Please provide a bucket key")
		os.Exit(1)
	}

	svc := elasticbeanstalk.New(
		session.New(&aws.Config{
			Region: aws.String(vargs.Region),
			Credentials: credentials.NewStaticCredentials(
				vargs.AccessKey,
				vargs.SecretKey,
				"",
			),
		}),
	)

	_, err := svc.CreateApplicationVersion(
		&elasticbeanstalk.CreateApplicationVersionInput{
			VersionLabel:          aws.String(vargs.VersionLabel),
			ApplicationName:       aws.String(vargs.Application),
			Description:           aws.String(vargs.Description),
			AutoCreateApplication: aws.Bool(vargs.AutoCreate),
			Process:               aws.Bool(vargs.Process),
			SourceBundle: &elasticbeanstalk.S3Location{
				S3Bucket: aws.String(vargs.BucketName),
				S3Key:    aws.String(vargs.BucketKey),
			},
		},
	)

	if vargs.EnvironmentUpdate == true && err == nil {

		if vargs.EnvironmentName == "" {
			fmt.Println("Can't update environment without environment name")
			os.Exit(1)
		}

		_, err = svc.UpdateEnvironment(
			&elasticbeanstalk.UpdateEnvironmentInput{
				VersionLabel:    aws.String(vargs.VersionLabel),
				ApplicationName: aws.String(vargs.Application),
				Description:     aws.String(vargs.Description),
				EnvironmentName: aws.String(vargs.EnvironmentName),
			},
		)
	}

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

	fmt.Println("Successfully deployed")
}
Exemple #30
0
func main() {
	fmt.Printf("Drone Webhook Plugin built from %s\n", buildCommit)

	system := drone.System{}
	repo := drone.Repo{}
	build := drone.Build{}
	vargs := Params{}

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

	if vargs.Method == "" {
		vargs.Method = "POST"
	}

	if vargs.ContentType == "" {
		vargs.ContentType = "application/json"
	}

	// Creates the payload, by default the payload
	// is the build details in json format, but a custom
	// template may also be used.

	var buf bytes.Buffer

	if vargs.Template == "" {
		data := struct {
			System drone.System `json:"system"`
			Repo   drone.Repo   `json:"repo"`
			Build  drone.Build  `json:"build"`
		}{system, repo, build}

		if err := json.NewEncoder(&buf).Encode(&data); err != nil {
			fmt.Printf("Error: Failed to encode JSON payload. %s\n", err)
			os.Exit(1)
		}
	} else {
		err := template.Write(&buf, vargs.Template, &drone.Payload{
			Build:  &build,
			Repo:   &repo,
			System: &system,
		})

		if err != nil {
			fmt.Printf("Error: Failed to execute the content template. %s\n", err)
			os.Exit(1)
		}
	}

	// build and execute a request for each url.
	// all auth, headers, method, template (payload),
	// and content_type values will be applied to
	// every webhook request.

	for i, rawurl := range vargs.URLs {
		uri, err := url.Parse(rawurl)

		if err != nil {
			fmt.Printf("Error: Failed to parse the hook URL. %s\n", err)
			os.Exit(1)
		}

		b := buf.Bytes()
		r := bytes.NewReader(b)

		req, err := http.NewRequest(vargs.Method, uri.String(), r)

		if err != nil {
			fmt.Printf("Error: Failed to create the HTTP request. %s\n", err)
			os.Exit(1)
		}

		req.Header.Set("Content-Type", vargs.ContentType)

		for key, value := range vargs.Headers {
			req.Header.Set(key, value)
		}

		if vargs.Auth.Username != "" {
			req.SetBasicAuth(vargs.Auth.Username, vargs.Auth.Password)
		}

		client := http.DefaultClient
		if vargs.SkipVerify {
			client = &http.Client{
				Transport: &http.Transport{
					TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
				},
			}
		}
		resp, err := client.Do(req)

		if err != nil {
			fmt.Printf("Error: Failed to execute the HTTP request. %s\n", err)
			os.Exit(1)
		}

		defer resp.Body.Close()

		if vargs.Debug || resp.StatusCode >= http.StatusBadRequest {
			body, err := ioutil.ReadAll(resp.Body)

			if err != nil {
				fmt.Printf("Error: Failed to read the HTTP response body. %s\n", err)
			}

			if vargs.Debug {
				fmt.Printf(
					debugRespFormat,
					i+1,
					req.URL,
					req.Method,
					req.Header,
					string(b),
					resp.Status,
					string(body),
				)
			} else {
				fmt.Printf(
					respFormat,
					i+1,
					req.URL,
					resp.Status,
					string(body),
				)
			}
		}
	}
}