Packager is now builder (#958)
This commit is contained in:
parent
5744050943
commit
6a0082741c
@ -1,16 +1,16 @@
|
|||||||
// Package packager creates a binary image. Due to package being a reserved keyword we use packager.
|
// Package build builds a micro runtime package
|
||||||
package packager
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/micro/go-micro/runtime/source"
|
"github.com/micro/go-micro/runtime/source"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Package builds binaries
|
// Builder builds binaries
|
||||||
type Packager interface {
|
type Builder interface {
|
||||||
// Compile builds a binary
|
// Build builds a package
|
||||||
Compile(*Source) (*Binary, error)
|
Build(*Source) (*Package, error)
|
||||||
// Deletes the binary
|
// Clean deletes the package
|
||||||
Delete(*Binary) error
|
Clean(*Package) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Source is the source of a build
|
// Source is the source of a build
|
||||||
@ -21,8 +21,8 @@ type Source struct {
|
|||||||
Repository *source.Repository
|
Repository *source.Repository
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary is the representation of a binary
|
// Package is micro service package
|
||||||
type Binary struct {
|
type Package struct {
|
||||||
// Name of the binary
|
// Name of the binary
|
||||||
Name string
|
Name string
|
||||||
// Location of the binary
|
// Location of the binary
|
@ -8,17 +8,17 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/fsouza/go-dockerclient"
|
docker "github.com/fsouza/go-dockerclient"
|
||||||
"github.com/micro/go-micro/runtime/package"
|
"github.com/micro/go-micro/runtime/build"
|
||||||
"github.com/micro/go-micro/util/log"
|
"github.com/micro/go-micro/util/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Packager struct {
|
type Builder struct {
|
||||||
Options packager.Options
|
Options build.Options
|
||||||
Client *docker.Client
|
Client *docker.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Packager) Compile(s *packager.Source) (*packager.Binary, error) {
|
func (d *Builder) Build(s *build.Source) (*build.Package, error) {
|
||||||
image := filepath.Join(s.Repository.Path, s.Repository.Name)
|
image := filepath.Join(s.Repository.Path, s.Repository.Name)
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
@ -63,7 +63,7 @@ func (d *Packager) Compile(s *packager.Source) (*packager.Binary, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &packager.Binary{
|
return &build.Package{
|
||||||
Name: image,
|
Name: image,
|
||||||
Path: image,
|
Path: image,
|
||||||
Type: "docker",
|
Type: "docker",
|
||||||
@ -71,13 +71,13 @@ func (d *Packager) Compile(s *packager.Source) (*packager.Binary, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Packager) Delete(b *packager.Binary) error {
|
func (d *Builder) Clean(b *build.Package) error {
|
||||||
image := filepath.Join(b.Path, b.Name)
|
image := filepath.Join(b.Path, b.Name)
|
||||||
return d.Client.RemoveImage(image)
|
return d.Client.RemoveImage(image)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPackager(opts ...packager.Option) packager.Packager {
|
func NewBuilder(opts ...build.Option) build.Builder {
|
||||||
options := packager.Options{}
|
options := build.Options{}
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&options)
|
o(&options)
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ func NewPackager(opts ...packager.Option) packager.Packager {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
return &Packager{
|
return &Builder{
|
||||||
Options: options,
|
Options: options,
|
||||||
Client: client,
|
Client: client,
|
||||||
}
|
}
|
@ -6,11 +6,11 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/micro/go-micro/runtime/package"
|
"github.com/micro/go-micro/runtime/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Packager struct {
|
type Builder struct {
|
||||||
Options packager.Options
|
Options build.Options
|
||||||
Cmd string
|
Cmd string
|
||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ func whichGo() string {
|
|||||||
return "go"
|
return "go"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Packager) Compile(s *packager.Source) (*packager.Binary, error) {
|
func (g *Builder) Build(s *build.Source) (*build.Package, error) {
|
||||||
binary := filepath.Join(g.Path, s.Repository.Name)
|
binary := filepath.Join(g.Path, s.Repository.Name)
|
||||||
source := filepath.Join(s.Repository.Path, s.Repository.Name)
|
source := filepath.Join(s.Repository.Path, s.Repository.Name)
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ func (g *Packager) Compile(s *packager.Source) (*packager.Binary, error) {
|
|||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &packager.Binary{
|
return &build.Package{
|
||||||
Name: s.Repository.Name,
|
Name: s.Repository.Name,
|
||||||
Path: binary,
|
Path: binary,
|
||||||
Type: "go",
|
Type: "go",
|
||||||
@ -50,19 +50,19 @@ func (g *Packager) Compile(s *packager.Source) (*packager.Binary, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Packager) Delete(b *packager.Binary) error {
|
func (g *Builder) Clean(b *build.Package) error {
|
||||||
binary := filepath.Join(b.Path, b.Name)
|
binary := filepath.Join(b.Path, b.Name)
|
||||||
return os.Remove(binary)
|
return os.Remove(binary)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPackager(opts ...packager.Option) packager.Packager {
|
func NewBuild(opts ...build.Option) build.Builder {
|
||||||
options := packager.Options{
|
options := build.Options{
|
||||||
Path: os.TempDir(),
|
Path: os.TempDir(),
|
||||||
}
|
}
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&options)
|
o(&options)
|
||||||
}
|
}
|
||||||
return &Packager{
|
return &Builder{
|
||||||
Options: options,
|
Options: options,
|
||||||
Cmd: whichGo(),
|
Cmd: whichGo(),
|
||||||
Path: options.Path,
|
Path: options.Path,
|
@ -1,4 +1,4 @@
|
|||||||
package packager
|
package build
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
// local path to download source
|
// local path to download source
|
@ -15,13 +15,13 @@ type Process struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Exec(exe *process.Executable) error {
|
func (p *Process) Exec(exe *process.Executable) error {
|
||||||
cmd := exec.Command(exe.Binary.Path)
|
cmd := exec.Command(exe.Package.Path)
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Fork(exe *process.Executable) (*process.PID, error) {
|
func (p *Process) Fork(exe *process.Executable) (*process.PID, error) {
|
||||||
// create command
|
// create command
|
||||||
cmd := exec.Command(exe.Binary.Path, exe.Args...)
|
cmd := exec.Command(exe.Package.Path, exe.Args...)
|
||||||
// set env vars
|
// set env vars
|
||||||
cmd.Env = append(cmd.Env, exe.Env...)
|
cmd.Env = append(cmd.Env, exe.Env...)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ package process
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/micro/go-micro/runtime/package"
|
"github.com/micro/go-micro/runtime/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Process manages a running process
|
// Process manages a running process
|
||||||
@ -20,8 +20,8 @@ type Process interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Executable struct {
|
type Executable struct {
|
||||||
// The executable binary
|
// Package containing executable
|
||||||
Binary *packager.Binary
|
Package *build.Package
|
||||||
// The env variables
|
// The env variables
|
||||||
Env []string
|
Env []string
|
||||||
// Args to pass
|
// Args to pass
|
||||||
|
@ -5,7 +5,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
packager "github.com/micro/go-micro/runtime/package"
|
"github.com/micro/go-micro/runtime/build"
|
||||||
|
|
||||||
"github.com/micro/go-micro/runtime/process"
|
"github.com/micro/go-micro/runtime/process"
|
||||||
proc "github.com/micro/go-micro/runtime/process/os"
|
proc "github.com/micro/go-micro/runtime/process/os"
|
||||||
"github.com/micro/go-micro/util/log"
|
"github.com/micro/go-micro/util/log"
|
||||||
@ -56,7 +57,7 @@ func newService(s *Service, c CreateOptions) *service {
|
|||||||
Service: s,
|
Service: s,
|
||||||
Process: new(proc.Process),
|
Process: new(proc.Process),
|
||||||
Exec: &process.Executable{
|
Exec: &process.Executable{
|
||||||
Binary: &packager.Binary{
|
Package: &build.Package{
|
||||||
Name: s.Name,
|
Name: s.Name,
|
||||||
Path: exec,
|
Path: exec,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user