本文整理匯總了Golang中github.com/flynn/flynn/controller/types.Release類的典型用法代碼示例。如果您正苦於以下問題:Golang Release類的具體用法?Golang Release怎麽用?Golang Release使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Release類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createTestRelease
func (s *S) createTestRelease(c *C, in *ct.Release) *ct.Release {
if len(in.ArtifactIDs) == 0 {
in.ArtifactIDs = []string{s.createTestArtifact(c, &ct.Artifact{Type: host.ArtifactTypeDocker}).ID}
in.LegacyArtifactID = in.ArtifactIDs[0]
}
c.Assert(s.c.CreateRelease(in), IsNil)
return in
}
示例2: createTestRelease
func (s *S) createTestRelease(c *C, in *ct.Release) *ct.Release {
if in.ArtifactID == "" {
in.ArtifactID = s.createTestArtifact(c, &ct.Artifact{}).ID
}
c.Assert(s.c.CreateRelease(in), IsNil)
return in
}
示例3: createTestRelease
func (s *S) createTestRelease(c *C, in *ct.Release) *ct.Release {
if in.ArtifactID == "" {
in.ArtifactID = s.createTestArtifact(c, &ct.Artifact{}).ID
}
out := &ct.Release{}
res, err := s.Post("/releases", in, out)
c.Assert(err, IsNil)
c.Assert(res.StatusCode, Equals, 200)
return out
}
示例4: 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()
//.........這裏部分代碼省略.........
示例5: 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
}
}
//.........這裏部分代碼省略.........
示例6: Delete
// Delete deletes any formations for the given app and release, then deletes
// the release and any associated file artifacts if there are no remaining
// formations for the release, enqueueing a worker job to delete any files
// stored in the blobstore
func (r *ReleaseRepo) Delete(app *ct.App, release *ct.Release) error {
tx, err := r.db.Begin()
if err != nil {
return err
}
if err := tx.Exec("formation_delete", app.ID, release.ID); err != nil {
tx.Rollback()
return err
}
// if the release still has formations, don't remove it entirely, just
// save a release deletion event and return
rows, err := tx.Query("formation_list_by_release", release.ID)
if err != nil {
tx.Rollback()
return err
}
formations, err := scanFormations(rows)
if err != nil {
tx.Rollback()
return err
}
if len(formations) > 0 {
apps := make([]string, len(formations))
for i, f := range formations {
apps[i] = f.AppID
}
event := ct.ReleaseDeletionEvent{
ReleaseDeletion: &ct.ReleaseDeletion{
RemainingApps: apps,
ReleaseID: release.ID,
},
}
if err := createEvent(tx.Exec, &ct.Event{
AppID: app.ID,
ObjectID: release.ID,
ObjectType: ct.EventTypeReleaseDeletion,
}, event); err != nil {
tx.Rollback()
return err
}
return tx.Commit()
}
fileArtifacts, err := r.artifacts.ListIDs(release.FileArtifactIDs()...)
if err != nil {
return err
}
if err := tx.Exec("release_delete", release.ID); err != nil {
tx.Rollback()
return err
}
blobstoreFiles := make([]string, 0, len(fileArtifacts))
for _, artifact := range fileArtifacts {
if err := tx.Exec("release_artifacts_delete", release.ID, artifact.ID); err != nil {
tx.Rollback()
return err
}
// only delete artifacts which aren't still referenced by other releases
var count int64
if err := tx.QueryRow("artifact_release_count", artifact.ID).Scan(&count); err != nil {
tx.Rollback()
return err
}
if count > 0 {
continue
}
if artifact.Blobstore() {
blobstoreFiles = append(blobstoreFiles, artifact.URI)
}
if err := tx.Exec("artifact_delete", artifact.ID); err != nil {
tx.Rollback()
return err
}
}
// if there are no blobstore files to delete, just save a release
// deletion event and return
if len(blobstoreFiles) == 0 {
event := ct.ReleaseDeletionEvent{
ReleaseDeletion: &ct.ReleaseDeletion{
ReleaseID: release.ID,
},
}
if err := createEvent(tx.Exec, &ct.Event{
AppID: app.ID,
ObjectID: release.ID,
ObjectType: ct.EventTypeReleaseDeletion,
}, event); err != nil {
tx.Rollback()
return err
//.........這裏部分代碼省略.........
示例7: runReleaseUpdate
func runReleaseUpdate(args *docopt.Args, client controller.Client) error {
var release *ct.Release
var err error
if args.String["<id>"] != "" {
release, err = client.GetRelease(args.String["<id>"])
} else {
release, err = client.GetAppRelease(mustApp())
}
if err != nil {
return err
}
updates := &ct.Release{}
data, err := ioutil.ReadFile(args.String["<file>"])
if err != nil {
return err
}
if err := json.Unmarshal(data, updates); err != nil {
return err
}
// Basically, there's no way to merge JSON that can reliably knock out set values.
// Instead, throw the --clean flag to start from a largely empty Release.
if args.Bool["--clean"] {
updates.ArtifactIDs = release.ArtifactIDs
release = updates
} else {
release.ID = ""
for key, value := range updates.Env {
release.Env[key] = value
}
for key, value := range updates.Meta {
release.Meta[key] = value
}
for procKey, procUpdate := range updates.Processes {
procRelease, ok := release.Processes[procKey]
if !ok {
release.Processes[procKey] = procUpdate
continue
}
if len(procUpdate.Cmd) > 0 {
procRelease.Cmd = procUpdate.Cmd
}
if len(procUpdate.Entrypoint) > 0 {
procRelease.Entrypoint = procUpdate.Entrypoint
}
for key, value := range procUpdate.Env {
procRelease.Env[key] = value
}
if len(procUpdate.Ports) > 0 {
procRelease.Ports = procUpdate.Ports
}
if procUpdate.Data {
procRelease.Data = true
}
if procUpdate.Omni {
procRelease.Omni = true
}
if procUpdate.HostNetwork {
procRelease.HostNetwork = true
}
if len(procUpdate.Service) > 0 {
procRelease.Service = procUpdate.Service
}
if procUpdate.Resurrect {
procRelease.Resurrect = true
}
for resKey, resValue := range procUpdate.Resources {
procRelease.Resources[resKey] = resValue
}
release.Processes[procKey] = procRelease
}
}
if err := client.CreateRelease(release); err != nil {
return err
}
if err := client.DeployAppRelease(mustApp(), release.ID); err != nil {
return err
}
log.Printf("Created release %s.", release.ID)
return nil
}
示例8: 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 {
//.........這裏部分代碼省略.........