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("\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() {
	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() {
	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 #5
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
		}
	}
}
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 #7
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 #8
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)
}