本文整理匯總了Golang中github.com/drone/drone-plugin-go/plugin.MustParse函數的典型用法代碼示例。如果您正苦於以下問題:Golang MustParse函數的具體用法?Golang MustParse怎麽用?Golang MustParse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了MustParse函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
fmt.Println("starting drone-cowpoke...")
workspace := plugin.Workspace{}
vargs := Cowpoke{}
plugin.Param("workspace", &workspace)
plugin.Param("vargs", &vargs)
plugin.MustParse()
if len(vargs.Url) == 0 {
fmt.Println("no cowpoke url was specified")
os.Exit(1)
}
if vargs.Port == 0 {
fmt.Println("no cowpoke port was specified")
os.Exit(1)
}
fmt.Println("loading image data from", filepath.Join(workspace.Path, ".docker.json"))
image := GetImageName(filepath.Join(workspace.Path, ".docker.json"))
if len(image) <= 0 {
fmt.Println("image load failed from .docker.json")
os.Exit(1)
}
var cowpokeUrl = fmt.Sprintf("%s:%d/api/environment/", vargs.Url, vargs.Port)
fmt.Println("cowpoke url set to:", cowpokeUrl)
fmt.Println(".docker.json value being posted:", image)
ExecutePut(cowpokeUrl + url.QueryEscape(image))
fmt.Println("finished drone-cowpoke.")
}
示例2: main
func main() {
log.SetFlags(0)
plugin.Param("workspace", &workspace)
plugin.Param("vargs", &vargs)
plugin.MustParse()
script := strings.Join(vargs.Script, "\n")
if err := ioutil.WriteFile(scriptName, []byte(script), 0644); err != nil {
log.Fatalf("WriteFile(%q): %v", script, err)
}
c := vargs.Cmd
if c == "" {
c = defaultCmd
}
cmd := exec.Command(c, scriptName)
cmd.Dir = workspace.Path
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = append(os.Environ(), vargs.Env...)
fmt.Println("$", strings.Join(cmd.Args, " "))
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
}
示例3: main
func main() {
log.SetFlags(0)
plugin.Param("workspace", &workspace)
plugin.Param("build", &build)
plugin.Param("repo", &repo)
plugin.Param("vargs", &vargs)
plugin.MustParse()
sort.Strings(vargs.Gzip) // need for matchGzip
// context for all clients
ctx := context.Background()
// GitHub client
gts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: vargs.GitHubToken})
client.ghub = github.NewClient(oauth2.NewClient(ctx, gts))
// GCS client
auth, err := google.JWTConfigFromJSON([]byte(vargs.AuthKey), storage.ScopeFullControl)
if err != nil {
fatalf("auth: %v", err)
}
tsrc := auth.TokenSource(ctx)
client.gcs, err = storage.NewClient(ctx, cloud.WithTokenSource(auth.TokenSource(ctx)))
if err != nil {
fatalf("storage client: %v", err)
}
// http client with service account authorization
client.http = oauth2.NewClient(ctx, tsrc)
run()
if ecode != 0 {
msg := fmt.Sprintf("exited with code %d", ecode)
updateStatus("error", msg, stagingURL)
}
os.Exit(ecode)
}
示例4: main
func main() {
fmt.Printf("Drone Terraform Plugin built from %s\n", buildCommit)
workspace := plugin.Workspace{}
vargs := terraform{}
plugin.Param("workspace", &workspace)
plugin.Param("vargs", &vargs)
plugin.MustParse()
if vargs.RoleARN != "" {
assumeRole(vargs.RoleARN)
}
var commands []*exec.Cmd
remote := vargs.Remote
if vargs.Cacert != "" {
commands = append(commands, installCaCert(vargs.Cacert))
}
if remote.Backend != "" {
commands = append(commands, deleteCache())
commands = append(commands, remoteConfigCommand(remote))
}
commands = append(commands, getModules())
commands = append(commands, planCommand(vargs.Vars, vargs.Parallelism))
if !vargs.Plan {
commands = append(commands, applyCommand(vargs.Parallelism))
}
commands = append(commands, deleteCache())
for _, c := range commands {
c.Env = os.Environ()
c.Dir = workspace.Path
if c.Dir == "" {
wd, err := os.Getwd()
if err == nil {
c.Dir = wd
}
}
if vargs.RootDir != "" {
c.Dir = c.Dir + "/" + vargs.RootDir
}
c.Stdout = os.Stdout
c.Stderr = os.Stderr
if !vargs.Sensitive {
trace(c)
}
err := c.Run()
if err != nil {
fmt.Println("Error!")
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Command completed successfully")
}
}
示例5: main
func main() {
workspace := plugin.Workspace{}
vargs := S3{}
plugin.Param("workspace", &workspace)
plugin.Param("vargs", &vargs)
plugin.MustParse()
// skip if AWS key or SECRET are empty. A good example for this would
// be forks building a project. S3 might be configured in the source
// repo, but not in the fork
if len(vargs.Key) == 0 || len(vargs.Secret) == 0 {
return
}
// make sure a default region is set
if len(vargs.Region) == 0 {
vargs.Region = "us-east-1"
}
// make sure a default access is set
// let's be conservative and assume private
if len(vargs.Access) == 0 {
vargs.Access = "private"
}
// if the target starts with a "/" we need
// to remove it, otherwise we might adding
// a 3rd slash to s3://
if strings.HasPrefix(vargs.Target, "/") {
vargs.Target = vargs.Target[1:]
}
cmd := command(vargs)
cmd.Env = os.Environ()
if len(vargs.Key) > 0 {
cmd.Env = append(cmd.Env, "AWS_ACCESS_KEY_ID="+vargs.Key)
}
if len(vargs.Secret) > 0 {
cmd.Env = append(cmd.Env, "AWS_SECRET_ACCESS_KEY="+vargs.Secret)
}
cmd.Dir = workspace.Path
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
trace(cmd)
// run the command and exit if failed.
err := cmd.Run()
if err != nil {
os.Exit(1)
}
}
示例6: main
func main() {
v := new(Params)
r := new(plugin.Repo)
b := new(plugin.Build)
w := new(plugin.Workspace)
plugin.Param("repo", r)
plugin.Param("build", b)
plugin.Param("workspace", w)
plugin.Param("vargs", &v)
plugin.MustParse()
err := clone(r, b, w, v)
if err != nil {
os.Exit(1)
}
}
示例7: main
func main() {
fmt.Printf("Drone Mercurial Plugin built at %s\n", buildDate)
v := new(Params)
r := new(plugin.Repo)
b := new(plugin.Build)
w := new(plugin.Workspace)
plugin.Param("repo", r)
plugin.Param("build", b)
plugin.Param("workspace", w)
plugin.Param("vargs", &v)
plugin.MustParse()
err := run(r, b, w, v)
if err != nil {
os.Exit(1)
}
}
示例8: main
func main() {
log.SetFlags(0)
plugin.Param("workspace", &workspace)
plugin.Param("vargs", &vargs)
plugin.MustParse()
sort.Strings(vargs.Gzip) // need for matchGzip
auth, err := google.JWTConfigFromJSON([]byte(vargs.AuthKey), storage.ScopeFullControl)
if err != nil {
fatalf("auth: %v", err)
}
ctx := context.Background()
client, err := storage.NewClient(ctx, cloud.WithTokenSource(auth.TokenSource(ctx)))
if err != nil {
fatalf("storage client: %v", err)
}
run(client)
os.Exit(ecode)
}
示例9: main
func main() {
testExpressions()
workspace := plugin.Workspace{}
repo := plugin.Repo{}
build := plugin.Build{}
vargs := mavendeploy.Maven{}
plugin.Param("repo", &repo)
plugin.Param("build", &build)
plugin.Param("workspace", &workspace)
plugin.Param("vargs", &vargs)
plugin.MustParse()
vargs.WorkspacePath(workspace.Path)
err := vargs.Publish()
if err != nil {
panic(err)
}
}
示例10: main
func main() {
workspace := plugin.Workspace{}
build := plugin.Build{}
vargs := Ansible{}
plugin.Param("workspace", &workspace)
plugin.Param("build", &build)
plugin.Param("vargs", &vargs)
plugin.MustParse()
vargs = setDefaults(vargs)
// write the rsa private key
if err := writeKey(workspace); err != nil {
fmt.Println(err)
os.Exit(1)
}
// write ansible configuration
if err := writeAnsibleConf(); err != nil {
fmt.Println(err)
os.Exit(1)
}
// Run ansible
cmd := command(vargs, workspace)
trace(cmd)
cmd.Env = os.Environ()
cmd.Dir = workspace.Path
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
fmt.Printf("Failed to deploy playbook %s with inventory %s: %s", vargs.Playbook, vargs.Inventory, err)
os.Exit(1)
}
}
示例11: main
func main() {
fmt.Printf("Drone Google Cloud Storage Plugin built from %s\n", buildCommit)
log.SetFlags(0)
plugin.Param("workspace", &workspace)
plugin.Param("vargs", &vargs)
plugin.MustParse()
sort.Strings(vargs.Gzip) // need for matchGzip
rand.Seed(time.Now().UnixNano())
auth, err := google.JWTConfigFromJSON([]byte(vargs.AuthKey), storage.ScopeFullControl)
if err != nil {
fatalf("auth: %v", err)
}
ctx := context.Background()
client, err := storage.NewClient(ctx, cloud.WithTokenSource(auth.TokenSource(ctx)))
if err != nil {
fatalf("storage client: %v", err)
}
run(client)
os.Exit(ecode)
}
示例12: main
func main() {
d := new(deployer)
w := new(plugin.Workspace)
plugin.Param("vargs", d)
plugin.Param("workspace", w)
plugin.MustParse()
// Save ssh keys
if err := os.MkdirAll("/root/.ssh", 0700); err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile("/root/.ssh/config", []byte(SSHConfig), 0644); err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile("/root/.ssh/id_rsa", []byte(w.Keys.Private), 0600); err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile("/root/.ssh/id_rsa.pub", []byte(w.Keys.Public), 0644); err != nil {
log.Fatal(err)
}
c := exec.Command("/bin/dep", "-n", d.Task, d.Stage)
c.Dir = w.Path
c.Stdout = os.Stdout
c.Stderr = os.Stderr
err := c.Run()
if err != nil {
log.Fatal(err)
}
log.Println("Command completed successfully")
}
示例13: main
func main() {
workspace := plugin.Workspace{}
vargs := terraform{}
plugin.Param("workspace", &workspace)
plugin.Param("vargs", &vargs)
plugin.MustParse()
var commands []*exec.Cmd
remote := vargs.Remote
if remote.Backend != "" {
commands = append(commands, remoteConfigCommand(remote))
}
commands = append(commands, planCommand(vargs.Vars))
if !vargs.DryRun {
commands = append(commands, applyCommand())
}
for _, c := range commands {
c.Env = os.Environ()
c.Dir = workspace.Path
c.Stdout = os.Stdout
c.Stderr = os.Stderr
trace(c)
err := c.Run()
if err != nil {
fmt.Println("Error!")
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Command completed successfully")
}
}
示例14: main
func main() {
workspace := plugin.Workspace{}
build := plugin.Build{}
vargs := Docker{}
plugin.Param("workspace", &workspace)
plugin.Param("build", &build)
plugin.Param("vargs", &vargs)
plugin.MustParse()
// in case someone uses the shorthand repository name
// with a custom registry, we should concatinate so that
// we have the fully qualified image name.
if strings.Count(vargs.Repo, "/") == 1 && len(vargs.Registry) != 0 {
vargs.Repo = fmt.Sprintf("%s/%s", vargs.Registry, vargs.Repo)
}
// Set the Registry value
if len(vargs.Registry) == 0 {
vargs.Registry = "https://index.docker.io/v1/"
}
// Set the Dockerfile path
if len(vargs.File) == 0 {
vargs.File = "."
}
// Set the Tag value
if len(vargs.Tag) == 0 {
vargs.Tag = "latest"
}
vargs.Repo = fmt.Sprintf("%s:%s", vargs.Repo, vargs.Tag)
go func() {
args := []string{"-d"}
if len(vargs.Storage) != 0 {
args = append(args, "-s", vargs.Storage)
}
if vargs.Insecure && len(vargs.Registry) != 0 {
args = append(args, "--insecure-registry", vargs.Registry)
}
for _, value := range vargs.Dns {
args = append(args, "--dns", value)
}
cmd := exec.Command("/usr/bin/docker", args...)
if os.Getenv("DOCKER_LAUNCH_DEBUG") == "true" {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
} else {
cmd.Stdout = ioutil.Discard
cmd.Stderr = ioutil.Discard
}
trace(cmd)
cmd.Run()
}()
// ping Docker until available
for i := 0; i < 3; i++ {
cmd := exec.Command("/usr/bin/docker", "info")
cmd.Stdout = ioutil.Discard
cmd.Stderr = ioutil.Discard
err := cmd.Run()
if err == nil {
break
}
time.Sleep(time.Second * 5)
}
// Login to Docker
if len(vargs.Username) != 0 {
cmd := exec.Command("/usr/bin/docker", "login", "-u", vargs.Username, "-p", vargs.Password, "-e", vargs.Email, vargs.Registry)
cmd.Dir = workspace.Path
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
fmt.Println("Login failed.")
os.Exit(1)
}
} else {
fmt.Printf("A username was not specified. Assuming anoynmous publishing.\n")
}
// Docker environment info
cmd := exec.Command("/usr/bin/docker", "version")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
trace(cmd)
cmd.Run()
cmd = exec.Command("/usr/bin/docker", "info")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
trace(cmd)
cmd.Run()
// Build the container
cmd = exec.Command("/usr/bin/docker", "build", "--pull=true", "--rm=true", "-t", vargs.Repo, vargs.File)
cmd.Dir = workspace.Path
cmd.Stdout = os.Stdout
//.........這裏部分代碼省略.........
示例15: main
func main() {
workspace := plugin.Workspace{}
build := plugin.Build{}
vargs := Docker{}
plugin.Param("workspace", &workspace)
plugin.Param("build", &build)
plugin.Param("vargs", &vargs)
plugin.MustParse()
// in case someone uses the shorthand repository name
// with a custom registry, we should concatinate so that
// we have the fully qualified image name.
if strings.Count(vargs.Repo, "/") <= 1 && len(vargs.Registry) != 0 && !strings.HasPrefix(vargs.Repo, vargs.Registry) {
vargs.Repo = fmt.Sprintf("%s/%s", vargs.Registry, vargs.Repo)
}
// Set the Registry value
if len(vargs.Registry) == 0 {
vargs.Registry = "https://index.docker.io/v1/"
}
// Set the Dockerfile name
if len(vargs.File) == 0 {
vargs.File = "Dockerfile"
}
// Set the Context value
if len(vargs.Context) == 0 {
vargs.Context = "."
}
// Set the Tag value
if vargs.Tag.Len() == 0 {
vargs.Tag = StrSlice{[]string{"latest"}}
}
// Get absolute path for 'save' file
if len(vargs.Save.File) != 0 {
if !filepath.IsAbs(vargs.Save.File) {
vargs.Save.File = filepath.Join(workspace.Path, vargs.Save.File)
}
}
// Get absolute path for 'load' file
if len(vargs.Load) != 0 {
if !filepath.IsAbs(vargs.Load) {
vargs.Load = filepath.Join(workspace.Path, vargs.Load)
}
}
go func() {
args := []string{"-d"}
if len(vargs.Storage) != 0 {
args = append(args, "-s", vargs.Storage)
}
if vargs.Insecure && len(vargs.Registry) != 0 {
args = append(args, "--insecure-registry", vargs.Registry)
}
if len(vargs.Mirror) != 0 {
args = append(args, "--registry-mirror", vargs.Mirror)
}
for _, value := range vargs.Dns {
args = append(args, "--dns", value)
}
cmd := exec.Command("/usr/bin/docker", args...)
if os.Getenv("DOCKER_LAUNCH_DEBUG") == "true" {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
} else {
cmd.Stdout = ioutil.Discard
cmd.Stderr = ioutil.Discard
}
trace(cmd)
cmd.Run()
}()
// ping Docker until available
for i := 0; i < 3; i++ {
cmd := exec.Command("/usr/bin/docker", "info")
cmd.Stdout = ioutil.Discard
cmd.Stderr = ioutil.Discard
err := cmd.Run()
if err == nil {
break
}
time.Sleep(time.Second * 5)
}
// Login to Docker
if len(vargs.Username) != 0 {
cmd := exec.Command("/usr/bin/docker", "login", "-u", vargs.Username, "-p", vargs.Password, "-e", vargs.Email, vargs.Registry)
cmd.Dir = workspace.Path
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
fmt.Println("Login failed.")
os.Exit(1)
}
} else {
fmt.Printf("A username was not specified. Assuming anoynmous publishing.\n")
//.........這裏部分代碼省略.........