2020-08-11 18:51:58 +03:00
|
|
|
// Package tar basically tarballs source code
|
|
|
|
package tar
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2020-08-19 17:47:17 +03:00
|
|
|
"github.com/unistack-org/micro/v3/build"
|
2020-08-11 18:51:58 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type tarBuild struct{}
|
|
|
|
|
|
|
|
func (t *tarBuild) Package(name string, src *build.Source) (*build.Package, error) {
|
|
|
|
pkg := name + ".tar.gz"
|
|
|
|
// path to the tarball
|
|
|
|
path := filepath.Join(os.TempDir(), src.Path, pkg)
|
|
|
|
|
|
|
|
// create a temp directory
|
|
|
|
if err := os.MkdirAll(filepath.Join(os.TempDir(), src.Path), 0755); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := Compress(src.Path, path); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &build.Package{
|
|
|
|
Name: name,
|
|
|
|
Path: path,
|
|
|
|
Type: t.String(),
|
|
|
|
Source: src,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tarBuild) Remove(b *build.Package) error {
|
|
|
|
return os.Remove(b.Path)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tarBuild) String() string {
|
|
|
|
return "tar.gz"
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewBuild(opts ...build.Option) build.Build {
|
|
|
|
return new(tarBuild)
|
|
|
|
}
|