rebirth

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2020 License: MIT Imports: 26 Imported by: 0

README

rebirth Actions Status

Supports live reloading for Go

go_rebirth

Features

  • Better features than github.com/pilu/fresh
  • Supports cross compile and live reloading on host OS for docker users ( Very Fast for Docker for Mac user )
  • Supports cross compile by cgo ( C/C++ ) ( currently, works on macOS ( and target architecture is amd64 ) only )
  • Supports helper commands for go run go test go build

Synopsis

Settings

rebirth needs configuration file ( rebirth.yml ) to running . rebirth init create it .

rebirth.yml example is the following.

task:
  migrate:
    desc: migrate schema
    commands:
      - mysql ....
host:
  docker: container_name
build:
  init:
    - echo 'init hook' # called once at starting
  before:
    - echo 'before hook' # called before build
  after:
    - echo 'after hook' # called after build
  env:
    CGO_LDFLAGS: /usr/local/lib/libz.a
run:
  env:
    RUNTIME_ENV: "fuga"
watch:
  root: . # root directory for watching ( default: . )
  ignore:
    - vendor
  • task : define custom command
  • host : specify host information for running to an application ( currently, supports docker only )
  • build : specify ENV variables for building
  • run : specify ENV variables for running
  • watch : specify root directory or ignore directories for watching go file

In case of running on localhost

1. Install rebirth CLI
$ GO111MODULE=on go get -u github.com/goccy/rebirth/cmd/rebirth
2. Create rebirth.yml
$ rebirth init
3. Run rebirth
rebirth

In case of running with Docker for Mac

Example tree

.
├── docker-compose.yml
├── main.go
└── rebirth.yml

main.go is your web application's source.

1. Install rebirth CLI
$ GO111MODULE=on go get -u github.com/goccy/rebirth/cmd/rebirth
2. Install cross compiler for cgo
$ brew install FiloSottile/musl-cross/musl-cross
3. Write settings
docker-compose.yml
version: '2'
services:
  app:
    image: golang:1.13.5
    container_name: rebirth_app
    volumes:
      - '.:/go/src/app'
    working_dir: /go/src/app
    environment:
      GO111MODULE: "on"
    command: |
      tail -f /dev/null
rebirth.yml
host:
  docker: rebirth_app # container_name in docker-compose.yml
4. Run rebirth
$ rebirth

# start live reloading !!

# build for docker container's architecture on macOS (e.g. GOOS=linux GOARCH=amd64
# execute built binary on target container

Helper commands

Usage:
  rebirth [OPTIONS] <command>

Help Options:
  -h, --help  Show this help message

Available commands:
  build  execute 'go build' command
  init   create rebirth.yml for configuration
  run    execute 'go run'   command
  test   execute 'go test'  command
rebirth build

Help cross compile your go script

$ rebirth build -o app script/hoge.go
rebirth test

Help cross compile for go test

$ rebirth test -v ./ -run Hoge
rebirth run

Help cross compile for go run

$ rebirth run script/hoge.go

How it Works

~/work/app directory is mounted on the container as /go/src/app

  1. install rebirth CLI ( GO111MODULE=on go get -u github.com/goccy/rebirth/cmd/rebirth )
  2. run rebirth and it cross compile myself for Linux ( GOOS=linux, GOARCH=amd64 ) and put it to .rebirth directory as __rebirth
  3. copy .rebirth/__rebirth to the container ( .rebirth directory is mounted on the container )
  4. watch main.go ( by fsnotify )

  1. cross compile main.go for Linux and put to .rebirth directory as program
  2. copy .rebirth/program to the container

  1. run __rebirth on the container
  2. __rebirth executes program
  3. edit main.go
  4. rebirth detects file changed event

  1. cross compile main.go for Linux and put to .rebirth directory as program
  2. copy .rebirth/program to the container
  3. rebirth send signal to __rebirth for reloading ( SIGHUP )
  4. __rebirth kill the current application and execute program as a new application

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExistsConfig

func ExistsConfig() bool

func ExpandPath added in v0.0.5

func ExpandPath(path string) string

Types

type Build

type Build struct {
	Main   string            `yaml:"main,omitempty"`
	Env    map[string]string `yaml:"env,omitempty"`
	Init   []string          `yaml:"init,omitempty"`
	Before []string          `yaml:"before,omitempty"`
	After  []string          `yaml:"after,omitempty"`
}

type Command

type Command struct {
	// contains filtered or unexported fields
}

func NewCommand

func NewCommand(args ...string) *Command

func (*Command) AddEnv

func (c *Command) AddEnv(env []string)

func (*Command) Run

func (c *Command) Run() error

func (*Command) RunAsync added in v0.0.3

func (c *Command) RunAsync()

func (*Command) SetDir

func (c *Command) SetDir(dir string)

func (*Command) Stop

func (c *Command) Stop() error

func (*Command) String

func (c *Command) String() string

type Config

type Config struct {
	Host  *Host            `yaml:"host,omitempty"`
	Build *Build           `yaml:"build,omitempty"`
	Run   *Run             `yaml:"run,omitempty"`
	Watch *Watch           `yaml:"watch,omitempty"`
	Task  map[string]*Task `yaml:"task,omitempty"`
}

func LoadConfig

func LoadConfig(confPath string) (*Config, error)

type DockerCommand

type DockerCommand struct {
	// contains filtered or unexported fields
}

func NewDockerCommand

func NewDockerCommand(container string, cmd ...string) *DockerCommand

func (*DockerCommand) Output

func (c *DockerCommand) Output() ([]byte, error)

func (*DockerCommand) Run

func (c *DockerCommand) Run() error

type GoCommand

type GoCommand struct {
	// contains filtered or unexported fields
}

func NewGoCommand

func NewGoCommand() *GoCommand

func (*GoCommand) AddEnv

func (c *GoCommand) AddEnv(env []string)

func (*GoCommand) Build

func (c *GoCommand) Build(args ...string) error

func (*GoCommand) EnableCrossBuild

func (c *GoCommand) EnableCrossBuild(container string)

func (*GoCommand) Run

func (c *GoCommand) Run(args ...string) error

func (*GoCommand) RunInGoContext added in v0.0.10

func (c *GoCommand) RunInGoContext(args ...string) error

func (*GoCommand) SetDir

func (c *GoCommand) SetDir(dir string)

func (*GoCommand) Test

func (c *GoCommand) Test(args ...string) error

type Host

type Host struct {
	Docker string `yaml:"docker,omitempty"`
}

type Reloader

type Reloader struct {
	// contains filtered or unexported fields
}

func NewReloader

func NewReloader(cfg *Config) *Reloader

func (*Reloader) Close

func (r *Reloader) Close() error

func (*Reloader) IsEnabledReload

func (r *Reloader) IsEnabledReload() bool

func (*Reloader) Reload

func (r *Reloader) Reload() error

func (*Reloader) Run

func (r *Reloader) Run() error

type Run

type Run struct {
	Env map[string]string `yaml:"env,omitempty"`
}

type Task added in v0.0.10

type Task struct {
	Desc     string   `yaml:"desc,omitempty"`
	Commands []string `yaml:"commands,omitempty"`
}

type Watch

type Watch struct {
	Root   string   `yaml:"root,omitempty"`
	Ignore []string `yaml:"ignore,omitempty"`
}

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

func NewWatcher

func NewWatcher(cfg *Config) *Watcher

func (*Watcher) Run

func (w *Watcher) Run(callback func()) error

Directories

Path Synopsis
_examples
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL