Skip to content

Commit

Permalink
Update to urfave/cli v2
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenMaude committed Jan 13, 2025
1 parent 85428ab commit 4f7dd1f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 46 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/sensiblecodeio/barrier v0.3.0
github.com/sensiblecodeio/git-prep-directory v0.6.0
github.com/sensiblecodeio/hookbot v0.15.2
github.com/urfave/cli v1.22.16
github.com/urfave/cli/v2 v2.27.5
golang.org/x/sys v0.29.0
)

Expand Down Expand Up @@ -39,6 +39,7 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect
go.opentelemetry.io/otel v1.33.0 // indirect
Expand Down
16 changes: 4 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
Expand Down Expand Up @@ -81,20 +79,15 @@ github.com/sensiblecodeio/hookbot v0.15.2/go.mod h1:pymbdketljEJo9e85f+u5cHcGNDn
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/urfave/cli v1.22.16 h1:MH0k6uJxdwdeWQTwhSO42Pwr4YLrNLwBtg1MRgTqPdQ=
github.com/urfave/cli v1.22.16/go.mod h1:EeJR6BKodywf4zciqrdw6hpCPk68JO9z5LazXZMn5Po=
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec h1:DGmKwyZwEB8dI7tbLt/I/gQuP559o/0FrAkHKlQM/Ks=
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec/go.mod h1:owBmyHYMLkxyrugmfwE/DLJyW8Ro9mkphwuVErQ0iUw=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
Expand Down Expand Up @@ -160,7 +153,6 @@ google.golang.org/grpc v1.66.3/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
66 changes: 35 additions & 31 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/docker/go-connections/nat"
"github.com/sensiblecodeio/barrier"
"github.com/sensiblecodeio/hookbot/pkg/listen"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"

"github.com/sensiblecodeio/hanoverd/pkg/builder"
"github.com/sensiblecodeio/hanoverd/pkg/iptables"
Expand Down Expand Up @@ -79,41 +79,41 @@ func main() {
app.Version = Version

app.Flags = []cli.Flag{
cli.BoolFlag{
&cli.BoolFlag{
Name: "disable-overlap",
Usage: "shut down old container before starting new one",
},
cli.StringSliceFlag{
&cli.StringSliceFlag{
Name: "env, e",
Usage: "environment variables to pass (reads from env if = omitted)",
Value: &cli.StringSlice{},
},
cli.StringSliceFlag{
&cli.StringSliceFlag{
Name: "publish, p",
Usage: "ports to publish (same syntax as docker)",
Value: &cli.StringSlice{},
},
cli.StringSliceFlag{
&cli.StringSliceFlag{
Name: "volume, v",
Usage: "Bind mount a volume",
Value: &cli.StringSlice{},
},
cli.StringSliceFlag{
&cli.StringSliceFlag{
Name: "mount, m",
Usage: "Supply mounts",
Value: &cli.StringSlice{},
},
cli.StringFlag{
&cli.StringFlag{
Name: "status-uri",
Usage: "specify URI which returns 200 OK when functioning correctly",
Value: "/",
},
cli.StringFlag{
Name: "hookbot",
Usage: "url of hookbot websocket endpoint to monitor for updates",
EnvVar: "HOOKBOT_URL",
&cli.StringFlag{
Name: "hookbot",
Usage: "url of hookbot websocket endpoint to monitor for updates",
EnvVars: []string{"HOOKBOT_URL"},
},
cli.DurationFlag{
&cli.DurationFlag{
Name: "overlap-grace-duration",
Usage: "length of time to wait before killing a superceded container",
Value: 1 * time.Second,
Expand All @@ -122,33 +122,36 @@ func main() {

app.Action = ActionRun

app.Commands = []cli.Command{
app.Commands = []*cli.Command{
{
Name: "builder",
Action: builder.Action,
Flags: []cli.Flag{
cli.StringFlag{
Name: "listen",
Usage: "url of hookbot websocket endpoint to monitor for updates",
EnvVar: "HOOKBOT_MONITOR_URL",
&cli.StringFlag{
Name: "listen",
Usage: "url of hookbot websocket endpoint to monitor for updates",
EnvVars: []string{"HOOKBOT_MONITOR_URL"},
},
cli.StringFlag{
Name: "docker-notify",
Usage: "url of hookbot pub endpoint to notify on complete build",
EnvVar: "HOOKBOT_DOCKER_NOTIFY_URL",
&cli.StringFlag{
Name: "docker-notify",
Usage: "url of hookbot pub endpoint to notify on complete build",
EnvVars: []string{"HOOKBOT_DOCKER_NOTIFY_URL"},
},
},
},
{
Name: "version",
Action: cli.ShowVersion,
Name: "version",
Action: func(cCtx *cli.Context) error {
cli.ShowVersion(cCtx)
return nil
},
},
}

app.RunAndExitOnError()
}

func ActionRun(c *cli.Context) {
func ActionRun(c *cli.Context) error {
var err error

options := Options{}
Expand All @@ -162,22 +165,22 @@ func ActionRun(c *cli.Context) {
containerName := "hanoverd"
var imageSource source.ImageSource

if c.GlobalString("hookbot") != "" {
if c.String("hookbot") != "" {

hookbotURL := c.GlobalString("hookbot")
hookbotURL := c.String("hookbot")
containerName, imageSource, err = source.GetSourceFromHookbot(hookbotURL)
if err != nil {
log.Fatalf("Failed to parse hookbot source: %v", err)
}

options.containerArgs = c.Args()
options.containerArgs = c.Args().Slice()

} else if len(c.Args()) == 0 {
} else if c.Args().Len() == 0 {
imageSource = &source.CwdSource{}

} else {
first := c.Args().First()
args := c.Args()[1:]
args := c.Args().Slice()[1:]

if first == "@" {
// If the first arg is "@", then use the Cwd
Expand Down Expand Up @@ -250,13 +253,14 @@ func ActionRun(c *cli.Context) {
value = <-sig
}()

if c.GlobalString("hookbot") != "" {
go MonitorHookbot(c.GlobalString("hookbot"), events)
if c.String("hookbot") != "" {
go MonitorHookbot(c.String("hookbot"), events)
}

go loop(containerName, imageSource, &wg, &dying, options, events)

<-dying.Barrier()
return nil
}

func MonitorHookbot(target string, notify chan<- *UpdateEvent) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/sensiblecodeio/hookbot/pkg/listen"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"

"github.com/sensiblecodeio/hanoverd/pkg/source"
"github.com/sensiblecodeio/hanoverd/pkg/util"
)

// Action is the codegangsta/cli action for running hanoverd in builder mode.
func Action(c *cli.Context) {
func Action(c *cli.Context) error {
_, imageSource, err := source.GetSourceFromHookbot(c.String("listen"))
if err != nil {
log.Fatalf("Failed to parse hookbot listen URL: %v", err)
Expand Down Expand Up @@ -115,6 +115,7 @@ func Action(c *cli.Context) {
}

log.Printf("Event stream finished")
return nil
}

func ParseRegistryImage(fullName string) (registry, repository string) {
Expand Down

0 comments on commit 4f7dd1f

Please sign in to comment.