https://github.com/goccy/rebirth
Supports live reloading for Go
https://github.com/goccy/rebirth
docker go golang golang-application golang-cli live-reload
Last synced: 3 months ago
JSON representation
Supports live reloading for Go
- Host: GitHub
- URL: https://github.com/goccy/rebirth
- Owner: goccy
- License: mit
- Created: 2019-12-16T10:14:33.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-05T02:09:46.000Z (almost 5 years ago)
- Last Synced: 2025-03-18T05:35:05.341Z (3 months ago)
- Topics: docker, go, golang, golang-application, golang-cli, live-reload
- Language: Go
- Homepage:
- Size: 412 KB
- Stars: 71
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rebirth [](https://github.com/goccy/rebirth/actions)
Supports live reloading for Go
# 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.
```yaml
task:
migrate:
desc: migrate schema
commands:
- mysql ....
host:
docker: container_name
build:
main: path/to/main.go # change path to main package ( default: . )
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
```bash
$ GO111MODULE=on go get -u github.com/goccy/rebirth/cmd/rebirth
```### 2. Create `rebirth.yml`
```bash
$ rebirth init
```### 3. Run `rebirth`
```bash
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
```bash
$ GO111MODULE=on go get -u github.com/goccy/rebirth/cmd/rebirth
```### 2. Install cross compiler for cgo
```bash
$ brew install FiloSottile/musl-cross/musl-cross
```### 3. Write settings
### docker-compose.yml
```yaml
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
```yaml
host:
docker: rebirth_app # container_name in docker-compose.yml
```### 4. Run `rebirth`
```bash
$ 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
```bash
Usage:
rebirth [OPTIONS]Help Options:
-h, --help Show this help messageAvailable 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
```bash
$ rebirth build -o app script/hoge.go
```### `rebirth test`
Help cross compile for `go test`
```bash
$ rebirth test -v ./ -run Hoge
```### `rebirth run`
Help cross compile for `go run`
```bash
$ 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](https://github.com/fsnotify/fsnotify) )
5. cross compile `main.go` for Linux and put to `.rebirth` directory as `program`
6. copy `.rebirth/program` to the container
7. run `__rebirth` on the container
8. `__rebirth` executes `program`
9. edit `main.go`
10. `rebirth` detects file changed event
11. cross compile `main.go` for Linux and put to `.rebirth` directory as `program`
12. copy `.rebirth/program` to the container
13. `rebirth` send signal to `__rebirth` for reloading ( `SIGHUP` )
14. `__rebirth` kill the current application and execute `program` as a new application# License
MIT