本文整理汇总了Golang中github.com/drone/drone-go/plugin.MustParse函数的典型用法代码示例。如果您正苦于以下问题:Golang MustParse函数的具体用法?Golang MustParse怎么用?Golang MustParse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustParse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
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
}
}
开发者ID:drone-plugins,项目名称:drone-rubygems,代码行数:34,代码来源:main.go
示例2: main
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
}
}
开发者ID:Inza,项目名称:drone-heroku,代码行数:27,代码来源:main.go
示例3: main
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
}
}
开发者ID:drone-plugins,项目名称:drone-deis,代码行数:34,代码来源:main.go
示例4: main
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)...)
}
开发者ID:drone-plugins,项目名称:drone-cloudfoundry,代码行数:27,代码来源:main.go
示例5: main
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)
}
}
开发者ID:drone-plugins,项目名称:drone-pushover,代码行数:59,代码来源:main.go
示例6: main
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
}
}
开发者ID:drone-plugins,项目名称:drone-anynines,代码行数:57,代码来源:main.go
示例7: main
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)
}
}
开发者ID:msteinert,项目名称:drone-pypi,代码行数:12,代码来源:main.go
示例8: main
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)
}
}
开发者ID:daxroc,项目名称:drone-git-push,代码行数:14,代码来源:main.go
示例9: main
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)
}
}
开发者ID:UKHomeOffice,项目名称:drone-kubernetes,代码行数:49,代码来源:main.go
示例10: main
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
}
}
开发者ID:masarakki,项目名称:drone-capistrano,代码行数:45,代码来源:main.go
示例11: main
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
}
}
开发者ID:drone-plugins,项目名称:drone-azure-web-apps,代码行数:45,代码来源:main.go
示例12: main
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
}
}
开发者ID:drone-plugins,项目名称:drone-cloudcontrol,代码行数:45,代码来源:main.go
示例13: main
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)
}
}
}
开发者ID:drone-plugins,项目名称:drone-cache,代码行数:78,代码来源:main.go
示例14: main
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,
})
//.........这里部分代码省略.........
开发者ID:drone-plugins,项目名称:drone-tutum,代码行数:101,代码来源:main.go
示例15: main
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, " ")
//.........这里部分代码省略.........
开发者ID:fridaystreet,项目名称:drone-ecs,代码行数:101,代码来源:main.go
示例16: main
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(
//.........这里部分代码省略.........
开发者ID:drone-plugins,项目名称:drone-codedeploy,代码行数:101,代码来源:main.go
示例17: main
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)
}
//.........这里部分代码省略.........
开发者ID:drone-plugins,项目名称:drone-webhook,代码行数:101,代码来源:main.go
示例18: main
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)
}
}
开发者ID:drone-plugins,项目名称:drone-containership,代码行数:79,代码来源:main.go
示例19: main
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)
}
}
//.........这里部分代码省略.........
开发者ID:carnivalmobile,项目名称:drone-ecr,代码行数:101,代码来源:main.go
示例20: main
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/[email protected] 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)
}
}
}
开发者ID:alexex,项目名称:drone-downstream,代码行数:66,代码来源:main.go
注:本文中的github.com/drone/drone-go/plugin.MustParse函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论