From ebb53d1656dc3bb26a51b5b5faf3aa8ed86f0b04 Mon Sep 17 00:00:00 2001 From: Alexander Baryshnikov Date: Wed, 23 May 2018 11:55:10 +0300 Subject: [PATCH] switch go goreleaser, small refactoring --- .gitignore | 3 ++- .goreleaser.yml | 22 ++++++++++++++++++++++ .goxc.json | 14 -------------- main.go => cmd/monexec/main.go | 15 +++++++++------ config.go => monexec/config.go | 9 ++++----- 5 files changed, 37 insertions(+), 26 deletions(-) create mode 100644 .goreleaser.yml delete mode 100644 .goxc.json rename main.go => cmd/monexec/main.go (91%) rename config.go => monexec/config.go (97%) diff --git a/.gitignore b/.gitignore index fb08241..b938996 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea/** build .goxc.local.json -vendor/ \ No newline at end of file +vendor/ +dist \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..b9c84dc --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,22 @@ +# This is an example goreleaser.yaml file with some sane defaults. +# Make sure to check the documentation at http://goreleaser.com +builds: + - binary: monexec + main: cmd/monexec/main.go + goos: + - windows + - darwin + - linux + goarch: + - amd64 + - 386 + - arm64 +archive: + format: tar.gz +nfpm: + homepage: https://github.com/reddec/monexec + description: Tool for controlling processes like a supervisord but with some features + maintainer: RedDec + license: MIT + formats: + - deb diff --git a/.goxc.json b/.goxc.json deleted file mode 100644 index 9c5b343..0000000 --- a/.goxc.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "Tasks": [ - "default", - "publish-github" - ], - "PackageVersion": "0.1.5", - "TaskSettings": { - "publish-github": { - "owner": "reddec", - "repository": "monexec" - } - }, - "ConfigVersion": "0.9" -} \ No newline at end of file diff --git a/main.go b/cmd/monexec/main.go similarity index 91% rename from main.go rename to cmd/monexec/main.go index c75afaa..5a78bcd 100644 --- a/main.go +++ b/cmd/monexec/main.go @@ -12,6 +12,9 @@ import ( "syscall" ) +var ( + version = "dev" +) var ( runCommand = kingpin.Command("run", "Run single executable") runGenerate = runCommand.Flag("generate", "Generate instead of run YAML configuration based on args").Bool() @@ -37,7 +40,7 @@ var ( ) func run() { - config := DefaultConfig() + config := monexec.DefaultConfig() config.Services = append(config.Services, monexec.Executable{ Name: *runLabel, @@ -49,10 +52,10 @@ func run() { WorkDir: *runWorkDir, Environment: *runEnv, }) - FillDefaultExecutable(&config.Services[0]) + monexec.FillDefaultExecutable(&config.Services[0]) if *runConsulEnable { - config.Consul = DefaultConsulConfig() + config.Consul = monexec.DefaultConsulConfig() config.Consul.URL = *runConsulAddress config.Consul.TTL = *runConsulTTL config.Consul.AutoDeregistrationTimeout = *runConsulDeRegTTL @@ -76,7 +79,7 @@ func run() { } func start() { - config, err := LoadConfig(*startSources...) + config, err := monexec.LoadConfig(*startSources...) if err != nil { log.Fatal(err) } @@ -84,7 +87,7 @@ func start() { runConfigInSupervisor(config, sv) } -func runConfigInSupervisor(config *Config, sv container.Supervisor) { +func runConfigInSupervisor(config * monexec.Config, sv container.Supervisor) { ctx, stop := context.WithCancel(context.Background()) c := make(chan os.Signal, 2) @@ -104,7 +107,7 @@ func runConfigInSupervisor(config *Config, sv container.Supervisor) { } func main() { - kingpin.Version("0.1.0").DefaultEnvars() + kingpin.Version(version).DefaultEnvars() switch kingpin.Parse() { case "run": run() diff --git a/config.go b/monexec/config.go similarity index 97% rename from config.go rename to monexec/config.go index a056f91..856cb21 100644 --- a/config.go +++ b/monexec/config.go @@ -1,4 +1,4 @@ -package main +package monexec import ( "context" @@ -15,7 +15,6 @@ import ( "github.com/hashicorp/consul/api" "github.com/reddec/container" "github.com/reddec/container/plugin" - "github.com/reddec/monexec/monexec" "gopkg.in/yaml.v2" "github.com/reddec/monexec/plugins" "github.com/mitchellh/mapstructure" @@ -40,7 +39,7 @@ func DefaultConsulConfig() *ConsulConfig { } type Config struct { - Services []monexec.Executable `yaml:"services"` + Services []Executable `yaml:"services"` Critical []string `yaml:"critical,omitempty"` Consul *ConsulConfig `yaml:"consul,omitempty"` Plugins map[string]interface{} `yaml:",inline"` // all unparsed means plugins @@ -99,7 +98,7 @@ func DefaultConfig() Config { return config } -func FillDefaultExecutable(exec *monexec.Executable) { +func FillDefaultExecutable(exec *Executable) { if exec.RestartTimeout == 0 { exec.RestartTimeout = 6 * time.Second } @@ -157,7 +156,7 @@ func (config *Config) Run(sv container.Supervisor, ctx context.Context) error { for _, exec := range config.Services { FillDefaultExecutable(&exec) wg.Add(1) - go func(exec monexec.Executable) { + go func(exec Executable) { defer wg.Done() container.Wait(sv.Watch(ctx, exec.Factory, exec.Restart, exec.RestartTimeout, false)) }(exec)