dgr/push.go
func (u Uploader) Upload() error {
	acifile, err := os.Open(u.Acipath)
	if err != nil {
		return errs.WithEF(err, data.WithField("file", u.Acipath), "Failed to open aci file")
	}
	defer acifile.Close()

	var ascfile *os.File
	if _, err := os.Stat(u.Ascpath); err == nil {
		ascfile, err = os.Open(u.Ascpath)
		if err != nil {
			return errs.WithEF(err, data.WithField("file", u.Ascpath), "Failed to open asc file")
		}
		defer ascfile.Close()
	}

	manifest, err := aci.ManifestFromImage(acifile)
	if err != nil {
		return errs.WithEF(err, data.WithField("file", u.Ascpath), "Failed to extract manifest from aci")
	}
	app, err := discovery.NewAppFromString(u.Uri)
	if err != nil {
		return errs.WithEF(err, data.WithField("uri", u.Uri), "Failed to prepare app")
	}

	if _, ok := app.Labels[archLabelName]; !ok {
		arch, ok := manifest.Labels.Get(archLabelName)
		if !ok {
			return fmt.Errorf("manifest is missing label: %q", archLabelName)
		}
		app.Labels[archLabelName] = arch
	}

	if _, ok := app.Labels[osLabelName]; !ok {
		os, ok := manifest.Labels.Get(osLabelName)
		if !ok {
			return fmt.Errorf("manifest is missing label: %q", osLabelName)
		}
		app.Labels[osLabelName] = os
	}

	if _, ok := app.Labels[extLabelName]; !ok {
		app.Labels[extLabelName] = strings.Trim(schema.ACIExtension, ".")
	}

	// Just to make sure that we start reading from the front of the file in
	// case aci.ManifestFromImage changed the cursor into the file.
	_, err = acifile.Seek(0, 0)
	if err != nil {
		return errs.WithE(err, "Failed to seek to beginning of file")
	}

	manblob, err := manifest.MarshalJSON()
	if err != nil {
		return errs.WithE(err, "Failed to marshall manifest")
	}

	initurl, err := u.getInitiationURL(app)
	if err != nil {
		return errs.WithEF(err, data.WithField("uri", u.Uri), "Failed to initate url")
	}

	initDeets, err := u.initiateUpload(initurl)
	if err != nil {
		return errs.WithE(err, "Failed to initiate upload")
	}

	type partToUpload struct {
		label string
		url   string
		r     io.Reader
		draw  bool
	}

	parts := []partToUpload{
		{"manifest", initDeets.ManifestURL, bytes.NewReader(manblob), false},
		{"ACI", initDeets.ACIURL, acifile, true}}
	if ascfile != nil {
		parts = append(parts, partToUpload{"signature", initDeets.SignatureURL, ascfile, true})
	}

	for _, part := range parts {
		err = u.uploadPart(part.url, part.r, part.draw, part.label)
		if err != nil {
			reason := fmt.Errorf("error uploading %s: %v", part.label, err)
			reportErr := u.reportFailure(initDeets.CompletedURL, reason.Error())
			if reportErr != nil {
				return fmt.Errorf("error uploading %s and error reporting failure: %v, %v", part.label, err, reportErr)
			}
			return reason
		}
	}

	err = u.reportSuccess(initDeets.CompletedURL)
	if err != nil {
		return errs.WithE(err, "Remote server report upload failure")
	}

	return nil
}
func (u Uploader) Upload() error {
	acifile, err := os.Open(u.Acipath)
	if err != nil {
		return errs.WithEF(err, data.WithField("file", u.Acipath), "Failed to open aci file")
	}
	defer acifile.Close()

	var ascfile *os.File
	if _, err := os.Stat(u.Ascpath); err == nil {
		ascfile, err = os.Open(u.Ascpath)
		if err != nil {
			return errs.WithEF(err, data.WithField("file", u.Ascpath), "Failed to open asc file")
		}
		defer ascfile.Close()
	}

	manifest, err := aci.ManifestFromImage(acifile)
	if err != nil {
		return errs.WithEF(err, data.WithField("file", u.Ascpath), "Failed to extract manifest from aci")
	}
	app, err := discovery.NewAppFromString(u.Uri)
	if err != nil {
		return errs.WithEF(err, data.WithField("uri", u.Uri), "Failed to prepare app")
	}

	if _, ok := app.Labels[archLabelName]; !ok {
		arch, ok := manifest.Labels.Get(archLabelName)
		if !ok {
			return fmt.Errorf("manifest is missing label: %q", archLabelName)
		}
		app.Labels[archLabelName] = arch
	}

	if _, ok := app.Labels[osLabelName]; !ok {
		os, ok := manifest.Labels.Get(osLabelName)
		if !ok {
			return fmt.Errorf("manifest is missing label: %q", osLabelName)
		}
		app.Labels[osLabelName] = os
	}

	if _, ok := app.Labels[extLabelName]; !ok {
		app.Labels[extLabelName] = strings.Trim(schema.ACIExtension, ".")
	}

	// Just to make sure that we start reading from the front of the file in
	// case aci.ManifestFromImage changed the cursor into the file.
	_, err = acifile.Seek(0, 0)
	if err != nil {
		return errs.WithE(err, "Failed to seek to beginning of file")
	}

	manblob, err := manifest.MarshalJSON()
	if err != nil {
		return errs.WithE(err, "Failed to marshall manifest")
	}

	initurl, err := u.getInitiationURL(app)
	if err != nil {
		return errs.WithEF(err, data.WithField("uri", u.Uri), "Failed to initate url")
	}

	initDeets, err := u.initiateUpload(initurl)
	if err != nil {
		return errs.WithE(err, "Failed to initiate upload")
	}

	type partToUpload struct {
		label string
		url   string
		r     io.Reader
		draw  bool
	}

	parts := []partToUpload{
		{"manifest", initDeets.ManifestURL, bytes.NewReader(manblob), false},
		{"ACI", initDeets.ACIURL, acifile, true}}
	if ascfile != nil {
		parts = append(parts, partToUpload{"signature", initDeets.SignatureURL, ascfile, true})
	}

	for _, part := range parts {
		err = u.uploadPart(part.url, part.r, part.draw, part.label)
		if err != nil {
			reason := fmt.Errorf("error uploading %s: %v", part.label, err)
			reportErr := u.reportFailure(initDeets.CompletedURL, reason.Error())
			if reportErr != nil {
				return fmt.Errorf("error uploading %s and error reporting failure: %v, %v", part.label, err, reportErr)
			}
			return reason
		}
	}

	err = u.reportSuccess(initDeets.CompletedURL)
	if err != nil {
		return errs.WithE(err, "Remote server report upload failure")
	}

	return nil
}
// Upload performs the upload of the ACI and signature specified in the
// Uploader struct.