示例#1
0
// Store stores the stuff in the S3
func (s3s *S3Store) Store(a *artifact.Artifact) error {
	destination := a.FullDestination()
	ctype := a.ContentType
	size := a.Size

	s3s.log.WithFields(logrus.Fields{
		"source":       a.Source,
		"dest":         destination,
		"bucket":       s3s.b.Name,
		"content_type": ctype,
	}).Debug("more artifact details")

	err := s3s.b.PutReaderHeader(destination, a.Instream, int64(size),
		map[string][]string{
			"Content-Type": []string{ctype},
		}, s3.Private)
	if err != nil {
		return err
	}

	md := artifactToMetadata(a)
	err = s3s.md.Save(md)
	if err != nil {
		return err
	}
	return nil
}
示例#2
0
func artifactToMetadata(a *artifact.Artifact) *metadata.Metadata {
	return &metadata.Metadata{
		JobID:       a.JobID,
		Size:        a.Size,
		Path:        a.FullDestination(),
		ContentType: a.ContentType,
	}
}
示例#3
0
// Store does the storing
func (fs *FileStore) Store(a *artifact.Artifact) error {
	fullPath := fs.artifactFullPath(a)
	fullPathPrefix := path.Dir(fullPath)

	err := os.MkdirAll(fullPathPrefix, 0755)
	if err != nil {
		fs.log.WithFields(logrus.Fields{
			"err":    err,
			"prefix": fullPathPrefix,
		}).Error("failed to make dest file path prefix")
		return err
	}

	fd, err := ioutil.TempFile("", "artifacts-tmp")
	if err != nil {
		fs.log.WithFields(logrus.Fields{
			"err": err,
		}).Error("failed to get tempfile")
		return err
	}

	defer fd.Close()

	_, err = io.CopyN(fd, a.Instream, int64(a.Size))
	if err != nil {
		fs.log.WithFields(logrus.Fields{
			"err":       err,
			"temp_file": fd.Name(),
		}).Error("failed to copy to temporary file")
		return err
	}

	defer os.Remove(fd.Name())
	err = os.Rename(fd.Name(), fullPath)
	if err != nil {
		fs.log.WithFields(logrus.Fields{
			"err":       err,
			"temp_file": fd.Name(),
			"dest":      fullPath,
		}).Error("failed to move temporary file to dest")
	}

	fs.log.WithFields(logrus.Fields{
		"source": a.Source,
		"prefix": fs.Prefix,
		"dest":   a.FullDestination(),
		"size":   humanize.Bytes(a.Size),
	}).Info("stored artifact to file")

	return nil
}
示例#4
0
func (fs *FileStore) artifactFullPath(a *artifact.Artifact) string {
	return filepath.Join(fs.Prefix, strings.TrimPrefix(a.FullDestination(), "/"))
}