75 lines
1.6 KiB
Go
75 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha1"
|
|
"fmt"
|
|
"gitea.illuad.fr/adrien/middleman/command"
|
|
"github.com/rs/zerolog/log"
|
|
"github.com/urfave/cli/v3"
|
|
"golang.org/x/sync/errgroup"
|
|
"os"
|
|
"os/signal"
|
|
"runtime/debug"
|
|
"syscall"
|
|
)
|
|
|
|
type noCommit struct {
|
|
message []byte
|
|
}
|
|
|
|
func (nc noCommit) String() string {
|
|
if nc.message == nil {
|
|
nc.message = []byte("not tied to a commit") // dbf242029aeedcfe71af2e5843474d8f8e2e9d63
|
|
}
|
|
sum := sha1.Sum(nc.message)
|
|
return fmt.Sprintf("%x", sum)
|
|
}
|
|
|
|
const appName = "middleman"
|
|
|
|
var version, commit string
|
|
|
|
func main() {
|
|
// Note: os.Kill/syscall.SIGKILL (SIGKILL) signal cannot be caught or ignored.
|
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
defer cancel()
|
|
var group *errgroup.Group
|
|
group, ctx = errgroup.WithContext(ctx)
|
|
app := cli.Command{
|
|
Name: appName,
|
|
Usage: "Securely mount the Docker socket: apply fine-grained access control to Docker socket HTTP requests",
|
|
Version: buildVersion(),
|
|
DefaultCommand: command.ServeCmd,
|
|
Commands: []*cli.Command{
|
|
command.Serve(group),
|
|
command.Healthcheck(group),
|
|
},
|
|
Authors: []any{
|
|
"Adrien <contact@illuad.fr>",
|
|
},
|
|
UseShortOptionHandling: true,
|
|
}
|
|
group.Go(func() error {
|
|
return app.Run(ctx, os.Args)
|
|
})
|
|
if err := group.Wait(); err != nil {
|
|
log.Err(err).Send()
|
|
}
|
|
}
|
|
|
|
func buildVersion() string {
|
|
info, ok := debug.ReadBuildInfo()
|
|
if ok {
|
|
if info.Main.Version != "" {
|
|
version = info.Main.Version
|
|
commit = info.Main.Sum
|
|
}
|
|
}
|
|
if version == "" && commit == "" {
|
|
version = "dev"
|
|
commit = noCommit{}.String()
|
|
}
|
|
return version + "-" + commit
|
|
}
|