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 }
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 }
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 }