Compare commits
No commits in common. "main" and "v1.1.0" have entirely different histories.
@ -1,40 +0,0 @@
|
|||||||
package commands
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"slices"
|
|
||||||
|
|
||||||
"gitea.codeblob.work/pk/hoster/internals/conf"
|
|
||||||
"gitea.codeblob.work/pk/hoster/internals/helpers"
|
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CmdCheckPort(c *cli.Context) error {
|
|
||||||
sitesAvail := conf.App.MustString("nginx.sitesAvailable")
|
|
||||||
existingProjects, err := helpers.FindHostConfigs(sitesAvail)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
usedPorts := []int{}
|
|
||||||
for _, project := range existingProjects {
|
|
||||||
usedPorts = append(usedPorts, project.InternalPort)
|
|
||||||
}
|
|
||||||
|
|
||||||
port := conf.App.Int("nginx.portRangeStart")
|
|
||||||
freePort := 0
|
|
||||||
for port <= conf.App.Int("nginx.portRangeEnd") {
|
|
||||||
if !slices.Contains(usedPorts, port) && helpers.IsFreePort(port) {
|
|
||||||
freePort = port
|
|
||||||
break
|
|
||||||
}
|
|
||||||
port++
|
|
||||||
}
|
|
||||||
|
|
||||||
if freePort == 0 {
|
|
||||||
return fmt.Errorf("no free port available")
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Free port: %d\n", freePort)
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -16,7 +16,7 @@ func Execute() {
|
|||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: "hoster",
|
Name: "hoster",
|
||||||
Usage: "Hoster",
|
Usage: "Hoster",
|
||||||
Version: "1.2.0",
|
Version: "1.1.0",
|
||||||
Commands: []*cli.Command{
|
Commands: []*cli.Command{
|
||||||
{
|
{
|
||||||
Name: "new",
|
Name: "new",
|
||||||
@ -56,20 +56,6 @@ func Execute() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Name: "port",
|
|
||||||
Subcommands: []*cli.Command{
|
|
||||||
{
|
|
||||||
Name: "free",
|
|
||||||
Usage: "Get the next free port in the configured range",
|
|
||||||
Before: func(c *cli.Context) error {
|
|
||||||
conf.LoadConfig(filepath.Join(findHomeDir(), ".hoster.yml"))
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
Action: commands.CmdCheckPort,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Name: "check",
|
Name: "check",
|
||||||
Usage: "Check if newer versions of docker images are available",
|
Usage: "Check if newer versions of docker images are available",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user