-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement grid-compose #1130
base: development
Are you sure you want to change the base?
implement grid-compose #1130
Changes from 8 commits
7503ba9
84cbd10
7f0d28b
9e70865
7d3cff0
905394b
40e67a2
9fcedd2
09d55e2
3b095a7
9e227e1
b0f3b22
4bf7aaf
352ef37
de9f63a
07c5da9
124fe56
bd2aa64
8ddab7b
deb6275
f21cf97
bf550b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
bin/* | ||
.pre-commit-config.yaml | ||
out |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
BIN_PATH = bin/main | ||
|
||
.PHONY: build run | ||
|
||
build: | ||
@go build -o $(BIN_PATH) ./main.go | ||
|
||
run: | ||
@go run main.go up -f ./grid-compose.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Grid-Compose | ||
|
||
is a tool for running multi-vm applications on TFGrid defined using a Yaml formatted file. | ||
|
||
## Usage | ||
|
||
`REQUIRED` EnvVars: | ||
|
||
- `MNEMONIC`: your secret words | ||
- `NETWORK`: one of (dev, qa, test, main) | ||
|
||
```bash | ||
grid-compose [OPTIONS] [COMMAND] | ||
|
||
OPTIONS: | ||
-f path to yaml file, default is ./grid-compose.yaml | ||
|
||
COMMANDS: | ||
- version: shows the project version | ||
- up: deploy the app | ||
- down: cancel all deployments | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var downCmd = &cobra.Command{ | ||
Use: "down", | ||
Short: "cancel your project on the grid", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := app.Down(); err != nil { | ||
log.Fatal().Err(err).Send() | ||
} | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var psCmd = &cobra.Command{ | ||
Use: "ps", | ||
Short: "list containers", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
flags := cmd.Flags() | ||
|
||
if err := app.Ps(cmd.Context(), flags); err != nil { | ||
log.Fatal().Err(err).Send() | ||
} | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/rs/zerolog" | ||
"github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
"github.com/threefoldtech/tfgrid-sdk-go/grid-compose/internal" | ||
) | ||
|
||
var ( | ||
app *internal.App | ||
configPath string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to avoid the global variable, we could add the app to the context. it will shared between the commands |
||
network string | ||
mnemonic string | ||
) | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
log.Fatal().Err(err).Send() | ||
} | ||
} | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "grid-compose", | ||
Short: "Grid-Compose is a tool for running multi-vm applications on TFGrid defined using a Yaml formatted file.", | ||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
var err error | ||
app, err = internal.NewApp(network, mnemonic, configPath) | ||
if err != nil { | ||
log.Fatal().Err(err).Send() | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
network = os.Getenv("NETWORK") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move getting the env to the Run in rootCmd |
||
mnemonic = os.Getenv("MNEMONIC") | ||
rootCmd.PersistentFlags().StringVarP(&configPath, "file", "f", "./grid-compose.yaml", "the grid-compose configuration file") | ||
psCmd.PersistentFlags().BoolP("verbose", "v", false, "all information about deployed services") | ||
psCmd.PersistentFlags().StringP("output", "o", "", "output result to a file") | ||
|
||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) | ||
|
||
rootCmd.AddCommand(versionCmd) | ||
rootCmd.AddCommand(upCmd) | ||
rootCmd.AddCommand(psCmd) | ||
rootCmd.AddCommand(downCmd) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// load config from file + validate | ||
// parse environment variables | ||
// deploy networks + volumes | ||
// deploy services | ||
var upCmd = &cobra.Command{ | ||
Use: "up", | ||
Short: "deploy application on the grid", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := app.Up(cmd.Context()); err != nil { | ||
log.Fatal().Err(err).Send() | ||
} | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var version = "v0.0.1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check how to properly do the versioning https://github.com/threefoldtech/tfgrid-sdk-go/blob/0c4a82b2e3fe68c8b70d4fac89bb3e31fecf8566/grid-cli/cmd/version.go |
||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "get current version number", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println(version) | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# not all features here are implemented yet | ||
version: '1.0.0' | ||
|
||
# cannot figure out how to run mycelium always error deployment not configured | ||
networks: | ||
net1: | ||
type: 'wg' | ||
net2: | ||
type: 'myc' | ||
net3: | ||
type: 'ygg' | ||
net4: | ||
type: 'ip4' | ||
net5: | ||
type: 'ip6' | ||
|
||
services: | ||
web: | ||
flist: 'https://hub.grid.tf/tf-official-apps/nginx-latest.flist' | ||
environment: | ||
- ENV_VAR_NAME=value | ||
volumes: | ||
- web-data:/data | ||
networks: | ||
- net1 | ||
resources: | ||
cpu: 2 | ||
memory: 2 | ||
depends_on: | ||
- database | ||
database: | ||
flist: 'https://hub.grid.tf/tf-official-apps/postgresql-latest.flist' | ||
environment: | ||
- POSTGRES_DB=postgres | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=password | ||
volumes: | ||
- db-data:/var/lib/postgresql/data | ||
networks: | ||
- net1 | ||
- net2 | ||
- net3 | ||
resources: | ||
cpu: 4 | ||
memory: 2 | ||
healthcheck: | ||
test: ['CMD', 'curl', 'http://{myceliumip}'] | ||
interval: 1m30s | ||
timeout: 10s | ||
retries: 3 | ||
# ask omar about the types zmount and all that | ||
storage: | ||
web-data: | ||
type: 'zmount' | ||
size: 10GB | ||
db-data: | ||
type: 'zmount' | ||
size: 10GB |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
version: '1.0.0' | ||
|
||
networks: | ||
net1: | ||
name: 'nettyy' | ||
nodes: | ||
- 11 | ||
- 14 | ||
- 144 | ||
range: | ||
ip: | ||
type: ip4 | ||
ip: 10.20.0.0 | ||
mask: | ||
type: cidr | ||
mask: 16/32 | ||
wg: true | ||
|
||
project_name: 'example_project' | ||
services: | ||
web5: | ||
flist: 'https://hub.grid.tf/tf-official-vms/ubuntu-24.04-full.flist' | ||
networks: | ||
- net1 | ||
network_types: | ||
- ip4 | ||
- ygg | ||
node_id: 11 | ||
entrypoint: '/sbin/zinit init' | ||
volumes: | ||
- webdata:/data | ||
resources: | ||
cpu: 1 | ||
memory: 2048 | ||
disk: 25600 | ||
database: | ||
flist: 'https://hub.grid.tf/tf-official-vms/ubuntu-24.04-full.flist' | ||
networks: | ||
- net1 | ||
network_types: | ||
- ygg | ||
volumes: | ||
- dbdata:/var/lib/postgresql/data | ||
node_id: 11 | ||
entrypoint: '/sbin/zinit init' | ||
resources: | ||
cpu: 1 | ||
memory: 2048 | ||
disk: 25600 | ||
|
||
storage: | ||
webdata: | ||
type: 'zmount' | ||
size: 10GB | ||
dbdata: | ||
type: 'zmount' | ||
size: 10GB |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
version: '1.0.0' | ||
|
||
networks: | ||
net1: | ||
type: 'wg' | ||
net2: | ||
type: 'myc' | ||
net3: | ||
type: 'ygg' | ||
net4: | ||
type: 'ip4' | ||
net5: | ||
type: 'ip6' | ||
|
||
services: | ||
web5: | ||
flist: 'https://hub.grid.tf/tf-official-vms/ubuntu-24.04-full.flist' | ||
networks: | ||
- net3 | ||
- net4 | ||
- net5 | ||
node_id: 144 | ||
entrypoint: '/sbin/zinit init' | ||
volumes: | ||
- webdata:/data | ||
resources: | ||
cpu: 1 | ||
memory: 2048 | ||
disk: 25600 | ||
database: | ||
flist: 'https://hub.grid.tf/tf-official-vms/ubuntu-24.04-full.flist' | ||
networks: | ||
- net3 | ||
- net1 | ||
volumes: | ||
- dbdata:/var/lib/postgresql/data | ||
node_id: 14 | ||
entrypoint: '/sbin/zinit init' | ||
resources: | ||
cpu: 1 | ||
memory: 2048 | ||
disk: 25600 | ||
|
||
storage: | ||
webdata: | ||
type: 'zmount' | ||
size: 10GB | ||
dbdata: | ||
type: 'zmount' | ||
size: 10GB |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: '1.0.0' | ||
|
||
services: | ||
new_single_vm: | ||
flist: 'https://hub.grid.tf/omarabdulaziz.3bot/ubuntu-jammy.flist' | ||
entrypoint: '/sbin/init' | ||
environment: | ||
- SSH_KEY=... | ||
resources: | ||
cpu: 1 | ||
memory: 512 | ||
node_id: 14 | ||
networks: | ||
- yggdrasil |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module github.com/threefoldtech/tfgrid-sdk-go/grid-compose | ||
|
||
go 1.21.0 | ||
|
||
require ( | ||
github.com/rs/zerolog v1.33.0 | ||
github.com/spf13/cobra v1.8.0 | ||
) | ||
|
||
require ( | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/mattn/go-colorable v0.1.13 // indirect | ||
github.com/mattn/go-isatty v0.0.19 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
golang.org/x/sys v0.12.0 // indirect | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
invoke the flags here, and pass to the method only the values it needs