本文整理汇总了Golang中github.com/flynn/flynn/bootstrap.Manifest类的典型用法代码示例。如果您正苦于以下问题:Golang Manifest类的具体用法?Golang Manifest怎么用?Golang Manifest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Manifest类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runBootstrapBackup
//.........这里部分代码省略.........
"json" jsonb,
"key_to_set" TEXT,
"value_to_set" TEXT
)
RETURNS jsonb
LANGUAGE sql
IMMUTABLE
STRICT
AS $function$
SELECT ('{' || string_agg(to_json("key") || ':' || "value", ',') || '}')::jsonb
FROM (SELECT *
FROM json_each("json"::json)
WHERE "key" <> "key_to_set"
UNION ALL
SELECT "key_to_set", to_json("value_to_set")) AS "fields"
$function$;
`)
type manifestStep struct {
ID string
Artifacts []*ct.Artifact
Artifact *ct.Artifact
Release struct {
Env map[string]string
Processes map[string]ct.ProcessType
}
}
var manifestSteps []*manifestStep
if err := json.Unmarshal(manifest, &manifestSteps); err != nil {
return fmt.Errorf("error decoding manifest json: %s", err)
}
manifestStepMap := make(map[string]bootstrap.Step, len(manifestSteps))
steps, err := bootstrap.UnmarshalManifest(manifest, nil)
if err != nil {
return fmt.Errorf("error decoding manifest json: %s", err)
}
for _, step := range steps {
manifestStepMap[step.StepMeta.ID] = step
}
artifacts := make(map[string]*ct.Artifact)
updateProcArgs := func(f *ct.ExpandedFormation, step *manifestStep) {
for typ, proc := range step.Release.Processes {
p := f.Release.Processes[typ]
p.Args = proc.Args
f.Release.Processes[typ] = p
}
}
updateVolumes := func(f *ct.ExpandedFormation, step *manifestStep) {
for typ, proc := range step.Release.Processes {
p := f.Release.Processes[typ]
p.Volumes = proc.Volumes
f.Release.Processes[typ] = p
}
}
for _, step := range manifestSteps {
switch step.ID {
case "discoverd":
updateVolumes(data.Discoverd, step)
case "postgres":
updateProcArgs(data.Postgres, step)
updateVolumes(data.Postgres, step)
case "controller":
updateProcArgs(data.Controller, step)
case "mariadb":
示例2: runBootstrapBackup
//.........这里部分代码省略.........
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{
URL: "http://mongodb-api.discoverd/ping",
示例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
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, clusterURL, hostIPs, minHosts, timeout)
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",
"PGDATABASE": "postgres",
示例4: runBootstrapBackup
//.........这里部分代码省略.........
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(`
UPDATE releases SET env = pg_temp.json_object_update_key(env, 'DISCOVERD_PEERS', '%s')