diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 8b5ec87..f94b229 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -21,3 +21,4 @@ jobs: generateReleaseNotes: true makeLatest: "legacy" name: "Version ${{ steps.version.outputs.version }}" + immutableCreate: true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b9e0526..e409760 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,6 +20,8 @@ jobs: uses: actions/checkout@v6 - name: Setup Go uses: actions/setup-go@v6 + with: + go-version-file: go.mod - name: Install depends run: go get . - name: Build diff --git a/LICENSE b/LICENSE index 0b734ba..086e3a8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright © 2023 Louis Royer +Copyright Louis Royer and the NextMN Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fe4634d --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +prefix = /usr/local +exec_prefix = $(prefix) +bindir = $(exec_prefix)/bin +BASHCOMPLETIONSDIR = $(exec_prefix)/share/bash-completion/completions + + +RM = rm -f +INSTALL = install -D +MKDIRP = mkdir -p + +.PHONY: install uninstall update build clean default +default: build +build: + go build +clean: + go clean +reinstall: uninstall install +install: + $(INSTALL) docker-setup $(DESTDIR)$(bindir)/docker-setup + $(MKDIRP) $(DESTDIR)$(BASHCOMPLETIONSDIR) + $(DESTDIR)$(bindir)/docker-setup completion bash > $(DESTDIR)$(BASHCOMPLETIONSDIR)/docker-setup + @echo "=================================" + @echo ">> Now run the following command:" + @echo "\tsource $(DESTDIR)$(BASHCOMPLETIONSDIR)/docker-setup" + @echo "=================================" +uninstall: + $(RM) $(DESTDIR)$(bindir)/docker-setup + $(RM) $(DESTDIR)$(BASHCOMPLETIONSDIR)/docker-setup diff --git a/README.md b/README.md index 5b4e094..2ac8a5a 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ cap_add: ``` ## Author -Louis Royer +Louis Royer and the NextMN Contributors ## License MIT diff --git a/go.mod b/go.mod index 60687d2..05e8348 100644 --- a/go.mod +++ b/go.mod @@ -1,19 +1,11 @@ module github.com/nextmn/docker-setup -go 1.23.0 - -toolchain go1.23.5 +go 1.25.5 require ( - github.com/nextmn/logrus-formatter v0.0.1 + github.com/nextmn/logrus-formatter v0.0.2 github.com/sirupsen/logrus v1.9.3 - github.com/urfave/cli/v2 v2.27.7 + github.com/urfave/cli/v3 v3.6.1 ) -require ( - github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect - github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/stretchr/testify v1.9.0 // indirect - github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect - golang.org/x/sys v0.31.0 // indirect -) +require golang.org/x/sys v0.40.0 // indirect diff --git a/go.sum b/go.sum index 610a013..08d5161 100644 --- a/go.sum +++ b/go.sum @@ -1,27 +1,21 @@ -github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo= -github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/nextmn/logrus-formatter v0.0.1 h1:Bsf78jjiEESc+rV8xE6IyKj4frDPGMwXFNrLQzm6A1E= -github.com/nextmn/logrus-formatter v0.0.1/go.mod h1:vdSZ+sIcSna8vjbXkSFxsnsKHqRwaUEed4JCPcXoGyM= +github.com/nextmn/logrus-formatter v0.0.2 h1:3eQeBenWxWSX2i+h/ESMmjwS6wP3UmhEgLMu66BX9Ao= +github.com/nextmn/logrus-formatter v0.0.2/go.mod h1:DZrXx9tS+t0Qn86tfsQa1sZNwGMXrLTHpczUQwd/UgI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 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/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU= -github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4= -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/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/urfave/cli/v3 v3.6.1 h1:j8Qq8NyUawj/7rTYdBGrxcH7A/j7/G8Q5LhWEW4G3Mo= +github.com/urfave/cli/v3 v3.6.1/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= -golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= +golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 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= diff --git a/internal/app/conf.go b/internal/app/conf.go index fd912a9..6c3cf8b 100644 --- a/internal/app/conf.go +++ b/internal/app/conf.go @@ -1,4 +1,4 @@ -// Copyright 2023 Louis Royer and docker-setup contributors. All rights reserved. +// Copyright Louis Royer and the NextMN contributors. All rights reserved. // Use of this source code is governed by a MIT-style license that can be // found in the LICENSE file. // SPDX-License-Identifier: MIT diff --git a/internal/app/hook.go b/internal/app/hook.go index 1e242b4..10175d5 100644 --- a/internal/app/hook.go +++ b/internal/app/hook.go @@ -1,4 +1,4 @@ -// Copyright 2023 Louis Royer and docker-setup contributors. All rights reserved. +// Copyright Louis Royer and the NextMN contributors. All rights reserved. // Use of this source code is governed by a MIT-style license that can be // found in the LICENSE file. // SPDX-License-Identifier: MIT diff --git a/internal/app/iproutehook.go b/internal/app/iproutehook.go index b385e03..16cc144 100644 --- a/internal/app/iproutehook.go +++ b/internal/app/iproutehook.go @@ -1,4 +1,4 @@ -// Copyright 2023 Louis Royer and docker-setup contributors. All rights reserved. +// Copyright Louis Royer and the NextMN contributors. All rights reserved. // Use of this source code is governed by a MIT-style license that can be // found in the LICENSE file. // SPDX-License-Identifier: MIT diff --git a/internal/app/nat4hook.go b/internal/app/nat4hook.go index 6a04e69..085db34 100644 --- a/internal/app/nat4hook.go +++ b/internal/app/nat4hook.go @@ -1,4 +1,4 @@ -// Copyright 2023 Louis Royer and docker-setup contributors. All rights reserved. +// Copyright Louis Royer and the NextMN contributors. All rights reserved. // Use of this source code is governed by a MIT-style license that can be // found in the LICENSE file. // SPDX-License-Identifier: MIT diff --git a/internal/app/userhook.go b/internal/app/userhook.go index 514954e..60aa644 100644 --- a/internal/app/userhook.go +++ b/internal/app/userhook.go @@ -1,4 +1,4 @@ -// Copyright 2023 Louis Royer and docker-setup contributors. All rights reserved. +// Copyright Louis Royer and the NextMN contributors. All rights reserved. // Use of this source code is governed by a MIT-style license that can be // found in the LICENSE file. // SPDX-License-Identifier: MIT diff --git a/main.go b/main.go index b05909c..72e0422 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,4 @@ -// Copyright 2023 Louis Royer and docker-setup contributors. All rights reserved. +// Copyright Louis Royer and the NextMN contributors. All rights reserved. // Use of this source code is governed by a MIT-style license that can be // found in the LICENSE file. // SPDX-License-Identifier: MIT @@ -8,32 +8,38 @@ import ( "context" "os" "os/signal" + "runtime/debug" "syscall" "github.com/nextmn/logrus-formatter/logger" "github.com/nextmn/docker-setup/internal/app" "github.com/sirupsen/logrus" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) func main() { logger.Init("docker-setup") ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT) defer cancel() - app := &cli.App{ - Name: "docker-setup", - Usage: "Configure a container for networking", - EnableBashCompletion: true, - Authors: []*cli.Author{ - {Name: "Louis Royer"}, + version := "Unknown version" + if info, ok := debug.ReadBuildInfo(); ok { + version = info.Main.Version + } + app := &cli.Command{ + Name: "docker-setup", + Usage: "Docker-setup - Configure a container for networking", + EnableShellCompletion: true, + Authors: []any{ + "Louis Royer", }, - Action: func(ctx *cli.Context) error { + Version: version, + Action: func(ctx context.Context, cmd *cli.Command) error { conf := app.NewConf() conf.RunInitHooks() if !conf.Oneshot() { select { - case <-ctx.Context.Done(): + case <-ctx.Done(): break } } @@ -41,7 +47,7 @@ func main() { return nil }, } - if err := app.RunContext(ctx, os.Args); err != nil { - logrus.Fatal(err) + if err := app.Run(ctx, os.Args); err != nil { + logrus.WithError(err).Fatal("Fatal error while running the application") } }