diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..0cc8d77 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +# git config merge.theirs.name "Always accept theirs" +# git config merge.theirs.driver "cp %B %A" +default.pgo binary merge=theirs diff --git a/.goreleaser.yml b/.goreleaser.yml index 87e4f73..4e4ee2d 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -10,13 +10,15 @@ before: - go generate ./... builds: - - binary: '{{ .ProjectName }}' + - id: default + binary: '{{ .ProjectName }}' goos: - darwin - freebsd - linux - netbsd - openbsd + - windows goarch: - 386 - amd64 @@ -34,15 +36,92 @@ builds: ignore: - goos: darwin goarch: 386 + - goos: darwin + goarch: arm - goos: freebsd goarch: arm64 - goos: netbsd goarch: arm64 - goos: openbsd goarch: arm64 + - goos: windows + goarch: 386 + - goos: windows + goarch: arm + - id: mips + binary: '{{ .ProjectName }}' + goos: + - linux + goarch: + - mips + - mipsle + gomips: + - softfloat + env: + - CGO_ENABLED=0 + flags: + - -trimpath + - -mod=readonly + ldflags: -s -w -X main.version={{ .Version }} + - id: arm64-v9 + binary: '{{ .ProjectName }}' + goos: + - darwin + - linux + goarch: + - arm64 + goarm64: + - v9.0 + env: + - CGO_ENABLED=0 + flags: + - -trimpath + - -mod=readonly + ldflags: -s -w -X main.version={{ .Version }} + - id: amd64-v3 + binary: '{{ .ProjectName }}' + goos: + - darwin + - freebsd + - linux + - netbsd + - openbsd + - windows + goarch: + - amd64 + goamd64: + - v3 + env: + - CGO_ENABLED=0 + flags: + - -trimpath + - -mod=readonly + ldflags: -s -w -X main.version={{ .Version }} archives: - - name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' + - id: default + ids: + - default + - mips + name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' + formats: + - tar.gz + wrap_in_directory: true + format_overrides: + - goos: windows + formats: + - zip + files: + - LICENSE + - README.md + - SECURITY.md + - BEST_PRACTICES.md + - example.config.toml + - id: optimized + ids: + - arm64-v9 + - amd64-v3 + name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm64 }}-{{ .Arm64 }}{{ end }}{{ if .Amd64 }}-{{ .Amd64 }}{{ end }}' formats: - tar.gz wrap_in_directory: true diff --git a/README.md b/README.md index 106a02b..6e24771 100644 --- a/README.md +++ b/README.md @@ -380,6 +380,7 @@ ExecStart=/usr/local/bin/mtg run /etc/mtg.toml Restart=always RestartSec=3 DynamicUser=true +LimitNOFILE=65536 AmbientCapabilities=CAP_NET_BIND_SERVICE [Install] diff --git a/default.pgo b/default.pgo new file mode 100644 index 0000000..c6a6454 Binary files /dev/null and b/default.pgo differ diff --git a/main.go b/main.go index 1f3a7d5..9583b23 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,23 @@ import ( ) func main() { + // this runs profiling server. To enable it, build with prof tag + // $ go build -tags prof + // + // Then you can pass a port using MTG_PROF_PORT environment variable. + // Default is 6000 + // $ MTG_PROF_PORT=6000 mtg run config.toml + // + // It will run a webserver with profiling data on + // localhost:${MTG_PROF_PORT:-6000}. + // + // To collect PGO do following: + // $ curl -o default.pgo 'http://localhost:6000/debug/pprof/profile?seconds=300' + // + // See also https://pkg.go.dev/net/http/pprof + // https://go.dev/blog/pprof + runProfile() + cli := &cli.CLI{} ctx := kong.Parse(cli, kong.Vars{ "version": getVersion(), diff --git a/run_profile.go b/run_profile.go new file mode 100644 index 0000000..06b7ab8 --- /dev/null +++ b/run_profile.go @@ -0,0 +1,7 @@ +//go:build !prof + +package main + +func runProfile() { + +} diff --git a/run_profile_tag_prof.go b/run_profile_tag_prof.go new file mode 100644 index 0000000..63ca2d8 --- /dev/null +++ b/run_profile_tag_prof.go @@ -0,0 +1,27 @@ +//go:build prof + +package main + +import ( + "fmt" + "net" + "net/http" + _ "net/http/pprof" //nolint: gosec + "os" +) + +const DefaultProfPort = "6000" + +func runProfile() { + port := os.Getenv("MTG_PROF_PORT") + if port == "" { + port = DefaultProfPort + } + + listener, err := net.Listen("tcp", net.JoinHostPort("127.0.0.1", port)) + if err != nil { + panic(err) + } + + go http.Serve(listener, nil) +}