Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
update packages, support @pocketbase and @surrealdb databases
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Sep 30, 2022
1 parent ea5d730 commit 0c3efc8
Show file tree
Hide file tree
Showing 20 changed files with 340 additions and 224 deletions.
74 changes: 44 additions & 30 deletions cmd/app/compose.go
Original file line number Diff line number Diff line change
@@ -1,54 +1,68 @@
package app

import (
"github.com/abdfnx/botway/internal/pipes/compose"
"fmt"
"log"
"os"
"os/exec"

"github.com/abdfnx/botway/constants"
"github.com/abdfnx/botway/internal/pipes/initx"
"github.com/abdfnx/botway/tools"
"github.com/abdfnx/botwaygo"
"github.com/abdfnx/looker"
"github.com/botwayorg/templates"
"github.com/spf13/cobra"
)

func ComposeCMD() *cobra.Command {
cmd := &cobra.Command{
Use: "compose",
Short: "Run and manage mulit-bots with botway compose",
}
Use: "compose",
Short: "Run and manage mulit-bots with docker compose",
PreRun: func(cmd *cobra.Command, args []string) { tools.CheckDir() },
Run: func(cmd *cobra.Command, args []string) {
_, err := looker.LookPath("docker")

cmd.AddCommand(ComposeUpCMD())
cmd.AddCommand(ComposeBuildCMD())
cmd.AddCommand(ComposeListCMD())
if err != nil {
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR"))
panic(constants.FAIL_FOREGROUND.Render(" docker is not installed"))
}

return cmd
}
tools.CreateEnvFile()

func ComposeUpCMD() *cobra.Command {
cmd := &cobra.Command{
Use: "up",
Short: "Create and start bots compose",
Run: func(cmd *cobra.Command, args []string) {
compose.Compose(false, false)
},
}
if botwaygo.GetBotInfo("bot.host_service") == "railway.app" {
initx.CopyConfig()
}

return cmd
}
dockerCompose := exec.Command("docker-compose", args...)

func ComposeBuildCMD() *cobra.Command {
cmd := &cobra.Command{
Use: "build",
Short: "Build or rebuild bots",
Run: func(cmd *cobra.Command, args []string) {
compose.Compose(true, false)
dockerCompose.Stdin = os.Stdin
dockerCompose.Stdout = os.Stdout
dockerCompose.Stderr = os.Stderr
err = dockerCompose.Run()

if err != nil {
log.Printf("error: %v\n", err)
}
},
}

cmd.AddCommand(ComposeInitCMD())

return cmd
}

func ComposeListCMD() *cobra.Command {
func ComposeInitCMD() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List bots services",
Use: "init",
Short: "Initialize `docker-compose.yaml`",
PreRun: func(cmd *cobra.Command, args []string) { tools.CheckDir() },
Run: func(cmd *cobra.Command, args []string) {
compose.Compose(false, true)
dockerComposeFile := os.WriteFile("docker-compose.yaml", []byte(templates.Content("dockerfiles/compose/docker-compose.yaml", "botway", "", "")), 0644)

if dockerComposeFile != nil {
log.Fatal(dockerComposeFile)
}
},
}

Expand Down
31 changes: 31 additions & 0 deletions cmd/app/pocketbase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package app

import (
"github.com/abdfnx/botway/tools"
"github.com/spf13/cobra"
)

func PocketBaseCMD() *cobra.Command {
cmd := &cobra.Command{
Use: "pocketbase",
Short: "Manage your work with PocketBase",
Aliases: []string{"pb"},
}

cmd.AddCommand(PocketBaseInitCMD())

return cmd
}

func PocketBaseInitCMD() *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Short: "Initialize pocketbase in your docker compose config file",
PreRun: func(cmd *cobra.Command, args []string) { tools.CheckDir() },
Run: func(cmd *cobra.Command, args []string) {
tools.InitInDockerCompose("pocketbase")
},
}

return cmd
}
31 changes: 31 additions & 0 deletions cmd/app/surrealdb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package app

import (
"github.com/abdfnx/botway/tools"
"github.com/spf13/cobra"
)

func SurrealCMD() *cobra.Command {
cmd := &cobra.Command{
Use: "surrealdb",
Short: "Manage your work with PocketBase",
Aliases: []string{"surreal", "sdb"},
}

cmd.AddCommand(SurrealInitCMD())

return cmd
}

func SurrealInitCMD() *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Short: "Initialize surrealdb in your docker compose config file",
PreRun: func(cmd *cobra.Command, args []string) { tools.CheckDir() },
Run: func(cmd *cobra.Command, args []string) {
tools.InitInDockerCompose("surrealdb")
},
}

return cmd
}
2 changes: 2 additions & 0 deletions cmd/botway/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func Execute(f *factory.Factory, version string, buildDate string) *cobra.Comman
app.GitHubCmd,
app.RailwayCMD(),
app.RenderCMD(),
app.PocketBaseCMD(),
app.SurrealCMD(),
versionCmd,
)

Expand Down
16 changes: 8 additions & 8 deletions constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package constants

import (
"io/ioutil"
"os"
"path/filepath"

"github.com/abdfnx/tran/dfs"
Expand Down Expand Up @@ -56,18 +56,18 @@ var (
HomeDir, _ = dfs.GetHomeDirectory()
BotwayDirPath = filepath.Join(HomeDir, ".botway")
BotwayConfigFile = filepath.Join(BotwayDirPath, "botway.json")
BotwayConfig, Berr = ioutil.ReadFile(BotwayConfigFile)
BotwayConfig, Berr = os.ReadFile(BotwayConfigFile)
BWBotsConfigFile = filepath.Join(BotwayDirPath, "bw-bots.json")
BWBotsConfig, Werr = ioutil.ReadFile(BWBotsConfigFile)
BotConfig, Oerr = ioutil.ReadFile(".botway.yaml")
BotComposeConfig, Cerr = ioutil.ReadFile(".botway-compose.yaml")
Guilds, Gerr = ioutil.ReadFile(filepath.Join("config", "guilds.json"))
BWBotsConfig, Werr = os.ReadFile(BWBotsConfigFile)
BotConfig, Oerr = os.ReadFile(".botway.yaml")
BotComposeConfig, Cerr = os.ReadFile(".botway-compose.yaml")
Guilds, Gerr = os.ReadFile(filepath.Join("config", "guilds.json"))

RailwayConfigFile = filepath.Join(HomeDir, ".botway", "railway-config.json")
RailwayConfig, Rerr = ioutil.ReadFile(RailwayConfigFile)
RailwayConfig, Rerr = os.ReadFile(RailwayConfigFile)

RenderConfigFile = filepath.Join(HomeDir, ".botway", "render-config.json")
RenderConfig, Nerr = ioutil.ReadFile(RenderConfigFile)
RenderConfig, Nerr = os.ReadFile(RenderConfigFile)

RAIL_PORT = 4411
)
5 changes: 5 additions & 0 deletions dockerfiles/compose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
mybot:
build: .
env_file:
- ./config/botway-tokens.env
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/spf13/viper v1.13.0
github.com/tidwall/gjson v1.14.3
github.com/tidwall/sjson v1.2.5
golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec
golang.org/x/term v0.0.0-20220919170432-7a66f970e087
)

Expand All @@ -43,7 +43,7 @@ require (
github.com/cli/browser v1.1.0 // indirect
github.com/cli/oauth v0.9.0 // indirect
github.com/cli/safeexec v1.0.0 // indirect
github.com/cli/shurcooL-graphql v0.0.1 // indirect
github.com/cli/shurcooL-graphql v0.0.2 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
Expand Down Expand Up @@ -98,7 +98,7 @@ require (
github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4 // indirect
github.com/yuin/goldmark v1.5.2 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
golang.org/x/net v0.0.0-20220926192436-02166a98028e // indirect
golang.org/x/net v0.0.0-20220927171203-f486391704dc // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.12 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
Loading

0 comments on commit 0c3efc8

Please sign in to comment.