本文整理匯總了Golang中github.com/flynn/flynn/controller/types.App類的典型用法代碼示例。如果您正苦於以下問題:Golang App類的具體用法?Golang App怎麽用?Golang App使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了App類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: deployApp
func deployApp(client *controller.Client, app *ct.App, uri string, log log15.Logger) error {
release, err := client.GetAppRelease(app.ID)
if err != nil {
log.Error("error getting release", "err", err)
return err
}
artifact, err := client.GetArtifact(release.ArtifactID)
if err != nil {
log.Error("error getting release artifact", "err", err)
return err
}
if !app.System() {
u, err := url.Parse(artifact.URI)
if err != nil {
return err
}
if u.Query().Get("name") != "flynn/slugrunner" {
return errDeploySkipped{"app not using slugrunner image"}
}
}
skipDeploy := artifact.URI == uri
// deploy the gitreceive / taffy apps if builder / runner images have changed
switch app.Name {
case "gitreceive":
proc, ok := release.Processes["app"]
if !ok {
e := "missing app process in gitreceive release"
log.Error(e)
return errors.New(e)
}
if updateSlugURIs(proc.Env) {
skipDeploy = false
}
release.Processes["app"] = proc
case "taffy":
if updateSlugURIs(release.Env) {
skipDeploy = false
}
}
if skipDeploy {
return errDeploySkipped{"app is already using latest images"}
}
artifact.ID = ""
artifact.URI = uri
if err := client.CreateArtifact(artifact); err != nil {
log.Error("error creating artifact", "err", err)
return err
}
release.ID = ""
release.ArtifactID = artifact.ID
if err := client.CreateRelease(release); err != nil {
log.Error("error creating new release", "err", err)
return err
}
if err := client.DeployAppRelease(app.ID, release.ID); err != nil {
log.Error("error deploying app", "err", err)
return err
}
return nil
}
示例2: deployApp
func deployApp(client controller.Client, app *ct.App, uri string, updateFn updater.UpdateReleaseFn, log log15.Logger) error {
release, err := client.GetAppRelease(app.ID)
if err != nil {
log.Error("error getting release", "err", err)
return err
}
artifact, err := client.GetArtifact(release.ImageArtifactID())
if err != nil {
log.Error("error getting release artifact", "err", err)
return err
}
if !app.System() {
u, err := url.Parse(artifact.URI)
if err != nil {
return err
}
if u.Query().Get("name") != "flynn/slugrunner" {
return errDeploySkipped{"app not using slugrunner image"}
}
}
skipDeploy := artifact.URI == uri
if updateImageIDs(release.Env) {
skipDeploy = false
}
if skipDeploy {
return errDeploySkipped{"app is already using latest images"}
}
artifact.ID = ""
artifact.URI = uri
if err := client.CreateArtifact(artifact); err != nil {
log.Error("error creating artifact", "err", err)
return err
}
release.ID = ""
release.SetImageArtifactID(artifact.ID)
if updateFn != nil {
updateFn(release)
}
if err := client.CreateRelease(release); err != nil {
log.Error("error creating new release", "err", err)
return err
}
timeoutCh := make(chan struct{})
time.AfterFunc(deployTimeout, func() { close(timeoutCh) })
if err := client.DeployAppRelease(app.ID, release.ID, timeoutCh); err != nil {
log.Error("error deploying app", "err", err)
return err
}
return nil
}
示例3: deployApp
func deployApp(client controller.Client, app *ct.App, uri string, updateFn updater.UpdateReleaseFn, log log15.Logger) error {
release, err := client.GetAppRelease(app.ID)
if err != nil {
log.Error("error getting release", "err", err)
return err
}
artifact, err := client.GetArtifact(release.ImageArtifactID())
if err != nil {
log.Error("error getting release artifact", "err", err)
return err
}
if !app.System() {
u, err := url.Parse(artifact.URI)
if err != nil {
return err
}
if u.Query().Get("name") != "flynn/slugrunner" {
return errDeploySkipped{"app not using slugrunner image"}
}
}
skipDeploy := artifact.URI == uri
if updateSlugURIs(release.Env) {
skipDeploy = false // deploy apps that depend on slugbuilder images if updated
}
if skipDeploy {
return errDeploySkipped{"app is already using latest images"}
}
artifact.ID = ""
artifact.URI = uri
if err := client.CreateArtifact(artifact); err != nil {
log.Error("error creating artifact", "err", err)
return err
}
release.ID = ""
release.SetImageArtifactID(artifact.ID)
if updateFn != nil {
updateFn(release)
}
if err := client.CreateRelease(release); err != nil {
log.Error("error creating new release", "err", err)
return err
}
if err := client.DeployAppRelease(app.ID, release.ID); err != nil {
log.Error("error deploying app", "err", err)
return err
}
return nil
}
示例4: SetRelease
func (r *AppRepo) SetRelease(app *ct.App, releaseID string) error {
tx, err := r.db.Begin()
if err != nil {
return err
}
var release *ct.Release
row := tx.QueryRow("SELECT release_id, artifact_id, data, created_at FROM releases WHERE release_id = $1 AND deleted_at IS NULL", releaseID)
if release, err = scanRelease(row); err != nil {
return err
}
app.ReleaseID = releaseID
if _, err := tx.Exec("UPDATE apps SET release_id = $2, updated_at = now() WHERE app_id = $1", app.ID, app.ReleaseID); err != nil {
tx.Rollback()
return err
}
if err := createEvent(tx.Exec, &ct.Event{
AppID: app.ID,
ObjectID: release.ID,
ObjectType: ct.EventTypeAppRelease,
}, release); err != nil {
tx.Rollback()
return err
}
return tx.Commit()
}
示例5: SetRelease
func (r *AppRepo) SetRelease(app *ct.App, releaseID string) error {
tx, err := r.db.Begin()
if err != nil {
return err
}
var release *ct.Release
var prevRelease *ct.Release
if app.ReleaseID != "" {
row := tx.QueryRow("release_select", app.ReleaseID)
prevRelease, _ = scanRelease(row)
}
row := tx.QueryRow("release_select", releaseID)
if release, err = scanRelease(row); err != nil {
return err
}
app.ReleaseID = releaseID
if err := tx.Exec("app_update_release", app.ID, app.ReleaseID); err != nil {
tx.Rollback()
return err
}
if err := createEvent(tx.Exec, &ct.Event{
AppID: app.ID,
ObjectID: release.ID,
ObjectType: ct.EventTypeAppRelease,
}, &ct.AppRelease{
PrevRelease: prevRelease,
Release: release,
}); err != nil {
tx.Rollback()
return err
}
return tx.Commit()
}
示例6: deployApp
func deployApp(client controller.Client, app *ct.App, image *ct.Artifact, updateFn updater.UpdateReleaseFn, log log15.Logger) error {
release, err := client.GetAppRelease(app.ID)
if err != nil {
log.Error("error getting release", "err", err)
return err
}
if len(release.ArtifactIDs) == 0 {
return errDeploySkipped{"release has no artifacts"}
}
artifact, err := client.GetArtifact(release.ArtifactIDs[0])
if err != nil {
log.Error("error getting release artifact", "err", err)
return err
}
if !app.System() && release.IsGitDeploy() {
if artifact.Meta["flynn.component"] != "slugrunner" {
return errDeploySkipped{"app not using slugrunner image"}
}
}
skipDeploy := artifact.Manifest().ID() == image.Manifest().ID()
if updateImageIDs(release.Env) {
skipDeploy = false
}
if skipDeploy {
return errDeploySkipped{"app is already using latest images"}
}
if err := client.CreateArtifact(image); err != nil {
log.Error("error creating artifact", "err", err)
return err
}
release.ID = ""
release.ArtifactIDs[0] = image.ID
if updateFn != nil {
updateFn(release)
}
if err := client.CreateRelease(release); err != nil {
log.Error("error creating new release", "err", err)
return err
}
timeoutCh := make(chan struct{})
time.AfterFunc(deployTimeout, func() { close(timeoutCh) })
if err := client.DeployAppRelease(app.ID, release.ID, timeoutCh); err != nil {
log.Error("error deploying app", "err", err)
return err
}
return nil
}
示例7: runMetaSet
func runMetaSet(app *types.App, args *docopt.Args, client controller.Client) error {
pairs := args.All["<var>=<val>"].([]string)
if app.Meta == nil {
app.Meta = make(map[string]string, len(pairs))
}
for _, s := range pairs {
v := strings.SplitN(s, "=", 2)
if len(v) != 2 {
return fmt.Errorf("invalid var format: %q", s)
}
app.Meta[v[0]] = v[1]
}
return client.UpdateAppMeta(app)
}
示例8: SetRelease
func (r *AppRepo) SetRelease(app *ct.App, releaseID string) error {
tx, err := r.db.Begin()
if err != nil {
return err
}
app.ReleaseID = releaseID
if _, err := tx.Exec("UPDATE apps SET release_id = $2, updated_at = now() WHERE app_id = $1", app.ID, app.ReleaseID); err != nil {
tx.Rollback()
return err
}
if err := createEvent(tx.Exec, &ct.Event{
AppID: app.ID,
ObjectID: app.ID,
ObjectType: ct.EventTypeApp,
}, app); err != nil {
tx.Rollback()
return err
}
return tx.Commit()
}
示例9: runImport
func runImport(args *docopt.Args, client controller.Client) error {
var src io.Reader = os.Stdin
if filename := args.String["--file"]; filename != "" {
f, err := os.Open(filename)
if err != nil {
return fmt.Errorf("error opening export file: %s", err)
}
defer f.Close()
src = f
}
tr := tar.NewReader(src)
var (
app *ct.App
release *ct.Release
imageArtifact *ct.Artifact
formation *ct.Formation
routes []router.Route
slug io.Reader
dockerImage struct {
config struct {
Tag string `json:"tag"`
}
archive io.Reader
}
pgDump io.Reader
mysqlDump io.Reader
uploadSize int64
)
numResources := 0
numRoutes := 1
for {
header, err := tr.Next()
if err == io.EOF {
break
} else if err != nil {
return fmt.Errorf("error reading export tar: %s", err)
}
switch path.Base(header.Name) {
case "app.json":
app = &ct.App{}
if err := json.NewDecoder(tr).Decode(app); err != nil {
return fmt.Errorf("error decoding app: %s", err)
}
app.ID = ""
case "release.json":
release = &ct.Release{}
if err := json.NewDecoder(tr).Decode(release); err != nil {
return fmt.Errorf("error decoding release: %s", err)
}
release.ID = ""
release.ArtifactIDs = nil
case "artifact.json":
imageArtifact = &ct.Artifact{}
if err := json.NewDecoder(tr).Decode(imageArtifact); err != nil {
return fmt.Errorf("error decoding image artifact: %s", err)
}
imageArtifact.ID = ""
case "formation.json":
formation = &ct.Formation{}
if err := json.NewDecoder(tr).Decode(formation); err != nil {
return fmt.Errorf("error decoding formation: %s", err)
}
formation.AppID = ""
formation.ReleaseID = ""
case "routes.json":
if err := json.NewDecoder(tr).Decode(&routes); err != nil {
return fmt.Errorf("error decoding routes: %s", err)
}
for _, route := range routes {
route.ID = ""
route.ParentRef = ""
}
case "slug.tar.gz":
f, err := ioutil.TempFile("", "slug.tar.gz")
if err != nil {
return fmt.Errorf("error creating slug tempfile: %s", err)
}
defer f.Close()
defer os.Remove(f.Name())
if _, err := io.Copy(f, tr); err != nil {
return fmt.Errorf("error reading slug: %s", err)
}
if _, err := f.Seek(0, os.SEEK_SET); err != nil {
return fmt.Errorf("error seeking slug tempfile: %s", err)
}
slug = f
uploadSize += header.Size
case "docker-image.json":
if err := json.NewDecoder(tr).Decode(&dockerImage.config); err != nil {
return fmt.Errorf("error decoding docker image json: %s", err)
}
case "docker-image.tar":
f, err := ioutil.TempFile("", "docker-image.tar")
if err != nil {
return fmt.Errorf("error creating docker image tempfile: %s", err)
}
defer f.Close()
//.........這裏部分代碼省略.........
示例10: runImport
func runImport(args *docopt.Args, client *controller.Client) error {
var src io.Reader = os.Stdin
if filename := args.String["--file"]; filename != "" {
f, err := os.Open(filename)
if err != nil {
return fmt.Errorf("error opening export file: %s", err)
}
defer f.Close()
src = f
}
tr := tar.NewReader(src)
var (
app *ct.App
release *ct.Release
artifact *ct.Artifact
formation *ct.Formation
routes []router.Route
slug io.Reader
pgDump io.Reader
uploadSize int64
)
numResources := 0
numRoutes := 1
for {
header, err := tr.Next()
if err == io.EOF {
break
} else if err != nil {
return fmt.Errorf("error reading export tar: %s", err)
}
switch path.Base(header.Name) {
case "app.json":
app = &ct.App{}
if err := json.NewDecoder(tr).Decode(app); err != nil {
return fmt.Errorf("error decoding app: %s", err)
}
app.ID = ""
case "release.json":
release = &ct.Release{}
if err := json.NewDecoder(tr).Decode(release); err != nil {
return fmt.Errorf("error decoding release: %s", err)
}
release.ID = ""
release.ArtifactID = ""
case "artifact.json":
artifact = &ct.Artifact{}
if err := json.NewDecoder(tr).Decode(artifact); err != nil {
return fmt.Errorf("error decoding artifact: %s", err)
}
artifact.ID = ""
case "formation.json":
formation = &ct.Formation{}
if err := json.NewDecoder(tr).Decode(formation); err != nil {
return fmt.Errorf("error decoding formation: %s", err)
}
formation.AppID = ""
formation.ReleaseID = ""
case "routes.json":
if err := json.NewDecoder(tr).Decode(&routes); err != nil {
return fmt.Errorf("error decoding routes: %s", err)
}
for _, route := range routes {
route.ID = ""
route.ParentRef = ""
}
case "slug.tar.gz":
f, err := ioutil.TempFile("", "slug.tar.gz")
if err != nil {
return fmt.Errorf("error creating slug tempfile: %s", err)
}
defer f.Close()
defer os.Remove(f.Name())
if _, err := io.Copy(f, tr); err != nil {
return fmt.Errorf("error reading slug: %s", err)
}
if _, err := f.Seek(0, os.SEEK_SET); err != nil {
return fmt.Errorf("error seeking slug tempfile: %s", err)
}
slug = f
uploadSize += header.Size
case "postgres.dump":
f, err := ioutil.TempFile("", "postgres.dump")
if err != nil {
return fmt.Errorf("error creating db tempfile: %s", err)
}
defer f.Close()
defer os.Remove(f.Name())
if _, err := io.Copy(f, tr); err != nil {
return fmt.Errorf("error reading db dump: %s", err)
}
if _, err := f.Seek(0, os.SEEK_SET); err != nil {
return fmt.Errorf("error seeking db tempfile: %s", err)
}
pgDump = f
uploadSize += header.Size
}
}
//.........這裏部分代碼省略.........
示例11: runImport
func runImport(args *docopt.Args, client controller.Client) error {
jobs, err := strconv.Atoi(args.String["--jobs"])
if err != nil {
return err
}
var src io.Reader = os.Stdin
if filename := args.String["--file"]; filename != "" {
f, err := os.Open(filename)
if err != nil {
return fmt.Errorf("error opening export file: %s", err)
}
defer f.Close()
src = f
}
tr := tar.NewReader(src)
var (
app *ct.App
release *ct.Release
artifacts []*ct.Artifact
formation *ct.Formation
routes []router.Route
legacySlug io.Reader
dockerImage struct {
config struct {
Tag string `json:"tag"`
}
archive io.Reader
}
pgDump io.Reader
mysqlDump io.Reader
uploadSize int64
)
numResources := 0
numRoutes := 1
layers := make(map[string]io.Reader)
for {
header, err := tr.Next()
if err == io.EOF {
break
} else if err != nil {
return fmt.Errorf("error reading export tar: %s", err)
}
filename := path.Base(header.Name)
if strings.HasSuffix(filename, ".layer") {
f, err := ioutil.TempFile("", "flynn-layer-")
if err != nil {
return fmt.Errorf("error creating layer tempfile: %s", err)
}
defer f.Close()
defer os.Remove(f.Name())
if _, err := io.Copy(f, tr); err != nil {
return fmt.Errorf("error reading %s: %s", header.Name, err)
}
if _, err := f.Seek(0, os.SEEK_SET); err != nil {
return fmt.Errorf("error seeking layer tempfile: %s", err)
}
layers[strings.TrimSuffix(filename, ".layer")] = f
uploadSize += header.Size
continue
}
switch filename {
case "app.json":
app = &ct.App{}
if err := json.NewDecoder(tr).Decode(app); err != nil {
return fmt.Errorf("error decoding app: %s", err)
}
app.ID = ""
case "release.json":
release = &ct.Release{}
if err := json.NewDecoder(tr).Decode(release); err != nil {
return fmt.Errorf("error decoding release: %s", err)
}
release.ID = ""
release.ArtifactIDs = nil
case "artifacts.json":
if err := json.NewDecoder(tr).Decode(&artifacts); err != nil {
return fmt.Errorf("error decoding artifacts: %s", err)
}
case "formation.json":
formation = &ct.Formation{}
if err := json.NewDecoder(tr).Decode(formation); err != nil {
return fmt.Errorf("error decoding formation: %s", err)
}
formation.AppID = ""
formation.ReleaseID = ""
case "routes.json":
if err := json.NewDecoder(tr).Decode(&routes); err != nil {
return fmt.Errorf("error decoding routes: %s", err)
}
for _, route := range routes {
route.ID = ""
route.ParentRef = ""
}
case "slug.tar.gz":
f, err := ioutil.TempFile("", "slug.tar.gz")
if err != nil {
//.........這裏部分代碼省略.........