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() { 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 } }
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 } }
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)...) }
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) } }
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 } }
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) } }
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) } }
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) } }
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 } }
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) } } }
func main() { fmt.Printf("Drone Tutum Plugin built from %s\n", buildCommit) repo := drone.Repo{} vargs := Params{} plugin.Param("repo", &repo) plugin.Param("vargs", &vargs) plugin.MustParse() if vargs.Service == "" { vargs.Service = repo.Name } if vargs.Key == "" { fmt.Println("Error: Please provide an API key") os.Exit(1) } if vargs.Username == "" { fmt.Println("Error: Please provide a username") os.Exit(1) } tutum.User = vargs.Username tutum.ApiKey = vargs.Key svcs, err := tutum.ListServices() if err != nil { fmt.Printf("Error: Failed to get a list of services. %s\n", err) os.Exit(1) } service := vargs.Service stack := "" stackURI := "" if strings.Contains(service, ".") { parts := strings.Split(service, ".") if len(parts) != 2 { fmt.Printf("Error: Failed to parse service name %q.\n", service) os.Exit(1) } service = parts[0] stack = parts[1] stacks, err := tutum.ListStacks() if err != nil { fmt.Printf("Error: Failed to get a list of the stacks. %s\n", err) os.Exit(1) } foundStack := false var stk tutum.Stack for _, stk = range stacks.Objects { if stk.Name == stack { foundStack = true break } } if !foundStack { fmt.Printf("Error: Failed to find stack %q.\n", stack) os.Exit(1) } stackURI = stk.Resource_uri } foundService := false var svc tutum.Service for _, svc = range svcs.Objects { if svc.Name == service { if stackURI == "" { foundService = true break } if svc.Stack == stackURI { foundService = true break } } } if !foundService { fmt.Printf("Error: Failed to find server %s.\n", vargs.Service) os.Exit(1) } if vargs.Image != "" && vargs.Image != svc.Image_name { err = svc.Update(tutum.ServiceCreateRequest{ Image: vargs.Image, }) if err != nil { fmt.Printf("Error: Failed to update the %s image for %s. %s\n", vargs.Image, vargs.Service, err) os.Exit(1) } } if vargs.Redeploy { fmt.Printf("Redeploying service \"%s\"\n", svc.Name) err = svc.Redeploy(tutum.ReuseVolumesOption{ Reuse: vargs.ReuseVolumes, }) if err != nil { fmt.Printf("Failed to redeploy the %s service. %s\n", svc.Name, err) os.Exit(1) } } }
func main() { fmt.Printf("Drone AWS ECS 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.AccessKey) == 0 { fmt.Println("Please provide an access key") os.Exit(1) return } if len(vargs.SecretKey) == 0 { fmt.Println("Please provide a secret key") os.Exit(1) return } if len(vargs.Region) == 0 { fmt.Println("Please provide a region") os.Exit(1) return } if len(vargs.Family) == 0 { fmt.Println("Please provide a task definition family name") os.Exit(1) return } if len(vargs.Image) == 0 { fmt.Println("Please provide an image name") os.Exit(1) return } if len(vargs.Tag) == 0 { vargs.Tag = "latest" } if len(vargs.Service) == 0 { fmt.Println("Please provide a service name") os.Exit(1) return } if vargs.Memory == 0 { vargs.Memory = 128 } svc := ecs.New( session.New(&aws.Config{ Region: aws.String(vargs.Region), Credentials: credentials.NewStaticCredentials(vargs.AccessKey, vargs.SecretKey, ""), })) Image := vargs.Image + ":" + vargs.Tag definition := ecs.ContainerDefinition{ Command: []*string{}, DnsSearchDomains: []*string{}, DnsServers: []*string{}, DockerLabels: map[string]*string{}, DockerSecurityOptions: []*string{}, EntryPoint: []*string{}, Environment: []*ecs.KeyValuePair{}, Essential: aws.Bool(true), ExtraHosts: []*ecs.HostEntry{}, Image: aws.String(Image), Links: []*string{}, Memory: aws.Int64(vargs.Memory), MountPoints: []*ecs.MountPoint{}, Name: aws.String(vargs.Family + "-container"), PortMappings: []*ecs.PortMapping{}, Ulimits: []*ecs.Ulimit{}, //User: aws.String("String"), VolumesFrom: []*ecs.VolumeFrom{}, //WorkingDirectory: aws.String("String"), } // Port mappings for _, portMapping := range vargs.PortMappings.Slice() { cleanedPortMapping := strings.Trim(portMapping, " ") parts := strings.SplitN(cleanedPortMapping, " ", 2) hostPort, hostPortErr := strconv.ParseInt(parts[0], 10, 64) if hostPortErr != nil { fmt.Println(hostPortErr.Error()) os.Exit(1) return } containerPort, containerPortError := strconv.ParseInt(parts[1], 10, 64) if containerPortError != nil { fmt.Println(containerPortError.Error()) os.Exit(1) return } pair := ecs.PortMapping{ ContainerPort: aws.Int64(containerPort), HostPort: aws.Int64(hostPort), Protocol: aws.String("TransportProtocol"), } definition.PortMappings = append(definition.PortMappings, &pair) } // Environment variables for _, envVar := range vargs.Environment.Slice() { parts := strings.SplitN(envVar, "=", 2) pair := ecs.KeyValuePair{ Name: aws.String(strings.Trim(parts[0], " ")), Value: aws.String(strings.Trim(parts[1], " ")), } definition.Environment = append(definition.Environment, &pair) } params := &ecs.RegisterTaskDefinitionInput{ ContainerDefinitions: []*ecs.ContainerDefinition{ &definition, }, Family: aws.String(vargs.Family), Volumes: []*ecs.Volume{}, } resp, err := svc.RegisterTaskDefinition(params) if err != nil { fmt.Println(err.Error()) os.Exit(1) return } val := *(resp.TaskDefinition.TaskDefinitionArn) sparams := &ecs.UpdateServiceInput{ Service: aws.String(vargs.Service), TaskDefinition: aws.String(val), } sresp, serr := svc.UpdateService(sparams) if serr != nil { fmt.Println(serr.Error()) return } fmt.Println(sresp) fmt.Println(resp) }
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") }
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), ) } } } }
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 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) } } }
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) } } }
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 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 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") }
func main() { fmt.Printf("Drone Bitballoon 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.AccessToken) == 0 { fmt.Println("Please provide a token") os.Exit(1) return } if len(vargs.Site) == 0 { fmt.Println("Please provide a site") os.Exit(1) return } if len(vargs.Path) == 0 { vargs.Path = workspace.Path } else { vargs.Path = path.Join( workspace.Path, vargs.Path) } client := bitballoon.NewClient( &bitballoon.Config{ AccessToken: vargs.AccessToken}) site, _, err := client.Sites.Get( vargs.Site) if err != nil { fmt.Println("Failed to find requested site") os.Exit(1) return } if vargs.Draft { deploy, _, err := site.Deploys.CreateDraft( vargs.Path) if err != nil { fmt.Println("Failed to deploy draft content") os.Exit(1) return } deploy.WaitForReady(0) } else { deploy, _, err := site.Deploys.Create( vargs.Path) if err != nil { fmt.Println("Failed to deploy site content") os.Exit(1) return } deploy.WaitForReady(0) } }