本文整理匯總了Golang中github.com/flynn/flynn/controller/types.Artifact類的典型用法代碼示例。如果您正苦於以下問題:Golang Artifact類的具體用法?Golang Artifact怎麽用?Golang Artifact使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Artifact類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: downloadImage
func (d *Downloader) downloadImage(artifact *ct.Artifact, info chan *ct.ImagePullInfo) error {
info <- &ct.ImagePullInfo{
Name: artifact.Meta["flynn.component"],
Type: ct.ImagePullTypeImage,
Artifact: artifact,
}
for _, rootfs := range artifact.Manifest().Rootfs {
for _, layer := range rootfs.Layers {
if layer.Type != ct.ImageLayerTypeSquashfs {
continue
}
info <- &ct.ImagePullInfo{
Name: artifact.Meta["flynn.component"],
Type: ct.ImagePullTypeLayer,
Layer: layer,
}
if err := d.downloadSquashfsLayer(layer, artifact.LayerURL(layer), artifact.Meta); err != nil {
return fmt.Errorf("error downloading layer: %s", err)
}
}
}
return nil
}
示例2: exportImage
func (e *Exporter) exportImage(name string, artifact *ct.Artifact) error {
log := e.log.New("name", name)
for _, rootfs := range artifact.Manifest().Rootfs {
for _, layer := range rootfs.Layers {
log.Info("exporting layer", "id", layer.ID)
if err := e.exportLayer(layer); err != nil {
log.Error("error exporting layer", "id", layer.ID, "err", err)
return err
}
}
}
path := e.imagePath(artifact.Manifest().ID())
if _, err := os.Stat(path); err == nil {
log.Info("manifest already exists")
return nil
}
log.Info("writing image manifest", "path", path)
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
log.Error("error writing image manifest", "path", path, "err", err)
return err
}
if err := ioutil.WriteFile(path, artifact.RawManifest, 0644); err != nil {
log.Error("error writing image manifest", "path", path, "err", err)
return err
}
return nil
}
示例3: createTestArtifact
func (s *S) createTestArtifact(c *C, in *ct.Artifact) *ct.Artifact {
if in.Type == "" {
in.Type = "docker"
}
if in.URI == "" {
in.URI = fmt.Sprintf("https://example.com/%s", random.String(8))
}
c.Assert(s.c.CreateArtifact(in), IsNil)
return in
}
示例4: createTestArtifact
func (s *S) createTestArtifact(c *C, in *ct.Artifact) *ct.Artifact {
if in.Type == "" {
in.Type = ct.ArtifactTypeFlynn
in.RawManifest = ct.ImageManifest{
Type: ct.ImageManifestTypeV1,
}.RawManifest()
}
if in.URI == "" {
in.URI = fmt.Sprintf("https://example.com/%s", random.String(8))
}
c.Assert(s.c.CreateArtifact(in), IsNil)
return in
}
示例5: downloadManifest
func downloadManifest(artifact *ct.Artifact) error {
verifier, err := verify.NewVerifier(artifact.Hashes, artifact.Size)
if err != nil {
return err
}
res, err := hh.RetryClient.Get(artifact.URI)
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return fmt.Errorf("unexpected HTTP status: %s", res.Status)
}
r := verifier.Reader(res.Body)
data, err := ioutil.ReadAll(r)
if err != nil {
return err
}
if err := verifier.Verify(); err != nil {
return err
}
artifact.RawManifest = data
return nil
}
示例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: 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()
//.........這裏部分代碼省略.........
示例8: 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
}
}
//.........這裏部分代碼省略.........