本文整理匯總了Golang中github.com/flynn/flynn/bootstrap.Config.Singleton方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.Singleton方法的具體用法?Golang Config.Singleton怎麽用?Golang Config.Singleton使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/flynn/flynn/bootstrap.Config
的用法示例。
在下文中一共展示了Config.Singleton方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runBootstrap
func runBootstrap(args *docopt.Args) error {
log.SetFlags(log.Lmicroseconds)
logf := textLogger
if args.Bool["--json"] {
logf = jsonLogger
}
var cfg bootstrap.Config
manifestFile := args.String["<manifest>"]
if manifestFile == "" {
manifestFile = "/etc/flynn/bootstrap-manifest.json"
}
var steps []string
if s := args.String["--steps"]; s != "" {
steps = strings.Split(s, ",")
}
var err error
manifest, err = readBootstrapManifest(manifestFile)
if err != nil {
return fmt.Errorf("Error reading manifest: %s", err)
}
if n := args.String["--min-hosts"]; n != "" {
if cfg.MinHosts, err = strconv.Atoi(n); err != nil || cfg.MinHosts < 1 {
return fmt.Errorf("invalid --min-hosts value")
}
}
cfg.Timeout, err = strconv.Atoi(args.String["--timeout"])
if err != nil {
return fmt.Errorf("invalid --timeout value")
}
if ipList := args.String["--peer-ips"]; ipList != "" {
cfg.IPs = strings.Split(ipList, ",")
if cfg.MinHosts == 0 {
cfg.MinHosts = len(cfg.IPs)
}
}
if cfg.MinHosts == 0 {
cfg.MinHosts = 1
}
cfg.Singleton = cfg.MinHosts == 1
if s := os.Getenv("SINGLETON"); s != "" {
cfg.Singleton = s == "true"
}
ch := make(chan *bootstrap.StepInfo)
done := make(chan struct{})
var last error
go func() {
for si := range ch {
logf(si)
last = si.Err
}
close(done)
}()
cfg.ClusterURL = args.String["--discovery"]
if bf := args.String["--from-backup"]; bf != "" {
err = runBootstrapBackup(manifest, bf, ch, cfg)
} else {
err = bootstrap.Run(manifest, ch, cfg, steps)
}
<-done
if err != nil && last != nil && err.Error() == last.Error() {
return ErrAlreadyLogged{err}
}
return err
}
示例2: runBootstrapBackup
//.........這裏部分代碼省略.........
OR uri = (SELECT env->>'%[2]s_IMAGE_URI' FROM releases WHERE release_id = (SELECT release_id FROM apps WHERE name = 'gitreceive'));`,
artifactURIs[name+"-image"], strings.ToUpper(name)))
}
// update the URI of redis artifacts currently being referenced by
// the redis app (which will also update all current redis
// resources to use the latest redis image)
sqlBuf.WriteString(fmt.Sprintf(`
UPDATE artifacts SET uri = '%s'
WHERE artifact_id = (SELECT (env->>'REDIS_IMAGE_ID')::uuid FROM releases WHERE release_id = (SELECT release_id FROM apps WHERE name = 'redis'))
OR uri = (SELECT env->>'REDIS_IMAGE_URI' FROM releases WHERE release_id = (SELECT release_id FROM apps WHERE name = 'redis'));`,
artifactURIs["redis-image"]))
// ensure the image ID environment variables are set for legacy apps
// which use image URI variables
for _, name := range []string{"redis", "slugbuilder", "slugrunner"} {
sqlBuf.WriteString(fmt.Sprintf(`
UPDATE releases SET env = pg_temp.json_object_update_key(env, '%[1]s_IMAGE_ID', (SELECT artifact_id::text FROM artifacts WHERE uri = '%[2]s'))
WHERE env->>'%[1]s_IMAGE_URI' IS NOT NULL;`,
strings.ToUpper(name), artifactURIs[name+"-image"]))
}
step := func(id, name string, action bootstrap.Action) bootstrap.Step {
if ra, ok := action.(*bootstrap.RunAppAction); ok {
ra.ID = id
}
return bootstrap.Step{
StepMeta: bootstrap.StepMeta{ID: id, Action: name},
Action: action,
}
}
// start discoverd/flannel/postgres/mariadb
cfg.Singleton = data.Postgres.Release.Env["SINGLETON"] == "true"
systemSteps := bootstrap.Manifest{
step("discoverd", "run-app", &bootstrap.RunAppAction{
ExpandedFormation: data.Discoverd,
}),
step("flannel", "run-app", &bootstrap.RunAppAction{
ExpandedFormation: data.Flannel,
}),
step("wait-hosts", "wait-hosts", &bootstrap.WaitHostsAction{}),
step("postgres", "run-app", &bootstrap.RunAppAction{
ExpandedFormation: data.Postgres,
}),
step("postgres-wait", "wait", &bootstrap.WaitAction{
URL: "http://postgres-api.discoverd/ping",
}),
}
// Only run up MariaDB if it's in the backup
if data.MariaDB != nil {
systemSteps = append(systemSteps, step("mariadb", "run-app", &bootstrap.RunAppAction{
ExpandedFormation: data.MariaDB,
}))
systemSteps = append(systemSteps, step("mariadb-wait", "wait", &bootstrap.WaitAction{
URL: "http://mariadb-api.discoverd/ping",
}))
}
// Only run up MongoDB if it's in the backup
if data.MongoDB != nil {
systemSteps = append(systemSteps, step("mongodb", "run-app", &bootstrap.RunAppAction{
ExpandedFormation: data.MongoDB,
}))
systemSteps = append(systemSteps, step("mongodb-wait", "wait", &bootstrap.WaitAction{
示例3: runBootstrapBackup
//.........這裏部分代碼省略.........
UPDATE artifacts SET uri = '%s'
WHERE artifact_id = (SELECT artifact_id FROM releases
WHERE release_id = (SELECT release_id FROM apps
WHERE name = '%s'));`, step.Artifact.URI, step.ID))
}
}
data.Discoverd.Artifact.URI = artifactURIs["discoverd"]
data.Discoverd.Release.Env["DISCOVERD_PEERS"] = "{{ range $ip := .SortedHostIPs }}{{ $ip }}:1110,{{ end }}"
data.Postgres.Artifact.URI = artifactURIs["postgres"]
data.Flannel.Artifact.URI = artifactURIs["flannel"]
data.Controller.Artifact.URI = artifactURIs["controller"]
for _, app := range []string{"gitreceive", "taffy"} {
for _, env := range []string{"slugbuilder", "slugrunner"} {
sqlBuf.WriteString(fmt.Sprintf(`
UPDATE releases SET env = pg_temp.json_object_update_key(env, '%s_IMAGE_URI', '%s')
WHERE release_id = (SELECT release_id from apps WHERE name = '%s');`,
strings.ToUpper(env), artifactURIs[env], app))
}
}
step := func(id, name string, action bootstrap.Action) bootstrap.Step {
if ra, ok := action.(*bootstrap.RunAppAction); ok {
ra.ID = id
}
return bootstrap.Step{
StepMeta: bootstrap.StepMeta{ID: id, Action: name},
Action: action,
}
}
// start discoverd/flannel/postgres
cfg.Singleton = data.Postgres.Release.Env["SINGLETON"] == "true"
steps := bootstrap.Manifest{
step("discoverd", "run-app", &bootstrap.RunAppAction{
ExpandedFormation: data.Discoverd,
}),
step("flannel", "run-app", &bootstrap.RunAppAction{
ExpandedFormation: data.Flannel,
}),
step("wait-hosts", "wait-hosts", &bootstrap.WaitHostsAction{}),
step("postgres", "run-app", &bootstrap.RunAppAction{
ExpandedFormation: data.Postgres,
}),
step("postgres-wait", "wait", &bootstrap.WaitAction{
URL: "http://postgres-api.discoverd/ping",
}),
}
state, err := steps.Run(ch, cfg)
if err != nil {
return err
}
// set DISCOVERD_PEERS in release
sqlBuf.WriteString(fmt.Sprintf(`
UPDATE releases SET env = pg_temp.json_object_update_key(env, 'DISCOVERD_PEERS', '%s')
WHERE release_id = (SELECT release_id FROM apps WHERE name = 'discoverd')
`, state.StepData["discoverd"].(*bootstrap.RunAppState).Release.Env["DISCOVERD_PEERS"]))
// load data into postgres
cmd := exec.JobUsingHost(state.Hosts[0], host.Artifact{Type: data.Postgres.Artifact.Type, URI: data.Postgres.Artifact.URI}, nil)
cmd.Entrypoint = []string{"psql"}
cmd.Env = map[string]string{
"PGHOST": "leader.postgres.discoverd",
"PGUSER": "flynn",
示例4: runBootstrapBackup
//.........這裏部分代碼省略.........
if data.MariaDB != nil {
data.MariaDB.Artifact.URI = artifactURIs["mariadb"]
if data.MariaDB.Processes["mariadb"] == 0 {
// skip mariadb if it wasn't scaled up in the backup
data.MariaDB = nil
}
}
sqlBuf.WriteString(fmt.Sprintf(`
UPDATE artifacts SET uri = '%s'
WHERE uri = (SELECT env->>'SLUGRUNNER_IMAGE_URI' FROM releases WHERE release_id = (SELECT release_id FROM apps WHERE name = 'gitreceive'));`,
artifactURIs["slugrunner"]))
for _, app := range []string{"gitreceive", "taffy"} {
for _, env := range []string{"slugbuilder", "slugrunner"} {
sqlBuf.WriteString(fmt.Sprintf(`
UPDATE releases SET env = pg_temp.json_object_update_key(env, '%s_IMAGE_URI', '%s')
WHERE release_id = (SELECT release_id from apps WHERE name = '%s');`,
strings.ToUpper(env), artifactURIs[env], app))
}
}
step := func(id, name string, action bootstrap.Action) bootstrap.Step {
if ra, ok := action.(*bootstrap.RunAppAction); ok {
ra.ID = id
}
return bootstrap.Step{
StepMeta: bootstrap.StepMeta{ID: id, Action: name},
Action: action,
}
}
// start discoverd/flannel/postgres/mariadb
cfg.Singleton = data.Postgres.Release.Env["SINGLETON"] == "true"
systemSteps := bootstrap.Manifest{
step("discoverd", "run-app", &bootstrap.RunAppAction{
ExpandedFormation: data.Discoverd,
}),
step("flannel", "run-app", &bootstrap.RunAppAction{
ExpandedFormation: data.Flannel,
}),
step("wait-hosts", "wait-hosts", &bootstrap.WaitHostsAction{}),
step("postgres", "run-app", &bootstrap.RunAppAction{
ExpandedFormation: data.Postgres,
}),
step("postgres-wait", "wait", &bootstrap.WaitAction{
URL: "http://postgres-api.discoverd/ping",
}),
}
// Only run up MariaDB if it's in the backup
if data.MariaDB != nil {
systemSteps = append(systemSteps, step("mariadb", "run-app", &bootstrap.RunAppAction{
ExpandedFormation: data.MariaDB,
}))
systemSteps = append(systemSteps, step("mariadb-wait", "wait", &bootstrap.WaitAction{
URL: "http://mariadb-api.discoverd/ping",
}))
}
state, err := systemSteps.Run(ch, cfg)
if err != nil {
return err
}
// set DISCOVERD_PEERS in release
sqlBuf.WriteString(fmt.Sprintf(`