Compare commits
	
		
			38 Commits
		
	
	
		
			0.1.1-alph
			...
			0.1.3-alph
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 357cc0593a | |||
| 8e111dc32f | |||
| 20ecdb8061 | |||
| f87aad4688 | |||
| 6794236b77 | |||
| 6c9bb89a10 | |||
| 66aeeee768 | |||
| 6c115926e3 | |||
| b6fe86f2ad | |||
| d290a4ec0b | |||
| f93563588a | |||
| 59c55c0a2f | |||
| 9fcdc45851 | |||
| 27d665c3be | |||
| bc5fc0b0cb | |||
| 99160967a8 | |||
| 683ef0c3de | |||
| 3c3d8dc0e7 | |||
| 855e9ea26d | |||
| 50d663ff6e | |||
| 39ad6e8aa8 | |||
| f39c8cbe21 | |||
| e114b2a939 | |||
| 511619722f | |||
| cf2653fef8 | |||
| 5ba40ad883 | |||
| 2e0c16d198 | |||
| 4c216fdf40 | |||
| 5f50c7960c | |||
| 719e24eb80 | |||
| c441a1ab52 | |||
| b0460bd923 | |||
| f1659b3bda | |||
| eb4a2b3339 | |||
| 265bfe92fd | |||
| 1757fabb89 | |||
| abf0ebf41d | |||
| 45f1692c99 | 
							
								
								
									
										8
									
								
								.gitea/ISSUE_TEMPLATE.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.gitea/ISSUE_TEMPLATE.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | --- | ||||||
|  | name: "Do not use this issue tracker" | ||||||
|  | about: "Do not use this issue tracker" | ||||||
|  | title: "Do not use this issue tracker" | ||||||
|  | labels: [] | ||||||
|  | --- | ||||||
|  |  | ||||||
|  | Please report your issue on [`coop-cloud/organising`](https://git.coopcloud.tech/coop-cloud/organising) | ||||||
							
								
								
									
										33
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								README.md
									
									
									
									
									
								
							| @ -38,6 +38,30 @@ make install | |||||||
|  |  | ||||||
| The abra binary will be in `$GOPATH/bin`. | The abra binary will be in `$GOPATH/bin`. | ||||||
|  |  | ||||||
|  | ## Autocompletion | ||||||
|  |  | ||||||
|  | **bash** | ||||||
|  |  | ||||||
|  | Copy `scripts/autocomplete/bash` into `/etc/bash_completion.d/` and rename | ||||||
|  | it to abra. | ||||||
|  |  | ||||||
|  | ``` | ||||||
|  | sudo cp scripts/autocomplete/bash /etc/bash_completion.d/abra | ||||||
|  | source /etc/bash_completion.d/abra | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | **(fi)zsh** | ||||||
|  |  | ||||||
|  | (fi)zsh doesn't have an autocompletion folder by default but you can create one, then copy `scripts/autocomplete/zsh` into it and add a couple lines to your `~/.zshrc` or `~/.fizsh/.fizshrc` | ||||||
|  |  | ||||||
|  | ``` | ||||||
|  | sudo mkdir /etc/zsh/completion.d/ | ||||||
|  | sudo cp scripts/autocomplete/zsh /etc/zsh/completion.d/abra | ||||||
|  | echo "PROG=abra\n_CLI_ZSH_AUTOCOMPLETE_HACK=1\nsource /etc/zsh/completion.d/abra" >> ~/.zshrc | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | (replace .zshrc with ~/.fizsh/.fizshrc if you use fizsh) | ||||||
|  |  | ||||||
| ## Hacking | ## Hacking | ||||||
|  |  | ||||||
| Install direnv, run `cp .envrc.sample .envrc`, then run `direnv allow` in this directory. This will set coopcloud repos as private due to [this bug.](https://git.coopcloud.tech/coop-cloud/coopcloud.tech/issues/20#issuecomment-8201). Or you can run `go env -w GOPRIVATE=coopcloud.tech` but I'm not sure how persistent this is. | Install direnv, run `cp .envrc.sample .envrc`, then run `direnv allow` in this directory. This will set coopcloud repos as private due to [this bug.](https://git.coopcloud.tech/coop-cloud/coopcloud.tech/issues/20#issuecomment-8201). Or you can run `go env -w GOPRIVATE=coopcloud.tech` but I'm not sure how persistent this is. | ||||||
| @ -58,6 +82,15 @@ We use [goreleaser](https://goreleaser.com) to help us automate releases. We use | |||||||
|  |  | ||||||
| For developers, while using this `-alpha` format, the `y` part is the "major" version part. So, if you make breaking changes, you increment that and _not_ the `x` part. So, if you're on `0.1.0-alpha`, then you'd go to `0.1.1-alpha` for a backwards compatible change and `0.2.0-alpha` for a backwards incompatible change. | For developers, while using this `-alpha` format, the `y` part is the "major" version part. So, if you make breaking changes, you increment that and _not_ the `x` part. So, if you're on `0.1.0-alpha`, then you'd go to `0.1.1-alpha` for a backwards compatible change and `0.2.0-alpha` for a backwards incompatible change. | ||||||
|  |  | ||||||
|  | ## Making a new release | ||||||
|  |  | ||||||
|  | - Change `ABRA_VERSION` to match the new tag in [`scripts`](./scripts/installer/installer) (use [semver](https://semver.org)) | ||||||
|  | - Commit that change (e.g. `git commit -m 'chore: publish next tag 0.3.1-alpha'`) | ||||||
|  | - Make a new tag (e.g. `git tag 0.y.z-alpha`) | ||||||
|  | - Push the new tag (e.g. `git push && git push --tags`) | ||||||
|  | - Wait until the build finishes on [build.coopcloud.tech](https://build.coopcloud.tech/coop-cloud/abra) | ||||||
|  | - Check the release worked, (e.g. `abra upgrade; abra version`) | ||||||
|  |  | ||||||
| ## Fork maintenance | ## Fork maintenance | ||||||
|  |  | ||||||
| We maintain a fork of [godotenv](https://github.com/Autonomic-Cooperative/godotenv) for two features: | We maintain a fork of [godotenv](https://github.com/Autonomic-Cooperative/godotenv) for two features: | ||||||
|  | |||||||
							
								
								
									
										67
									
								
								TODO.md
									
									
									
									
									
								
							
							
						
						
									
										67
									
								
								TODO.md
									
									
									
									
									
								
							| @ -1,67 +0,0 @@ | |||||||
| # TODO |  | ||||||
|  |  | ||||||
| ## Bash feature parity |  | ||||||
|  |  | ||||||
| - [ ] Commands |  | ||||||
|   - [x] `abra server` |  | ||||||
|     - [x] `ls` |  | ||||||
|     - [x] `add` |  | ||||||
|     - [x] `new` |  | ||||||
|       - [x] `capsul` |  | ||||||
|       - [x] `hetzner` |  | ||||||
|     - [x] `rm` |  | ||||||
|     - [x] `init` |  | ||||||
|   - [ ] `abra app` |  | ||||||
|     - [x] `ls` |  | ||||||
|     - [x] `new` |  | ||||||
|     - [x] `backup` |  | ||||||
|     - [x] `deploy` |  | ||||||
|     - [x] `check` |  | ||||||
|     - [x] `version` |  | ||||||
|     - [x] `config` |  | ||||||
|     - [x] `cp` |  | ||||||
|     - [x] `logs` |  | ||||||
|     - [x] `ps` |  | ||||||
|     - [x] `restore` |  | ||||||
|     - [x] `rm` |  | ||||||
|     - [x] `run` |  | ||||||
|     - [ ] `rollback` |  | ||||||
|     - [x] `secret` |  | ||||||
|       - [x] `generate` |  | ||||||
|       - [x] `insert` |  | ||||||
|       - [x] `rm` |  | ||||||
|       - [x] `ls` |  | ||||||
|     - [x] `undeploy` |  | ||||||
|     - [ ] `volume` |  | ||||||
|       - [x] `ls` (WIP: knoflook) |  | ||||||
|       - [ ] `rm` (WIP: knoflook) |  | ||||||
|   - [x] `abra recipe` |  | ||||||
|     - [x] `ls` |  | ||||||
|     - [x] `create` |  | ||||||
|     - [x] `upgrade` |  | ||||||
|     - [x] `sync` |  | ||||||
|     - [x] `versions` |  | ||||||
|     - [x] `lint` |  | ||||||
|   - [ ] `upgrade` |  | ||||||
|   - [x] `version` |  | ||||||
|  |  | ||||||
| ## Next phase |  | ||||||
|  |  | ||||||
| - [ ] Polishing UI/UX and testing |  | ||||||
| - [ ] Refactoring and code organisation |  | ||||||
| - [ ] Automated builds for releasing |  | ||||||
|  |  | ||||||
| ## New features |  | ||||||
|  |  | ||||||
| - [ ] Commands |  | ||||||
|   - [ ] `abra server` |  | ||||||
|     - [ ] `dns` |  | ||||||
|       - [ ] `gandi` |  | ||||||
|   - [ ] `abra recipe` |  | ||||||
|     - [ ] "TBD apps.json generating command" (see [#40](https://git.coopcloud.tech/coop-cloud/go-abra/issues/40)) |  | ||||||
| - [ ] Package manager integration |  | ||||||
|   - [x] AUR |  | ||||||
|   - [ ] Debian |  | ||||||
|   - [ ] Ubuntu |  | ||||||
|   - [ ] Fedora |  | ||||||
|   - [ ] Homebrew |  | ||||||
| @ -66,13 +66,22 @@ var appBackupCommand = &cli.Command{ | |||||||
|  |  | ||||||
| 		sourceAndExec := fmt.Sprintf("%s; %s", sourceCmd, execCmd) | 		sourceAndExec := fmt.Sprintf("%s; %s", sourceCmd, execCmd) | ||||||
| 		cmd := exec.Command("bash", "-c", sourceAndExec) | 		cmd := exec.Command("bash", "-c", sourceAndExec) | ||||||
| 		output, err := cmd.Output() | 		if err := internal.RunCmd(cmd); err != nil { | ||||||
| 		if err != nil { |  | ||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		fmt.Print(string(output)) |  | ||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
|  | 	BashComplete: func(c *cli.Context) { | ||||||
|  | 		appNames, err := config.GetAppNames() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Warn(err) | ||||||
|  | 		} | ||||||
|  | 		if c.NArg() > 0 { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		for _, a := range appNames { | ||||||
|  | 			fmt.Println(a) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,6 +1,7 @@ | |||||||
| package app | package app | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
|  | 	"fmt" | ||||||
| 	"os" | 	"os" | ||||||
| 	"path" | 	"path" | ||||||
| 	"strings" | 	"strings" | ||||||
| @ -44,8 +45,20 @@ var appCheckCommand = &cli.Command{ | |||||||
| 			logrus.Fatalf("%s is missing %s", app.Path, missingEnvVars) | 			logrus.Fatalf("%s is missing %s", app.Path, missingEnvVars) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		logrus.Info("All necessary environment variables defined") | 		logrus.Infof("all necessary environment variables defined for '%s'", app.Name) | ||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
|  | 	BashComplete: func(c *cli.Context) { | ||||||
|  | 		appNames, err := config.GetAppNames() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Warn(err) | ||||||
|  | 		} | ||||||
|  | 		if c.NArg() > 0 { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		for _, a := range appNames { | ||||||
|  | 			fmt.Println(a) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,10 +1,12 @@ | |||||||
| package app | package app | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
|  | 	"fmt" | ||||||
| 	"os" | 	"os" | ||||||
| 	"os/exec" | 	"os/exec" | ||||||
|  |  | ||||||
| 	"coopcloud.tech/abra/cli/internal" | 	"coopcloud.tech/abra/cli/internal" | ||||||
|  | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"github.com/AlecAivazis/survey/v2" | 	"github.com/AlecAivazis/survey/v2" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| 	"github.com/urfave/cli/v2" | 	"github.com/urfave/cli/v2" | ||||||
| @ -38,4 +40,16 @@ var appConfigCommand = &cli.Command{ | |||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
|  | 	BashComplete: func(c *cli.Context) { | ||||||
|  | 		appNames, err := config.GetAppNames() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Warn(err) | ||||||
|  | 		} | ||||||
|  | 		if c.NArg() > 0 { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		for _, a := range appNames { | ||||||
|  | 			fmt.Println(a) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -6,6 +6,7 @@ import ( | |||||||
| 	"os" | 	"os" | ||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
|  | 	"coopcloud.tech/abra/cli/formatter" | ||||||
| 	"coopcloud.tech/abra/cli/internal" | 	"coopcloud.tech/abra/cli/internal" | ||||||
| 	"coopcloud.tech/abra/pkg/client" | 	"coopcloud.tech/abra/pkg/client" | ||||||
| 	"coopcloud.tech/abra/pkg/config" | 	"coopcloud.tech/abra/pkg/config" | ||||||
| @ -55,11 +56,13 @@ var appCpCommand = &cli.Command{ | |||||||
| 			service = parsedSrc[0] | 			service = parsedSrc[0] | ||||||
| 			srcPath = parsedSrc[1] | 			srcPath = parsedSrc[1] | ||||||
| 			dstPath = dst | 			dstPath = dst | ||||||
|  | 			logrus.Debugf("assuming transfer is coming FROM the container") | ||||||
| 		} else if len(parsedDst) == 2 { | 		} else if len(parsedDst) == 2 { | ||||||
| 			service = parsedDst[0] | 			service = parsedDst[0] | ||||||
| 			dstPath = parsedDst[1] | 			dstPath = parsedDst[1] | ||||||
| 			srcPath = src | 			srcPath = src | ||||||
| 			isToContainer = true // <src> <container:dst> | 			isToContainer = true // <src> <container:dst> | ||||||
|  | 			logrus.Debugf("assuming transfer is going TO the container") | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		appFiles, err := config.LoadAppFiles("") | 		appFiles, err := config.LoadAppFiles("") | ||||||
| @ -90,6 +93,8 @@ var appCpCommand = &cli.Command{ | |||||||
| 		} | 		} | ||||||
| 		container := containers[0] | 		container := containers[0] | ||||||
|  |  | ||||||
|  | 		logrus.Debugf("retrieved '%s' as target container on '%s'", formatter.ShortenID(container.ID), app.Server) | ||||||
|  |  | ||||||
| 		if isToContainer { | 		if isToContainer { | ||||||
| 			if _, err := os.Stat(srcPath); err != nil { | 			if _, err := os.Stat(srcPath); err != nil { | ||||||
| 				logrus.Fatalf("'%s' does not exist?", srcPath) | 				logrus.Fatalf("'%s' does not exist?", srcPath) | ||||||
|  | |||||||
| @ -54,4 +54,16 @@ var appDeployCommand = &cli.Command{ | |||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
|  | 	BashComplete: func(c *cli.Context) { | ||||||
|  | 		appNames, err := config.GetAppNames() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Warn(err) | ||||||
|  | 		} | ||||||
|  | 		if c.NArg() > 0 { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		for _, a := range appNames { | ||||||
|  | 			fmt.Println(a) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -95,6 +95,7 @@ can take some time. | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		table.Render() | 		table.Render() | ||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -9,6 +9,7 @@ import ( | |||||||
|  |  | ||||||
| 	"coopcloud.tech/abra/cli/internal" | 	"coopcloud.tech/abra/cli/internal" | ||||||
| 	"coopcloud.tech/abra/pkg/client" | 	"coopcloud.tech/abra/pkg/client" | ||||||
|  | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"github.com/docker/docker/api/types" | 	"github.com/docker/docker/api/types" | ||||||
| 	"github.com/docker/docker/api/types/filters" | 	"github.com/docker/docker/api/types/filters" | ||||||
| 	dockerClient "github.com/docker/docker/client" | 	dockerClient "github.com/docker/docker/client" | ||||||
| @ -72,8 +73,10 @@ var appLogsCommand = &cli.Command{ | |||||||
|  |  | ||||||
| 		serviceName := c.Args().Get(1) | 		serviceName := c.Args().Get(1) | ||||||
| 		if serviceName == "" { | 		if serviceName == "" { | ||||||
|  | 			logrus.Debug("tailing logs for all app services") | ||||||
| 			stackLogs(app.StackName(), cl) | 			stackLogs(app.StackName(), cl) | ||||||
| 		} | 		} | ||||||
|  | 		logrus.Debugf("tailing logs for '%s'", serviceName) | ||||||
|  |  | ||||||
| 		service := fmt.Sprintf("%s_%s", app.StackName(), serviceName) | 		service := fmt.Sprintf("%s_%s", app.StackName(), serviceName) | ||||||
| 		filters := filters.NewArgs() | 		filters := filters.NewArgs() | ||||||
| @ -109,4 +112,16 @@ var appLogsCommand = &cli.Command{ | |||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
|  | 	BashComplete: func(c *cli.Context) { | ||||||
|  | 		appNames, err := config.GetAppNames() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Warn(err) | ||||||
|  | 		} | ||||||
|  | 		if c.NArg() > 0 { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		for _, a := range appNames { | ||||||
|  | 			fmt.Println(a) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -32,7 +32,7 @@ var newAppServerFlag = &cli.StringFlag{ | |||||||
| 	Aliases:     []string{"s"}, | 	Aliases:     []string{"s"}, | ||||||
| 	Value:       "", | 	Value:       "", | ||||||
| 	Usage:       "Show apps of a specific server", | 	Usage:       "Show apps of a specific server", | ||||||
| 	Destination: &listAppServer, | 	Destination: &newAppServer, | ||||||
| } | } | ||||||
|  |  | ||||||
| var newAppName string | var newAppName string | ||||||
| @ -78,25 +78,18 @@ var appNewCommand = &cli.Command{ | |||||||
| 	}, | 	}, | ||||||
| 	ArgsUsage: "<recipe>", | 	ArgsUsage: "<recipe>", | ||||||
| 	Action:    action, | 	Action:    action, | ||||||
| } | 	BashComplete: func(c *cli.Context) { | ||||||
|  |  | ||||||
| // getRecipeMeta retrieves the recipe metadata from the recipe catalogue. |  | ||||||
| func getRecipeMeta(recipeName string) (catalogue.RecipeMeta, error) { |  | ||||||
| 		catl, err := catalogue.ReadRecipeCatalogue() | 		catl, err := catalogue.ReadRecipeCatalogue() | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 		return catalogue.RecipeMeta{}, err | 			logrus.Warn(err) | ||||||
| 		} | 		} | ||||||
|  | 		if c.NArg() > 0 { | ||||||
| 	recipeMeta, ok := catl[recipeName] | 			return | ||||||
| 	if !ok { |  | ||||||
| 		err := fmt.Errorf("recipe '%s' does not exist?", recipeName) |  | ||||||
| 		return catalogue.RecipeMeta{}, err |  | ||||||
| 		} | 		} | ||||||
| 	if err := recipePkg.EnsureExists(recipeMeta.Name); err != nil { | 		for name, _ := range catl { | ||||||
| 		return catalogue.RecipeMeta{}, err | 			fmt.Println(name) | ||||||
| 		} | 		} | ||||||
|  | 	}, | ||||||
| 	return recipeMeta, nil |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // ensureDomainFlag checks if the domain flag was used. if not, asks the user for it/ | // ensureDomainFlag checks if the domain flag was used. if not, asks the user for it/ | ||||||
| @ -114,11 +107,11 @@ func ensureDomainFlag() error { | |||||||
|  |  | ||||||
| // ensureServerFlag checks if the server flag was used. if not, asks the user for it. | // ensureServerFlag checks if the server flag was used. if not, asks the user for it. | ||||||
| func ensureServerFlag() error { | func ensureServerFlag() error { | ||||||
| 	appFiles, err := config.LoadAppFiles(newAppServer) | 	servers, err := config.GetServers() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	servers := appFiles.GetServers() |  | ||||||
| 	if newAppServer == "" { | 	if newAppServer == "" { | ||||||
| 		prompt := &survey.Select{ | 		prompt := &survey.Select{ | ||||||
| 			Message: "Select app server:", | 			Message: "Select app server:", | ||||||
| @ -128,6 +121,7 @@ func ensureServerFlag() error { | |||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -178,7 +172,7 @@ func action(c *cli.Context) error { | |||||||
| 		logrus.Fatal(err) | 		logrus.Fatal(err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	recipeMeta, err := getRecipeMeta(recipe.Name) | 	recipeMeta, err := catalogue.GetRecipeMeta(recipe.Name) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logrus.Fatal(err) | 		logrus.Fatal(err) | ||||||
| 	} | 	} | ||||||
| @ -204,6 +198,7 @@ func action(c *cli.Context) error { | |||||||
| 	if len(sanitisedAppName) > 45 { | 	if len(sanitisedAppName) > 45 { | ||||||
| 		logrus.Fatalf("'%s' cannot be longer than 45 characters", sanitisedAppName) | 		logrus.Fatalf("'%s' cannot be longer than 45 characters", sanitisedAppName) | ||||||
| 	} | 	} | ||||||
|  | 	logrus.Debugf("'%s' sanitised as '%s' for new app", newAppName, sanitisedAppName) | ||||||
|  |  | ||||||
| 	if err := config.CopyAppEnvSample(recipe.Name, newAppName, newAppServer); err != nil { | 	if err := config.CopyAppEnvSample(recipe.Name, newAppName, newAppServer); err != nil { | ||||||
| 		logrus.Fatal(err) | 		logrus.Fatal(err) | ||||||
| @ -220,8 +215,11 @@ func action(c *cli.Context) error { | |||||||
| 		for secret := range secrets { | 		for secret := range secrets { | ||||||
| 			secretTable.Append([]string{secret, secrets[secret]}) | 			secretTable.Append([]string{secret, secrets[secret]}) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		if len(secrets) > 0 { | ||||||
| 			defer secretTable.Render() | 			defer secretTable.Render() | ||||||
| 		} | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	tableCol := []string{"Name", "Domain", "Type", "Server"} | 	tableCol := []string{"Name", "Domain", "Type", "Server"} | ||||||
| 	table := abraFormatter.CreateTable(tableCol) | 	table := abraFormatter.CreateTable(tableCol) | ||||||
|  | |||||||
| @ -2,11 +2,13 @@ package app | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"fmt" | ||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
| 	abraFormatter "coopcloud.tech/abra/cli/formatter" | 	abraFormatter "coopcloud.tech/abra/cli/formatter" | ||||||
| 	"coopcloud.tech/abra/cli/internal" | 	"coopcloud.tech/abra/cli/internal" | ||||||
| 	"coopcloud.tech/abra/pkg/client" | 	"coopcloud.tech/abra/pkg/client" | ||||||
|  | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"github.com/docker/cli/cli/command/formatter" | 	"github.com/docker/cli/cli/command/formatter" | ||||||
| 	"github.com/docker/docker/api/types" | 	"github.com/docker/docker/api/types" | ||||||
| 	"github.com/docker/docker/api/types/filters" | 	"github.com/docker/docker/api/types/filters" | ||||||
| @ -35,7 +37,7 @@ var appPsCommand = &cli.Command{ | |||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		tableCol := []string{"ID", "Image", "Command", "Created", "Status", "Ports", "Names"} | 		tableCol := []string{"id", "image", "command", "created", "status", "ports", "names"} | ||||||
| 		table := abraFormatter.CreateTable(tableCol) | 		table := abraFormatter.CreateTable(tableCol) | ||||||
|  |  | ||||||
| 		for _, container := range containers { | 		for _, container := range containers { | ||||||
| @ -54,4 +56,16 @@ var appPsCommand = &cli.Command{ | |||||||
| 		table.Render() | 		table.Render() | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
|  | 	BashComplete: func(c *cli.Context) { | ||||||
|  | 		appNames, err := config.GetAppNames() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Warn(err) | ||||||
|  | 		} | ||||||
|  | 		if c.NArg() > 0 { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		for _, a := range appNames { | ||||||
|  | 			fmt.Println(a) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -39,13 +39,13 @@ var appRemoveCommand = &cli.Command{ | |||||||
| 		if !internal.Force { | 		if !internal.Force { | ||||||
| 			response := false | 			response := false | ||||||
| 			prompt := &survey.Confirm{ | 			prompt := &survey.Confirm{ | ||||||
| 				Message: fmt.Sprintf("About to delete %s, are you sure", app.Name), | 				Message: fmt.Sprintf("about to delete %s, are you sure?", app.Name), | ||||||
| 			} | 			} | ||||||
| 			if err := survey.AskOne(prompt, &response); err != nil { | 			if err := survey.AskOne(prompt, &response); err != nil { | ||||||
| 				logrus.Fatal(err) | 				logrus.Fatal(err) | ||||||
| 			} | 			} | ||||||
| 			if !response { | 			if !response { | ||||||
| 				logrus.Fatal("User aborted app removal") | 				logrus.Fatal("user aborted app removal") | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @ -89,7 +89,7 @@ var appRemoveCommand = &cli.Command{ | |||||||
| 			var secretNamesToRemove []string | 			var secretNamesToRemove []string | ||||||
| 			if !internal.Force { | 			if !internal.Force { | ||||||
| 				secretsPrompt := &survey.MultiSelect{ | 				secretsPrompt := &survey.MultiSelect{ | ||||||
| 					Message: "Which secrets do you want to remove?", | 					Message: "which secrets do you want to remove?", | ||||||
| 					Options: secretNames, | 					Options: secretNames, | ||||||
| 					Default: secretNames, | 					Default: secretNames, | ||||||
| 				} | 				} | ||||||
| @ -103,10 +103,10 @@ var appRemoveCommand = &cli.Command{ | |||||||
| 				if err != nil { | 				if err != nil { | ||||||
| 					logrus.Fatal(err) | 					logrus.Fatal(err) | ||||||
| 				} | 				} | ||||||
| 				logrus.Info(fmt.Sprintf("Secret: %s removed", name)) | 				logrus.Info(fmt.Sprintf("secret: %s removed", name)) | ||||||
| 			} | 			} | ||||||
| 		} else { | 		} else { | ||||||
| 			logrus.Info("No secrets to remove") | 			logrus.Info("no secrets to remove") | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		volumeListOKBody, err := cl.VolumeList(ctx, fs) | 		volumeListOKBody, err := cl.VolumeList(ctx, fs) | ||||||
| @ -125,7 +125,7 @@ var appRemoveCommand = &cli.Command{ | |||||||
| 				var removeVols []string | 				var removeVols []string | ||||||
| 				if !internal.Force { | 				if !internal.Force { | ||||||
| 					volumesPrompt := &survey.MultiSelect{ | 					volumesPrompt := &survey.MultiSelect{ | ||||||
| 						Message: "Which volumes do you want to remove?", | 						Message: "which volumes do you want to remove?", | ||||||
| 						Options: vols, | 						Options: vols, | ||||||
| 						Default: vols, | 						Default: vols, | ||||||
| 					} | 					} | ||||||
| @ -138,21 +138,33 @@ var appRemoveCommand = &cli.Command{ | |||||||
| 					if err != nil { | 					if err != nil { | ||||||
| 						logrus.Fatal(err) | 						logrus.Fatal(err) | ||||||
| 					} | 					} | ||||||
| 					logrus.Info(fmt.Sprintf("Volume %s removed", vol)) | 					logrus.Info(fmt.Sprintf("volume %s removed", vol)) | ||||||
| 				} | 				} | ||||||
| 			} else { | 			} else { | ||||||
| 				logrus.Info("No volumes were removed") | 				logrus.Info("no volumes were removed") | ||||||
| 			} | 			} | ||||||
| 		} else { | 		} else { | ||||||
| 			logrus.Info("No volumes to remove") | 			logrus.Info("no volumes to remove") | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		err = os.Remove(app.Path) | 		err = os.Remove(app.Path) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
| 		logrus.Info(fmt.Sprintf("File: %s removed", app.Path)) | 		logrus.Info(fmt.Sprintf("file: %s removed", app.Path)) | ||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
|  | 	BashComplete: func(c *cli.Context) { | ||||||
|  | 		appNames, err := config.GetAppNames() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Warn(err) | ||||||
|  | 		} | ||||||
|  | 		if c.NArg() > 0 { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		for _, a := range appNames { | ||||||
|  | 			fmt.Println(a) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -70,13 +70,10 @@ var appRestoreCommand = &cli.Command{ | |||||||
|  |  | ||||||
| 		sourceAndExec := fmt.Sprintf("%s; %s", sourceCmd, execCmd) | 		sourceAndExec := fmt.Sprintf("%s; %s", sourceCmd, execCmd) | ||||||
| 		cmd := exec.Command("bash", "-c", sourceAndExec) | 		cmd := exec.Command("bash", "-c", sourceAndExec) | ||||||
| 		output, err := cmd.Output() | 		if err := internal.RunCmd(cmd); err != nil { | ||||||
| 		if err != nil { |  | ||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		fmt.Print(string(output)) |  | ||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,10 +1,82 @@ | |||||||
| package app | package app | ||||||
|  |  | ||||||
| import "github.com/urfave/cli/v2" | import ( | ||||||
|  | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"context" | ||||||
|  |  | ||||||
|  | 	"coopcloud.tech/abra/pkg/config" | ||||||
|  |  | ||||||
|  | 	"coopcloud.tech/abra/cli/internal" | ||||||
|  | 	appPkg "coopcloud.tech/abra/pkg/app" | ||||||
|  | 	"coopcloud.tech/abra/pkg/catalogue" | ||||||
|  | 	"coopcloud.tech/abra/pkg/client" | ||||||
|  | 	"github.com/sirupsen/logrus" | ||||||
|  | 	"github.com/urfave/cli/v2" | ||||||
|  | ) | ||||||
|  |  | ||||||
| var appRollbackCommand = &cli.Command{ | var appRollbackCommand = &cli.Command{ | ||||||
| 	Name:      "rollback", | 	Name:      "rollback", | ||||||
| 	Usage:     "Roll an app back to a previous version", | 	Usage:     "Roll an app back to a previous version", | ||||||
| 	Aliases:   []string{"b"}, | 	Aliases:   []string{"r"}, | ||||||
| 	ArgsUsage: "[<version>]", | 	ArgsUsage: "[<version>]", | ||||||
|  | 	BashComplete: func(c *cli.Context) { | ||||||
|  | 		appNames, err := config.GetAppNames() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Warn(err) | ||||||
|  | 		} | ||||||
|  | 		if c.NArg() > 0 { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		for _, a := range appNames { | ||||||
|  | 			fmt.Println(a) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
|  | 	Action: func(c *cli.Context) error { | ||||||
|  | 		app := internal.ValidateApp(c) | ||||||
|  |  | ||||||
|  | 		ctx := context.Background() | ||||||
|  | 		cl, err := client.New(app.Server) | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Fatal(err) | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		recipeMeta, err := catalogue.GetRecipeMeta(app.Type) | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Fatal(err) | ||||||
|  | 		} | ||||||
|  | 		if len(recipeMeta.Versions) == 0 { | ||||||
|  | 			logrus.Fatalf("no catalogue versions available for '%s'", app.Type) | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		deployedVersions, isDeployed, err := appPkg.DeployedVersions(ctx, cl, app) | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Fatal(err) | ||||||
|  | 		} | ||||||
|  | 		if !isDeployed { | ||||||
|  | 			logrus.Fatalf("'%s' is not deployed?", app.Name) | ||||||
|  | 		} | ||||||
|  | 		if _, exists := deployedVersions["app"]; !exists { | ||||||
|  | 			logrus.Fatalf("no versioned 'app' service for '%s', cannot determine version", app.Name) | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		version := c.Args().Get(1) | ||||||
|  | 		if version == "" { | ||||||
|  | 			// TODO: | ||||||
|  | 			// using deployedVersions["app"], get index+1 version from catalogue | ||||||
|  | 			// otherwise bail out saying there is nothing to rollback to | ||||||
|  | 		} else { | ||||||
|  | 			// TODO | ||||||
|  | 			// ensure this version is listed in the catalogue | ||||||
|  | 			// ensure this version is "older" (lower down in the list) | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		// TODO | ||||||
|  | 		// display table of existing state and expected state and prompt | ||||||
|  | 		// run the deployment with this target version! | ||||||
|  |  | ||||||
|  | 		logrus.Fatal("command not implemented yet, coming soon TM") | ||||||
|  |  | ||||||
|  | 		return nil | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -8,6 +8,7 @@ import ( | |||||||
| 	"coopcloud.tech/abra/cli/internal" | 	"coopcloud.tech/abra/cli/internal" | ||||||
| 	"coopcloud.tech/abra/pkg/client" | 	"coopcloud.tech/abra/pkg/client" | ||||||
| 	"coopcloud.tech/abra/pkg/client/container" | 	"coopcloud.tech/abra/pkg/client/container" | ||||||
|  | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"github.com/docker/cli/cli/command" | 	"github.com/docker/cli/cli/command" | ||||||
| 	"github.com/docker/docker/api/types" | 	"github.com/docker/docker/api/types" | ||||||
| 	"github.com/docker/docker/api/types/filters" | 	"github.com/docker/docker/api/types/filters" | ||||||
| @ -42,7 +43,11 @@ var appRunCommand = &cli.Command{ | |||||||
| 		app := internal.ValidateApp(c) | 		app := internal.ValidateApp(c) | ||||||
|  |  | ||||||
| 		if c.Args().Len() < 2 { | 		if c.Args().Len() < 2 { | ||||||
| 			internal.ShowSubcommandHelpAndError(c, errors.New("no <service> provided")) | 			internal.ShowSubcommandHelpAndError(c, errors.New("no <service> provided?")) | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		if c.Args().Len() < 3 { | ||||||
|  | 			internal.ShowSubcommandHelpAndError(c, errors.New("no <args> provided?")) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		ctx := context.Background() | 		ctx := context.Background() | ||||||
| @ -96,4 +101,25 @@ var appRunCommand = &cli.Command{ | |||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
|  | 	BashComplete: func(c *cli.Context) { | ||||||
|  | 		switch c.NArg() { | ||||||
|  | 		case 0: | ||||||
|  | 			appNames, err := config.GetAppNames() | ||||||
|  | 			if err != nil { | ||||||
|  | 				logrus.Warn(err) | ||||||
|  | 			} | ||||||
|  | 			for _, a := range appNames { | ||||||
|  | 				fmt.Println(a) | ||||||
|  | 			} | ||||||
|  | 		case 1: | ||||||
|  | 			appName := c.Args().First() | ||||||
|  | 			serviceNames, err := config.GetAppServiceNames(appName) | ||||||
|  | 			if err != nil { | ||||||
|  | 				logrus.Warn(err) | ||||||
|  | 			} | ||||||
|  | 			for _, s := range serviceNames { | ||||||
|  | 				fmt.Println(s) | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -10,6 +10,7 @@ import ( | |||||||
| 	abraFormatter "coopcloud.tech/abra/cli/formatter" | 	abraFormatter "coopcloud.tech/abra/cli/formatter" | ||||||
| 	"coopcloud.tech/abra/cli/internal" | 	"coopcloud.tech/abra/cli/internal" | ||||||
| 	"coopcloud.tech/abra/pkg/client" | 	"coopcloud.tech/abra/pkg/client" | ||||||
|  | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"coopcloud.tech/abra/pkg/secret" | 	"coopcloud.tech/abra/pkg/secret" | ||||||
| 	"github.com/docker/docker/api/types" | 	"github.com/docker/docker/api/types" | ||||||
| 	"github.com/docker/docker/api/types/filters" | 	"github.com/docker/docker/api/types/filters" | ||||||
| @ -82,13 +83,13 @@ var appSecretGenerateCommand = &cli.Command{ | |||||||
| 			os.Exit(1) | 			os.Exit(1) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		tableCol := []string{"Name", "Value"} | 		tableCol := []string{"name", "value"} | ||||||
| 		table := abraFormatter.CreateTable(tableCol) | 		table := abraFormatter.CreateTable(tableCol) | ||||||
| 		for name, val := range secretVals { | 		for name, val := range secretVals { | ||||||
| 			table.Append([]string{name, val}) | 			table.Append([]string{name, val}) | ||||||
| 		} | 		} | ||||||
| 		table.Render() | 		table.Render() | ||||||
| 		logrus.Warn("these secrets are not shown again, please take note of them *now*") | 		logrus.Warn("generated secrets are not shown again, please take note of them *now*") | ||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
| @ -234,6 +235,18 @@ var appSecretLsCommand = &cli.Command{ | |||||||
| 		table.Render() | 		table.Render() | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
|  | 	BashComplete: func(c *cli.Context) { | ||||||
|  | 		appNames, err := config.GetAppNames() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Warn(err) | ||||||
|  | 		} | ||||||
|  | 		if c.NArg() > 0 { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		for _, a := range appNames { | ||||||
|  | 			fmt.Println(a) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  |  | ||||||
| var appSecretCommand = &cli.Command{ | var appSecretCommand = &cli.Command{ | ||||||
|  | |||||||
| @ -2,10 +2,12 @@ package app | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"fmt" | ||||||
|  |  | ||||||
| 	"coopcloud.tech/abra/cli/internal" | 	"coopcloud.tech/abra/cli/internal" | ||||||
| 	"coopcloud.tech/abra/pkg/client" | 	"coopcloud.tech/abra/pkg/client" | ||||||
| 	stack "coopcloud.tech/abra/pkg/client/stack" | 	stack "coopcloud.tech/abra/pkg/client/stack" | ||||||
|  | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| 	"github.com/urfave/cli/v2" | 	"github.com/urfave/cli/v2" | ||||||
| ) | ) | ||||||
| @ -35,4 +37,16 @@ volumes as eligiblef or pruning once undeployed. | |||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
|  | 	BashComplete: func(c *cli.Context) { | ||||||
|  | 		appNames, err := config.GetAppNames() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Warn(err) | ||||||
|  | 		} | ||||||
|  | 		if c.NArg() > 0 { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		for _, a := range appNames { | ||||||
|  | 			fmt.Println(a) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -7,6 +7,7 @@ import ( | |||||||
|  |  | ||||||
| 	abraFormatter "coopcloud.tech/abra/cli/formatter" | 	abraFormatter "coopcloud.tech/abra/cli/formatter" | ||||||
| 	"coopcloud.tech/abra/cli/internal" | 	"coopcloud.tech/abra/cli/internal" | ||||||
|  | 	appPkg "coopcloud.tech/abra/pkg/app" | ||||||
| 	"coopcloud.tech/abra/pkg/client/stack" | 	"coopcloud.tech/abra/pkg/client/stack" | ||||||
| 	"coopcloud.tech/abra/pkg/config" | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"github.com/docker/distribution/reference" | 	"github.com/docker/distribution/reference" | ||||||
| @ -24,22 +25,10 @@ func getImagePath(image string) (string, error) { | |||||||
| 	if strings.Contains(path, "library") { | 	if strings.Contains(path, "library") { | ||||||
| 		path = strings.Split(path, "/")[1] | 		path = strings.Split(path, "/")[1] | ||||||
| 	} | 	} | ||||||
|  | 	logrus.Debugf("parsed '%s' from '%s'", path, image) | ||||||
| 	return path, nil | 	return path, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // parseVersionLabel parses a $STACK_NAME_$SERVICE_NAME service label |  | ||||||
| func parseServiceName(label string) string { |  | ||||||
| 	idx := strings.LastIndex(label, "_") |  | ||||||
| 	return label[idx+1:] |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // parseVersionLabel parses a $VERSION-$DIGEST service label |  | ||||||
| func parseVersionLabel(label string) (string, string) { |  | ||||||
| 	// versions may look like v4.2-abcd or v4.2-alpine-abcd |  | ||||||
| 	idx := strings.LastIndex(label, "-") |  | ||||||
| 	return label[:idx], label[idx+1:] |  | ||||||
| } |  | ||||||
|  |  | ||||||
| var appVersionCommand = &cli.Command{ | var appVersionCommand = &cli.Command{ | ||||||
| 	Name:    "version", | 	Name:    "version", | ||||||
| 	Aliases: []string{"v"}, | 	Aliases: []string{"v"}, | ||||||
| @ -65,14 +54,14 @@ var appVersionCommand = &cli.Command{ | |||||||
| 			}(app.Server, label) | 			}(app.Server, label) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		tableCol := []string{"Name", "Image", "Version", "Digest"} | 		tableCol := []string{"name", "image", "version", "digest"} | ||||||
| 		table := abraFormatter.CreateTable(tableCol) | 		table := abraFormatter.CreateTable(tableCol) | ||||||
|  |  | ||||||
| 		statuses := make(map[string]stack.StackStatus) | 		statuses := make(map[string]stack.StackStatus) | ||||||
| 		for range compose.Services { | 		for range compose.Services { | ||||||
| 			status := <-ch | 			status := <-ch | ||||||
| 			if len(status.Services) > 0 { | 			if len(status.Services) > 0 { | ||||||
| 				serviceName := parseServiceName(status.Services[0].Spec.Name) | 				serviceName := appPkg.ParseServiceName(status.Services[0].Spec.Name) | ||||||
| 				statuses[serviceName] = status | 				statuses[serviceName] = status | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @ -85,7 +74,7 @@ var appVersionCommand = &cli.Command{ | |||||||
| 			if status, ok := statuses[service.Name]; ok { | 			if status, ok := statuses[service.Name]; ok { | ||||||
| 				statusService := status.Services[0] | 				statusService := status.Services[0] | ||||||
| 				label := fmt.Sprintf("coop-cloud.%s.%s.version", app.StackName(), service.Name) | 				label := fmt.Sprintf("coop-cloud.%s.%s.version", app.StackName(), service.Name) | ||||||
| 				version, digest := parseVersionLabel(statusService.Spec.Labels[label]) | 				version, digest := appPkg.ParseVersionLabel(statusService.Spec.Labels[label]) | ||||||
| 				image, err := getImagePath(statusService.Spec.Labels["com.docker.stack.image"]) | 				image, err := getImagePath(statusService.Spec.Labels["com.docker.stack.image"]) | ||||||
| 				if err != nil { | 				if err != nil { | ||||||
| 					logrus.Fatal(err) | 					logrus.Fatal(err) | ||||||
| @ -104,4 +93,16 @@ var appVersionCommand = &cli.Command{ | |||||||
| 		table.Render() | 		table.Render() | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
|  | 	BashComplete: func(c *cli.Context) { | ||||||
|  | 		appNames, err := config.GetAppNames() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Warn(err) | ||||||
|  | 		} | ||||||
|  | 		if c.NArg() > 0 { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		for _, a := range appNames { | ||||||
|  | 			fmt.Println(a) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -2,10 +2,12 @@ package app | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"fmt" | ||||||
|  |  | ||||||
| 	abraFormatter "coopcloud.tech/abra/cli/formatter" | 	abraFormatter "coopcloud.tech/abra/cli/formatter" | ||||||
| 	"coopcloud.tech/abra/cli/internal" | 	"coopcloud.tech/abra/cli/internal" | ||||||
| 	"coopcloud.tech/abra/pkg/client" | 	"coopcloud.tech/abra/pkg/client" | ||||||
|  | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"github.com/AlecAivazis/survey/v2" | 	"github.com/AlecAivazis/survey/v2" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| 	"github.com/urfave/cli/v2" | 	"github.com/urfave/cli/v2" | ||||||
| @ -13,7 +15,7 @@ import ( | |||||||
|  |  | ||||||
| var appVolumeListCommand = &cli.Command{ | var appVolumeListCommand = &cli.Command{ | ||||||
| 	Name:    "list", | 	Name:    "list", | ||||||
| 	Usage:   "list volumes associated with an app", | 	Usage:   "List volumes associated with an app", | ||||||
| 	Aliases: []string{"ls"}, | 	Aliases: []string{"ls"}, | ||||||
| 	Action: func(c *cli.Context) error { | 	Action: func(c *cli.Context) error { | ||||||
| 		app := internal.ValidateApp(c) | 		app := internal.ValidateApp(c) | ||||||
| @ -24,7 +26,7 @@ var appVolumeListCommand = &cli.Command{ | |||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		table := abraFormatter.CreateTable([]string{"DRIVER", "VOLUME NAME"}) | 		table := abraFormatter.CreateTable([]string{"driver", "volume name"}) | ||||||
| 		var volTable [][]string | 		var volTable [][]string | ||||||
| 		for _, volume := range volumeList { | 		for _, volume := range volumeList { | ||||||
| 			volRow := []string{ | 			volRow := []string{ | ||||||
| @ -43,7 +45,7 @@ var appVolumeListCommand = &cli.Command{ | |||||||
|  |  | ||||||
| var appVolumeRemoveCommand = &cli.Command{ | var appVolumeRemoveCommand = &cli.Command{ | ||||||
| 	Name:    "remove", | 	Name:    "remove", | ||||||
| 	Usage:   "remove volume(s) associated with an app", | 	Usage:   "Remove volume(s) associated with an app", | ||||||
| 	Aliases: []string{"rm"}, | 	Aliases: []string{"rm"}, | ||||||
| 	Flags: []cli.Flag{ | 	Flags: []cli.Flag{ | ||||||
| 		internal.ForceFlag, | 		internal.ForceFlag, | ||||||
| @ -61,7 +63,7 @@ var appVolumeRemoveCommand = &cli.Command{ | |||||||
| 		var volumesToRemove []string | 		var volumesToRemove []string | ||||||
| 		if !internal.Force { | 		if !internal.Force { | ||||||
| 			volumesPrompt := &survey.MultiSelect{ | 			volumesPrompt := &survey.MultiSelect{ | ||||||
| 				Message: "Which volumes do you want to remove?", | 				Message: "which volumes do you want to remove?", | ||||||
| 				Options: volumeNames, | 				Options: volumeNames, | ||||||
| 				Default: volumeNames, | 				Default: volumeNames, | ||||||
| 			} | 			} | ||||||
| @ -77,10 +79,22 @@ var appVolumeRemoveCommand = &cli.Command{ | |||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		logrus.Info("Volumes removed successfully.") | 		logrus.Info("volumes removed successfully") | ||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
|  | 	BashComplete: func(c *cli.Context) { | ||||||
|  | 		appNames, err := config.GetAppNames() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Warn(err) | ||||||
|  | 		} | ||||||
|  | 		if c.NArg() > 0 { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		for _, a := range appNames { | ||||||
|  | 			fmt.Println(a) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  |  | ||||||
| var appVolumeCommand = &cli.Command{ | var appVolumeCommand = &cli.Command{ | ||||||
|  | |||||||
							
								
								
									
										17
									
								
								cli/catalogue/catalogue.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								cli/catalogue/catalogue.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | |||||||
|  | package catalogue | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"github.com/urfave/cli/v2" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | // CatalogueCommand defines the `abra catalogue` command and sub-commands. | ||||||
|  | var CatalogueCommand = &cli.Command{ | ||||||
|  | 	Name:        "catalogue", | ||||||
|  | 	Usage:       "Manage the recipe catalogue", | ||||||
|  | 	Aliases:     []string{"c"}, | ||||||
|  | 	ArgsUsage:   "<recipe>", | ||||||
|  | 	Description: "This command helps recipe packagers interact with the recipe catalogue", | ||||||
|  | 	Subcommands: []*cli.Command{ | ||||||
|  | 		catalogueGenerateCommand, | ||||||
|  | 	}, | ||||||
|  | } | ||||||
							
								
								
									
										41
									
								
								cli/catalogue/generate.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								cli/catalogue/generate.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,41 @@ | |||||||
|  | package catalogue | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"path" | ||||||
|  | 	"strings" | ||||||
|  |  | ||||||
|  | 	"coopcloud.tech/abra/pkg/catalogue" | ||||||
|  | 	"coopcloud.tech/abra/pkg/config" | ||||||
|  | 	"coopcloud.tech/abra/pkg/git" | ||||||
|  | 	"github.com/sirupsen/logrus" | ||||||
|  | 	"github.com/urfave/cli/v2" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | var catalogueGenerateCommand = &cli.Command{ | ||||||
|  | 	Name:         "generate", | ||||||
|  | 	Aliases:      []string{"g"}, | ||||||
|  | 	Usage:        "Generate a new copy of the catalogue", | ||||||
|  | 	BashComplete: func(c *cli.Context) {}, | ||||||
|  | 	Action: func(c *cli.Context) error { | ||||||
|  | 		catl, err := catalogue.ReadRecipeCatalogue() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Fatal(err) | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		for recipeName, recipeMeta := range catl { | ||||||
|  | 			recipeDir := path.Join(config.ABRA_DIR, "apps", strings.ToLower(recipeName)) | ||||||
|  | 			if err := git.Clone(recipeDir, recipeMeta.Repository); err != nil { | ||||||
|  | 				logrus.Fatal(err) | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			if err := git.EnsureUpToDate(recipeDir); err != nil { | ||||||
|  | 				logrus.Fatal(err) | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		// for reach app, build the recipemeta from parsing | ||||||
|  | 		// spit out a JSON file | ||||||
|  |  | ||||||
|  | 		return nil | ||||||
|  | 	}, | ||||||
|  | } | ||||||
							
								
								
									
										14
									
								
								cli/cli.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								cli/cli.go
									
									
									
									
									
								
							| @ -6,6 +6,7 @@ import ( | |||||||
| 	"os" | 	"os" | ||||||
|  |  | ||||||
| 	"coopcloud.tech/abra/cli/app" | 	"coopcloud.tech/abra/cli/app" | ||||||
|  | 	"coopcloud.tech/abra/cli/catalogue" | ||||||
| 	"coopcloud.tech/abra/cli/recipe" | 	"coopcloud.tech/abra/cli/recipe" | ||||||
| 	"coopcloud.tech/abra/cli/server" | 	"coopcloud.tech/abra/cli/server" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| @ -54,7 +55,9 @@ func RunApp(version, commit string) { | |||||||
| 			app.AppCommand, | 			app.AppCommand, | ||||||
| 			server.ServerCommand, | 			server.ServerCommand, | ||||||
| 			recipe.RecipeCommand, | 			recipe.RecipeCommand, | ||||||
|  | 			catalogue.CatalogueCommand, | ||||||
| 			VersionCommand, | 			VersionCommand, | ||||||
|  | 			UpgradeCommand, | ||||||
| 		}, | 		}, | ||||||
| 		Flags: []cli.Flag{ | 		Flags: []cli.Flag{ | ||||||
| 			VerboseFlag, | 			VerboseFlag, | ||||||
| @ -68,6 +71,17 @@ func RunApp(version, commit string) { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	app.EnableBashCompletion = true | ||||||
|  |  | ||||||
|  | 	app.Before = func(c *cli.Context) error { | ||||||
|  | 		if Debug { | ||||||
|  | 			logrus.SetLevel(logrus.DebugLevel) | ||||||
|  | 		} | ||||||
|  | 		return nil | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("Flying abra version '%s', commit '%s', enjoy the ride", version, commit) | ||||||
|  |  | ||||||
| 	if err := app.Run(os.Args); err != nil { | 	if err := app.Run(os.Args); err != nil { | ||||||
| 		logrus.Fatal(err) | 		logrus.Fatal(err) | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -31,6 +31,7 @@ func HumanDuration(timestamp int64) string { | |||||||
| 	return units.HumanDuration(now.Sub(date)) + " ago" | 	return units.HumanDuration(now.Sub(date)) + " ago" | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // CreateTable prepares a table layout for output. | ||||||
| func CreateTable(columns []string) *tablewriter.Table { | func CreateTable(columns []string) *tablewriter.Table { | ||||||
| 	table := tablewriter.NewWriter(os.Stdout) | 	table := tablewriter.NewWriter(os.Stdout) | ||||||
| 	table.SetHeader(columns) | 	table.SetHeader(columns) | ||||||
|  | |||||||
							
								
								
									
										39
									
								
								cli/internal/command.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								cli/internal/command.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,39 @@ | |||||||
|  | package internal | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"bufio" | ||||||
|  | 	"fmt" | ||||||
|  | 	"os/exec" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | // RunCmd runs a shell command and streams stdout/stderr in real-time. | ||||||
|  | func RunCmd(cmd *exec.Cmd) error { | ||||||
|  | 	r, err := cmd.StdoutPipe() | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	cmd.Stderr = cmd.Stdout | ||||||
|  | 	done := make(chan struct{}) | ||||||
|  | 	scanner := bufio.NewScanner(r) | ||||||
|  |  | ||||||
|  | 	go func() { | ||||||
|  | 		for scanner.Scan() { | ||||||
|  | 			line := scanner.Text() | ||||||
|  | 			fmt.Println(line) | ||||||
|  | 		} | ||||||
|  | 		done <- struct{}{} | ||||||
|  | 	}() | ||||||
|  |  | ||||||
|  | 	if err := cmd.Start(); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	<-done | ||||||
|  |  | ||||||
|  | 	if err := cmd.Wait(); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
| @ -2,7 +2,6 @@ package internal | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"os" |  | ||||||
|  |  | ||||||
| 	"coopcloud.tech/abra/pkg/app" | 	"coopcloud.tech/abra/pkg/app" | ||||||
| 	"coopcloud.tech/abra/pkg/config" | 	"coopcloud.tech/abra/pkg/config" | ||||||
| @ -22,9 +21,10 @@ func ValidateRecipe(c *cli.Context) recipe.Recipe { | |||||||
| 	recipe, err := recipe.Get(recipeName) | 	recipe, err := recipe.Get(recipeName) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logrus.Fatal(err) | 		logrus.Fatal(err) | ||||||
| 		os.Exit(1) |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("validated '%s' as recipe argument", recipeName) | ||||||
|  |  | ||||||
| 	return recipe | 	return recipe | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -39,8 +39,22 @@ func ValidateApp(c *cli.Context) config.App { | |||||||
| 	app, err := app.Get(appName) | 	app, err := app.Get(appName) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logrus.Fatal(err) | 		logrus.Fatal(err) | ||||||
| 		os.Exit(1) |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("validated '%s' as app argument", appName) | ||||||
|  |  | ||||||
| 	return app | 	return app | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // ValidateDomain ensures the domain name arg is valid. | ||||||
|  | func ValidateDomain(c *cli.Context) string { | ||||||
|  | 	domainName := c.Args().First() | ||||||
|  |  | ||||||
|  | 	if domainName == "" { | ||||||
|  | 		ShowSubcommandHelpAndError(c, errors.New("no domain provided")) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("validated '%s' as domain argument", domainName) | ||||||
|  |  | ||||||
|  | 	return domainName | ||||||
|  | } | ||||||
|  | |||||||
| @ -7,6 +7,7 @@ import ( | |||||||
|  |  | ||||||
| 	"coopcloud.tech/abra/cli/formatter" | 	"coopcloud.tech/abra/cli/formatter" | ||||||
| 	"coopcloud.tech/abra/cli/internal" | 	"coopcloud.tech/abra/cli/internal" | ||||||
|  | 	"coopcloud.tech/abra/pkg/catalogue" | ||||||
| 	"coopcloud.tech/abra/pkg/config" | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"coopcloud.tech/tagcmp" | 	"coopcloud.tech/tagcmp" | ||||||
| 	"github.com/docker/distribution/reference" | 	"github.com/docker/distribution/reference" | ||||||
| @ -76,18 +77,30 @@ var recipeLintCommand = &cli.Command{ | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		tableCol := []string{"Rule", "Satisfied"} | 		tableCol := []string{"rule", "satisfied"} | ||||||
| 		table := formatter.CreateTable(tableCol) | 		table := formatter.CreateTable(tableCol) | ||||||
| 		table.Append([]string{"Compose files have the expected version", strconv.FormatBool(expectedVersion)}) | 		table.Append([]string{"compose files have the expected version", strconv.FormatBool(expectedVersion)}) | ||||||
| 		table.Append([]string{"Environment configuration is provided", strconv.FormatBool(envSampleProvided)}) | 		table.Append([]string{"environment configuration is provided", strconv.FormatBool(envSampleProvided)}) | ||||||
| 		table.Append([]string{"Recipe contains a service named 'app'", strconv.FormatBool(serviceNamedApp)}) | 		table.Append([]string{"recipe contains a service named 'app'", strconv.FormatBool(serviceNamedApp)}) | ||||||
| 		table.Append([]string{"Traefik routing enabled on at least one service", strconv.FormatBool(traefikEnabled)}) | 		table.Append([]string{"traefik routing enabled on at least one service", strconv.FormatBool(traefikEnabled)}) | ||||||
| 		table.Append([]string{"All services have a healthcheck enabled", strconv.FormatBool(healthChecksForAllServices)}) | 		table.Append([]string{"all services have a healthcheck enabled", strconv.FormatBool(healthChecksForAllServices)}) | ||||||
| 		table.Append([]string{"All images are using a tag", strconv.FormatBool(allImagesTagged)}) | 		table.Append([]string{"all images are using a tag", strconv.FormatBool(allImagesTagged)}) | ||||||
| 		table.Append([]string{"No usage of unstable 'latest' tags", strconv.FormatBool(noUnstableTags)}) | 		table.Append([]string{"no usage of unstable 'latest' tags", strconv.FormatBool(noUnstableTags)}) | ||||||
| 		table.Append([]string{"All tags are using a semver-like format", strconv.FormatBool(semverLikeTags)}) | 		table.Append([]string{"all tags are using a semver-like format", strconv.FormatBool(semverLikeTags)}) | ||||||
| 		table.Render() | 		table.Render() | ||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
|  | 	BashComplete: func(c *cli.Context) { | ||||||
|  | 		catl, err := catalogue.ReadRecipeCatalogue() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Warn(err) | ||||||
|  | 		} | ||||||
|  | 		if c.NArg() > 0 { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 		for name, _ := range catl { | ||||||
|  | 			fmt.Println(name) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -23,7 +23,7 @@ var recipeListCommand = &cli.Command{ | |||||||
| 		recipes := catl.Flatten() | 		recipes := catl.Flatten() | ||||||
| 		sort.Sort(catalogue.ByRecipeName(recipes)) | 		sort.Sort(catalogue.ByRecipeName(recipes)) | ||||||
|  |  | ||||||
| 		tableCol := []string{"Name", "Category", "Status"} | 		tableCol := []string{"name", "category", "status"} | ||||||
| 		table := formatter.CreateTable(tableCol) | 		table := formatter.CreateTable(tableCol) | ||||||
|  |  | ||||||
| 		for _, recipe := range recipes { | 		for _, recipe := range recipes { | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ import ( | |||||||
|  |  | ||||||
| 	"coopcloud.tech/abra/cli/internal" | 	"coopcloud.tech/abra/cli/internal" | ||||||
| 	"coopcloud.tech/abra/pkg/config" | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"github.com/go-git/go-git/v5" | 	"coopcloud.tech/abra/pkg/git" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| 	"github.com/urfave/cli/v2" | 	"github.com/urfave/cli/v2" | ||||||
| ) | ) | ||||||
| @ -28,10 +28,8 @@ var recipeNewCommand = &cli.Command{ | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		url := fmt.Sprintf("%s/example.git", config.REPOS_BASE_URL) | 		url := fmt.Sprintf("%s/example.git", config.REPOS_BASE_URL) | ||||||
| 		_, err := git.PlainClone(directory, false, &git.CloneOptions{URL: url, Tags: git.AllTags}) | 		if err := git.Clone(directory, url); err != nil { | ||||||
| 		if err != nil { | 			return err | ||||||
| 			logrus.Fatal(err) |  | ||||||
| 			return nil |  | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		gitRepo := path.Join(config.APPS_DIR, recipe.Name, ".git") | 		gitRepo := path.Join(config.APPS_DIR, recipe.Name, ".git") | ||||||
| @ -39,6 +37,7 @@ var recipeNewCommand = &cli.Command{ | |||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 			return nil | 			return nil | ||||||
| 		} | 		} | ||||||
|  | 		logrus.Debugf("removed git repo in '%s'", gitRepo) | ||||||
|  |  | ||||||
| 		toParse := []string{ | 		toParse := []string{ | ||||||
| 			path.Join(config.APPS_DIR, recipe.Name, "README.md"), | 			path.Join(config.APPS_DIR, recipe.Name, "README.md"), | ||||||
| @ -71,7 +70,7 @@ var recipeNewCommand = &cli.Command{ | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		logrus.Infof( | 		logrus.Infof( | ||||||
| 			"New recipe '%s' created in %s, happy hacking!\n", | 			"new recipe '%s' created in %s, happy hacking!\n", | ||||||
| 			recipe.Name, path.Join(config.APPS_DIR, recipe.Name), | 			recipe.Name, path.Join(config.APPS_DIR, recipe.Name), | ||||||
| 		) | 		) | ||||||
|  |  | ||||||
|  | |||||||
| @ -36,7 +36,7 @@ the versioning metadata of up-and-running containers are. | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if !hasAppService { | 		if !hasAppService { | ||||||
| 			logrus.Fatal(fmt.Sprintf("No 'app' service defined in '%s', cannot proceed", recipe.Name)) | 			logrus.Fatal(fmt.Sprintf("no 'app' service defined in '%s'", recipe.Name)) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		for _, service := range recipe.Config.Services { | 		for _, service := range recipe.Config.Services { | ||||||
| @ -44,17 +44,20 @@ the versioning metadata of up-and-running containers are. | |||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				logrus.Fatal(err) | 				logrus.Fatal(err) | ||||||
| 			} | 			} | ||||||
|  | 			logrus.Debugf("detected image '%s' for service '%s'", img, service.Name) | ||||||
|  |  | ||||||
| 			digest, err := client.GetTagDigest(img) | 			digest, err := client.GetTagDigest(img) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				logrus.Fatal(err) | 				logrus.Fatal(err) | ||||||
| 			} | 			} | ||||||
|  | 			logrus.Debugf("retrieved digest '%s' for '%s'", digest, img) | ||||||
|  |  | ||||||
| 			tag := img.(reference.NamedTagged).Tag() | 			tag := img.(reference.NamedTagged).Tag() | ||||||
| 			label := fmt.Sprintf("coop-cloud.${STACK_NAME}.%s.version=%s-%s", service.Name, tag, digest) | 			label := fmt.Sprintf("coop-cloud.${STACK_NAME}.%s.version=%s-%s", service.Name, tag, digest) | ||||||
| 			if err := recipe.UpdateLabel(service.Name, label); err != nil { | 			if err := recipe.UpdateLabel(service.Name, label); err != nil { | ||||||
| 				logrus.Fatal(err) | 				logrus.Fatal(err) | ||||||
| 			} | 			} | ||||||
|  | 			logrus.Debugf("added label '%s' to service '%s'", label, service.Name) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
|  | |||||||
| @ -40,6 +40,7 @@ This is step 1 of upgrading a recipe. Step 2 is running "abra recipe sync | |||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				logrus.Fatal(err) | 				logrus.Fatal(err) | ||||||
| 			} | 			} | ||||||
|  | 			logrus.Debugf("read '%s' from the recipe catalogue for '%s'", catlVersions, service.Name) | ||||||
|  |  | ||||||
| 			img, err := reference.ParseNormalizedNamed(service.Image) | 			img, err := reference.ParseNormalizedNamed(service.Image) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| @ -51,6 +52,7 @@ This is step 1 of upgrading a recipe. Step 2 is running "abra recipe sync | |||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				logrus.Fatal(err) | 				logrus.Fatal(err) | ||||||
| 			} | 			} | ||||||
|  | 			logrus.Debugf("retrieved '%s' from remote registry for '%s'", regVersions, image) | ||||||
|  |  | ||||||
| 			if strings.Contains(image, "library") { | 			if strings.Contains(image, "library") { | ||||||
| 				// ParseNormalizedNamed prepends 'library' to images like nginx:<tag>, | 				// ParseNormalizedNamed prepends 'library' to images like nginx:<tag>, | ||||||
| @ -61,6 +63,7 @@ This is step 1 of upgrading a recipe. Step 2 is running "abra recipe sync | |||||||
|  |  | ||||||
| 			semverLikeTag := true | 			semverLikeTag := true | ||||||
| 			if !tagcmp.IsParsable(img.(reference.NamedTagged).Tag()) { | 			if !tagcmp.IsParsable(img.(reference.NamedTagged).Tag()) { | ||||||
|  | 				logrus.Debugf("'%s' not considered semver-like", img.(reference.NamedTagged).Tag()) | ||||||
| 				semverLikeTag = false | 				semverLikeTag = false | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| @ -68,6 +71,7 @@ This is step 1 of upgrading a recipe. Step 2 is running "abra recipe sync | |||||||
| 			if err != nil && semverLikeTag { | 			if err != nil && semverLikeTag { | ||||||
| 				logrus.Fatal(err) | 				logrus.Fatal(err) | ||||||
| 			} | 			} | ||||||
|  | 			logrus.Debugf("parsed '%s' for '%s'", tag, service.Name) | ||||||
|  |  | ||||||
| 			var compatible []tagcmp.Tag | 			var compatible []tagcmp.Tag | ||||||
| 			for _, regVersion := range regVersions { | 			for _, regVersion := range regVersions { | ||||||
| @ -81,10 +85,12 @@ This is step 1 of upgrading a recipe. Step 2 is running "abra recipe sync | |||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | 			logrus.Debugf("detected potential upgradable tags '%s' for '%s'", compatible, service.Name) | ||||||
|  |  | ||||||
| 			sort.Sort(tagcmp.ByTagDesc(compatible)) | 			sort.Sort(tagcmp.ByTagDesc(compatible)) | ||||||
|  |  | ||||||
| 			if len(compatible) == 0 && semverLikeTag { | 			if len(compatible) == 0 && semverLikeTag { | ||||||
| 				logrus.Info(fmt.Sprintf("No new versions available for '%s', '%s' is the latest", image, tag)) | 				logrus.Info(fmt.Sprintf("no new versions available for '%s', '%s' is the latest", image, tag)) | ||||||
| 				continue // skip on to the next tag and don't update any compose files | 				continue // skip on to the next tag and don't update any compose files | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| @ -101,11 +107,13 @@ This is step 1 of upgrading a recipe. Step 2 is running "abra recipe sync | |||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			msg := fmt.Sprintf("Which tag would you like to upgrade to? (service: %s, tag: %s)", service.Name, tag) | 			logrus.Debugf("detected compatible upgradable tags '%s' for '%s'", compatibleStrings, service.Name) | ||||||
|  |  | ||||||
|  | 			msg := fmt.Sprintf("upgrade to which tag? (service: %s, tag: %s)", service.Name, tag) | ||||||
| 			if !tagcmp.IsParsable(img.(reference.NamedTagged).Tag()) { | 			if !tagcmp.IsParsable(img.(reference.NamedTagged).Tag()) { | ||||||
| 				tag := img.(reference.NamedTagged).Tag() | 				tag := img.(reference.NamedTagged).Tag() | ||||||
| 				logrus.Warning(fmt.Sprintf("Unable to determine versioning semantics of '%s', listing all tags...", tag)) | 				logrus.Warning(fmt.Sprintf("unable to determine versioning semantics of '%s', listing all tags", tag)) | ||||||
| 				msg = fmt.Sprintf("Which tag would you like to upgrade to? (service: %s, tag: %s)", service.Name, tag) | 				msg = fmt.Sprintf("upgrade to which tag? (service: %s, tag: %s)", service.Name, tag) | ||||||
| 				compatibleStrings = []string{} | 				compatibleStrings = []string{} | ||||||
| 				for _, regVersion := range regVersions { | 				for _, regVersion := range regVersions { | ||||||
| 					compatibleStrings = append(compatibleStrings, regVersion.Name) | 					compatibleStrings = append(compatibleStrings, regVersion.Name) | ||||||
| @ -124,6 +132,7 @@ This is step 1 of upgrading a recipe. Step 2 is running "abra recipe sync | |||||||
| 			if err := recipe.UpdateTag(image, upgradeTag); err != nil { | 			if err := recipe.UpdateTag(image, upgradeTag); err != nil { | ||||||
| 				logrus.Fatal(err) | 				logrus.Fatal(err) | ||||||
| 			} | 			} | ||||||
|  | 			logrus.Debugf("tag updated from '%s' to '%s' for '%s'", image, upgradeTag, recipe.Name) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
|  | |||||||
| @ -26,13 +26,13 @@ var recipeVersionCommand = &cli.Command{ | |||||||
| 			logrus.Fatalf("'%s' recipe doesn't exist?", recipe.Name) | 			logrus.Fatalf("'%s' recipe doesn't exist?", recipe.Name) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		tableCol := []string{"Version", "Service", "Image", "Digest"} | 		tableCol := []string{"Version", "Service", "Image", "Tag", "Digest"} | ||||||
| 		table := formatter.CreateTable(tableCol) | 		table := formatter.CreateTable(tableCol) | ||||||
|  |  | ||||||
| 		for _, serviceVersion := range recipeMeta.Versions { | 		for _, serviceVersion := range recipeMeta.Versions { | ||||||
| 			for tag, meta := range serviceVersion { | 			for tag, meta := range serviceVersion { | ||||||
| 				for service, serviceMeta := range meta { | 				for service, serviceMeta := range meta { | ||||||
| 					table.Append([]string{tag, service, serviceMeta.Image, serviceMeta.Digest}) | 					table.Append([]string{tag, service, serviceMeta.Image, serviceMeta.Tag, serviceMeta.Digest}) | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -1,8 +1,10 @@ | |||||||
| package server | package server | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"context" | ||||||
|  | 	"os/user" | ||||||
|  |  | ||||||
|  | 	"coopcloud.tech/abra/cli/internal" | ||||||
| 	"coopcloud.tech/abra/pkg/client" | 	"coopcloud.tech/abra/pkg/client" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| 	"github.com/urfave/cli/v2" | 	"github.com/urfave/cli/v2" | ||||||
| @ -10,20 +12,80 @@ import ( | |||||||
|  |  | ||||||
| var serverAddCommand = &cli.Command{ | var serverAddCommand = &cli.Command{ | ||||||
| 	Name:  "add", | 	Name:  "add", | ||||||
| 	Usage:       "Add a new server, reachable on <server>.", | 	Usage: "Add a new server", | ||||||
|  | 	Description: ` | ||||||
|  | This command adds a new server that abra will communicate with, to deploy apps. | ||||||
|  |  | ||||||
|  | The <domain> argument must be a publicy accessible domain name which points to | ||||||
|  | your server. You should have SSH access to this server, Abra will assume port | ||||||
|  | 22 and will use your current system username to make an initial connection. You | ||||||
|  | can use the <user> and <port> arguments to adjust this. | ||||||
|  |  | ||||||
|  | For example: | ||||||
|  |  | ||||||
|  |     abra server add varia.zone 12345 glodemodem | ||||||
|  |  | ||||||
|  | Abra will construct the following SSH connection string then: | ||||||
|  |  | ||||||
|  |     ssh://globemodem@varia.zone:12345 | ||||||
|  |  | ||||||
|  | All communication between Abra and the server will use this SSH connection. | ||||||
|  |  | ||||||
|  | `, | ||||||
| 	Aliases:   []string{"a"}, | 	Aliases:   []string{"a"}, | ||||||
| 	ArgsUsage:   "<server> [<user>] [<port>]", | 	ArgsUsage: "<domain> [<user>] [<port>]", | ||||||
| 	Description: "[<user>], [<port>]    SSH connection details", |  | ||||||
| 	Action: func(c *cli.Context) error { | 	Action: func(c *cli.Context) error { | ||||||
| 		argLen := c.Args().Len() | 		domainName := internal.ValidateDomain(c) | ||||||
| 		args := c.Args().Slice() |  | ||||||
| 		if argLen < 3 { | 		var username string | ||||||
| 			args = append(args, make([]string, 3-argLen)...) | 		var port string | ||||||
| 		} |  | ||||||
| 		if err := client.CreateContext(args[0], args[1], args[2]); err != nil { | 		username = c.Args().Get(1) | ||||||
|  | 		if username == "" { | ||||||
|  | 			systemUser, err := user.Current() | ||||||
|  | 			if err != nil { | ||||||
| 				logrus.Fatal(err) | 				logrus.Fatal(err) | ||||||
| 			} | 			} | ||||||
| 		fmt.Println(args[0]) | 			username = systemUser.Username | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		port = c.Args().Get(2) | ||||||
|  | 		if port == "" { | ||||||
|  | 			port = "22" | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		store := client.NewDefaultDockerContextStore() | ||||||
|  | 		contexts, err := store.Store.List() | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Fatal(err) | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		for _, context := range contexts { | ||||||
|  | 			if context.Name == domainName { | ||||||
|  | 				logrus.Fatalf("server at '%s' already exists?", domainName) | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		logrus.Debugf("creating context with domain '%s', username '%s' and port '%s'", domainName, username, port) | ||||||
|  |  | ||||||
|  | 		if err := client.CreateContext(domainName, username, port); err != nil { | ||||||
|  | 			logrus.Fatal(err) | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		ctx := context.Background() | ||||||
|  | 		cl, err := client.New(domainName) | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Fatal(err) | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		if _, err := cl.Info(ctx); err != nil { | ||||||
|  | 			logrus.Fatalf("unable to make a connection to '%s'?", domainName) | ||||||
|  | 			logrus.Debug(err) | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		logrus.Debugf("remote connection to '%s' is definitely up", domainName) | ||||||
|  | 		logrus.Infof("server at '%s' has been added", domainName) | ||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -2,7 +2,6 @@ package server | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"errors" |  | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"net" | 	"net" | ||||||
| 	"time" | 	"time" | ||||||
| @ -20,21 +19,18 @@ var serverInitCommand = &cli.Command{ | |||||||
| 	Usage:     "Initialise server for deploying apps", | 	Usage:     "Initialise server for deploying apps", | ||||||
| 	Aliases:   []string{"i"}, | 	Aliases:   []string{"i"}, | ||||||
| 	HideHelp:  true, | 	HideHelp:  true, | ||||||
| 	ArgsUsage: "<server>", | 	ArgsUsage: "<domain>", | ||||||
| 	Description: ` | 	Description: ` | ||||||
| Initialise swarm mode on the target <server>. | Initialise swarm mode on the target <domain>. | ||||||
|  |  | ||||||
| This initialisation explicitly chooses the "single host swarm" mode which uses | This initialisation explicitly chooses the "single host swarm" mode which uses | ||||||
| the default IPv4 address as the advertising address. This can be re-configured | the default IPv4 address as the advertising address. This can be re-configured | ||||||
| later for more advanced use cases. | later for more advanced use cases. | ||||||
| `, | `, | ||||||
| 	Action: func(c *cli.Context) error { | 	Action: func(c *cli.Context) error { | ||||||
| 		server := c.Args().First() | 		domainName := internal.ValidateDomain(c) | ||||||
| 		if server == "" { |  | ||||||
| 			internal.ShowSubcommandHelpAndError(c, errors.New("no server provided")) |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		cl, err := client.New(server) | 		cl, err := client.New(domainName) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| @ -49,15 +45,16 @@ later for more advanced use cases. | |||||||
| 				return d.DialContext(ctx, "udp", "95.216.24.230:53") | 				return d.DialContext(ctx, "udp", "95.216.24.230:53") | ||||||
| 			}, | 			}, | ||||||
| 		} | 		} | ||||||
|  | 		logrus.Debugf("created DNS resolver via 95.216.24.230") | ||||||
|  |  | ||||||
| 		ctx := context.Background() | 		ctx := context.Background() | ||||||
| 		ips, err := resolver.LookupIPAddr(ctx, server) | 		ips, err := resolver.LookupIPAddr(ctx, domainName) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if len(ips) == 0 { | 		if len(ips) == 0 { | ||||||
| 			return fmt.Errorf("unable to retrieve ipv4 address for %s", server) | 			return fmt.Errorf("unable to retrieve ipv4 address for %s", domainName) | ||||||
| 		} | 		} | ||||||
| 		ipv4 := ips[0].IP.To4().String() | 		ipv4 := ips[0].IP.To4().String() | ||||||
|  |  | ||||||
| @ -68,11 +65,13 @@ later for more advanced use cases. | |||||||
| 		if _, err := cl.SwarmInit(ctx, initReq); err != nil { | 		if _, err := cl.SwarmInit(ctx, initReq); err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
|  | 		logrus.Debugf("initialised swarm on '%s'", domainName) | ||||||
|  |  | ||||||
| 		netOpts := types.NetworkCreate{Driver: "overlay", Scope: "swarm"} | 		netOpts := types.NetworkCreate{Driver: "overlay", Scope: "swarm"} | ||||||
| 		if _, err := cl.NetworkCreate(ctx, "proxy", netOpts); err != nil { | 		if _, err := cl.NetworkCreate(ctx, "proxy", netOpts); err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
|  | 		logrus.Debug("swarm overlay network 'proxy' created") | ||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
|  | |||||||
| @ -13,7 +13,7 @@ import ( | |||||||
| var serverListCommand = &cli.Command{ | var serverListCommand = &cli.Command{ | ||||||
| 	Name:      "list", | 	Name:      "list", | ||||||
| 	Aliases:   []string{"ls"}, | 	Aliases:   []string{"ls"}, | ||||||
| 	Usage:     "List locally-defined servers.", | 	Usage:     "List managed servers", | ||||||
| 	ArgsUsage: " ", | 	ArgsUsage: " ", | ||||||
| 	HideHelp:  true, | 	HideHelp:  true, | ||||||
| 	Action: func(c *cli.Context) error { | 	Action: func(c *cli.Context) error { | ||||||
| @ -22,6 +22,7 @@ var serverListCommand = &cli.Command{ | |||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		tableColumns := []string{"Name", "Connection"} | 		tableColumns := []string{"Name", "Connection"} | ||||||
| 		table := formatter.CreateTable(tableColumns) | 		table := formatter.CreateTable(tableColumns) | ||||||
| 		defer table.Render() | 		defer table.Render() | ||||||
| @ -30,8 +31,8 @@ var serverListCommand = &cli.Command{ | |||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
| 		for _, serverName := range serverNames { |  | ||||||
|  |  | ||||||
|  | 		for _, serverName := range serverNames { | ||||||
| 			var row []string | 			var row []string | ||||||
| 			for _, ctx := range contexts { | 			for _, ctx := range contexts { | ||||||
| 				endpoint, err := client.GetContextEndpoint(ctx) | 				endpoint, err := client.GetContextEndpoint(ctx) | ||||||
| @ -47,9 +48,8 @@ var serverListCommand = &cli.Command{ | |||||||
| 				row = []string{serverName, "UNKNOWN"} | 				row = []string{serverName, "UNKNOWN"} | ||||||
| 			} | 			} | ||||||
| 			table.Append(row) | 			table.Append(row) | ||||||
|  |  | ||||||
| 		} | 		} | ||||||
| 		return nil |  | ||||||
|  |  | ||||||
|  | 		return nil | ||||||
| 	}, | 	}, | ||||||
| } | } | ||||||
|  | |||||||
| @ -79,12 +79,14 @@ environment variable or otherwise passing the "--env/-e" flag. | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if hetznerCloudAPIToken == "" { | 		if hetznerCloudAPIToken == "" { | ||||||
| 			logrus.Fatal("Hetzner Cloud API token is missing, cannot continue") | 			logrus.Fatal("Hetzner Cloud API token is missing") | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		ctx := context.Background() | 		ctx := context.Background() | ||||||
| 		client := hcloud.NewClient(hcloud.WithToken(hetznerCloudAPIToken)) | 		client := hcloud.NewClient(hcloud.WithToken(hetznerCloudAPIToken)) | ||||||
|  |  | ||||||
|  | 		logrus.Debugf("successfully created hetzner cloud API client") | ||||||
|  |  | ||||||
| 		var sshKeys []*hcloud.SSHKey | 		var sshKeys []*hcloud.SSHKey | ||||||
| 		for _, sshKey := range c.StringSlice("ssh-keys") { | 		for _, sshKey := range c.StringSlice("ssh-keys") { | ||||||
| 			sshKey, _, err := client.SSHKey.GetByName(ctx, sshKey) | 			sshKey, _, err := client.SSHKey.GetByName(ctx, sshKey) | ||||||
| @ -106,13 +108,17 @@ environment variable or otherwise passing the "--env/-e" flag. | |||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		logrus.Debugf("new server '%s' created", name) | ||||||
|  |  | ||||||
| 		tableColumns := []string{"Name", "IPv4", "Root Password"} | 		tableColumns := []string{"Name", "IPv4", "Root Password"} | ||||||
| 		table := formatter.CreateTable(tableColumns) | 		table := formatter.CreateTable(tableColumns) | ||||||
|  |  | ||||||
| 		if len(sshKeys) > 0 { | 		if len(sshKeys) > 0 { | ||||||
| 			table.Append([]string{name, res.Server.PublicNet.IPv4.IP.String(), "N/A (using SSH keys)"}) | 			table.Append([]string{name, res.Server.PublicNet.IPv4.IP.String(), "N/A (using SSH keys)"}) | ||||||
| 		} else { | 		} else { | ||||||
| 			table.Append([]string{name, res.Server.PublicNet.IPv4.IP.String(), res.RootPassword}) | 			table.Append([]string{name, res.Server.PublicNet.IPv4.IP.String(), res.RootPassword}) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		table.Render() | 		table.Render() | ||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| @ -182,13 +188,14 @@ environment variable or otherwise passing the "--env/-e" flag. | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if capsulAPIToken == "" { | 		if capsulAPIToken == "" { | ||||||
| 			logrus.Fatal("Capsul API token is missing, cannot continue") | 			logrus.Fatal("Capsul API token is missing") | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		// yep, the response time is quite slow, something to fix Capsul side | 		// yep, the response time is quite slow, something to fix on the Capsul side | ||||||
| 		client := &http.Client{Timeout: 20 * time.Second} | 		client := &http.Client{Timeout: 20 * time.Second} | ||||||
|  |  | ||||||
| 		capsulCreateURL := fmt.Sprintf("https://%s/api/capsul/create", capsulInstance) | 		capsulCreateURL := fmt.Sprintf("https://%s/api/capsul/create", capsulInstance) | ||||||
|  | 		logrus.Debugf("using '%s' as capsul create url", capsulCreateURL) | ||||||
| 		values := map[string]string{ | 		values := map[string]string{ | ||||||
| 			"name":      name, | 			"name":      name, | ||||||
| 			"size":      capsulType, | 			"size":      capsulType, | ||||||
| @ -230,6 +237,7 @@ environment variable or otherwise passing the "--env/-e" flag. | |||||||
| 		if err := json.NewDecoder(res.Body).Decode(&resp); err != nil { | 		if err := json.NewDecoder(res.Body).Decode(&resp); err != nil { | ||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  | 		logrus.Debugf("capsul created with ID: '%s'", resp.ID) | ||||||
|  |  | ||||||
| 		tableColumns := []string{"Name", "ID"} | 		tableColumns := []string{"Name", "ID"} | ||||||
| 		table := formatter.CreateTable(tableColumns) | 		table := formatter.CreateTable(tableColumns) | ||||||
| @ -242,8 +250,12 @@ environment variable or otherwise passing the "--env/-e" flag. | |||||||
|  |  | ||||||
| var serverNewCommand = &cli.Command{ | var serverNewCommand = &cli.Command{ | ||||||
| 	Name:    "new", | 	Name:    "new", | ||||||
|  | 	Aliases: []string{"n"}, | ||||||
| 	Usage:   "Create a new server using a 3rd party provider", | 	Usage:   "Create a new server using a 3rd party provider", | ||||||
| 	Description: "Use a provider plugin to create a new server which can then be used to house a new Co-op Cloud installation.", | 	Description: ` | ||||||
|  | Use a provider plugin to create a new server which can then be used to house a | ||||||
|  | new Co-op Cloud installation. | ||||||
|  | `, | ||||||
| 	ArgsUsage: "<provider>", | 	ArgsUsage: "<provider>", | ||||||
| 	Subcommands: []*cli.Command{ | 	Subcommands: []*cli.Command{ | ||||||
| 		serverNewHetznerCloudCommand, | 		serverNewHetznerCloudCommand, | ||||||
|  | |||||||
| @ -1,8 +1,6 @@ | |||||||
| package server | package server | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"errors" |  | ||||||
|  |  | ||||||
| 	"coopcloud.tech/abra/cli/internal" | 	"coopcloud.tech/abra/cli/internal" | ||||||
| 	"coopcloud.tech/abra/pkg/client" | 	"coopcloud.tech/abra/pkg/client" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| @ -19,13 +17,14 @@ internal bookkeeping so that it is not managed any more. | |||||||
| `, | `, | ||||||
| 	HideHelp: true, | 	HideHelp: true, | ||||||
| 	Action: func(c *cli.Context) error { | 	Action: func(c *cli.Context) error { | ||||||
| 		server := c.Args().First() | 		domainName := internal.ValidateDomain(c) | ||||||
| 		if server == "" { |  | ||||||
| 			internal.ShowSubcommandHelpAndError(c, errors.New("no server provided")) | 		if err := client.DeleteContext(domainName); err != nil { | ||||||
| 		} |  | ||||||
| 		if err := client.DeleteContext(server); err != nil { |  | ||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		logrus.Infof("server at '%s' has been forgotten", domainName) | ||||||
|  |  | ||||||
| 		return nil | 		return nil | ||||||
| 	}, | 	}, | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										23
									
								
								cli/upgrade.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								cli/upgrade.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,23 @@ | |||||||
|  | package cli | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"os/exec" | ||||||
|  |  | ||||||
|  | 	"coopcloud.tech/abra/cli/internal" | ||||||
|  | 	"github.com/sirupsen/logrus" | ||||||
|  | 	"github.com/urfave/cli/v2" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | // UpgradeCommand upgrades abra in-place. | ||||||
|  | var UpgradeCommand = &cli.Command{ | ||||||
|  | 	Name:  "upgrade", | ||||||
|  | 	Usage: "Upgrade abra", | ||||||
|  | 	Action: func(c *cli.Context) error { | ||||||
|  | 		cmd := exec.Command("bash", "-c", "curl -s https://install.abra.coopcloud.tech | bash") | ||||||
|  | 		logrus.Debugf("attempting to run '%s'", cmd) | ||||||
|  | 		if err := internal.RunCmd(cmd); err != nil { | ||||||
|  | 			logrus.Fatal(err) | ||||||
|  | 		} | ||||||
|  | 		return nil | ||||||
|  | 	}, | ||||||
|  | } | ||||||
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							| @ -5,7 +5,7 @@ go 1.17 | |||||||
| require ( | require ( | ||||||
| 	coopcloud.tech/tagcmp v0.0.0-20210906102006-2a8edd82d75d | 	coopcloud.tech/tagcmp v0.0.0-20210906102006-2a8edd82d75d | ||||||
| 	github.com/AlecAivazis/survey/v2 v2.3.1 | 	github.com/AlecAivazis/survey/v2 v2.3.1 | ||||||
| 	github.com/Autonomic-Cooperative/godotenv v1.3.1 | 	github.com/Autonomic-Cooperative/godotenv v1.3.1-0.20210731170023-c37c0920d1a4 | ||||||
| 	github.com/docker/cli v20.10.8+incompatible | 	github.com/docker/cli v20.10.8+incompatible | ||||||
| 	github.com/docker/distribution v2.7.1+incompatible | 	github.com/docker/distribution v2.7.1+incompatible | ||||||
| 	github.com/docker/docker v20.10.8+incompatible | 	github.com/docker/docker v20.10.8+incompatible | ||||||
|  | |||||||
							
								
								
									
										4
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								go.sum
									
									
									
									
									
								
							| @ -26,8 +26,8 @@ coopcloud.tech/tagcmp v0.0.0-20210906102006-2a8edd82d75d/go.mod h1:ESVm0wQKcbcFi | |||||||
| dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= | dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= | ||||||
| github.com/AlecAivazis/survey/v2 v2.3.1 h1:lzkuHA60pER7L4eYL8qQJor4bUWlJe4V0gqAT19tdOA= | github.com/AlecAivazis/survey/v2 v2.3.1 h1:lzkuHA60pER7L4eYL8qQJor4bUWlJe4V0gqAT19tdOA= | ||||||
| github.com/AlecAivazis/survey/v2 v2.3.1/go.mod h1:TH2kPCDU3Kqq7pLbnCWwZXDBjnhZtmsCle5EiYDJ2fg= | github.com/AlecAivazis/survey/v2 v2.3.1/go.mod h1:TH2kPCDU3Kqq7pLbnCWwZXDBjnhZtmsCle5EiYDJ2fg= | ||||||
| github.com/Autonomic-Cooperative/godotenv v1.3.1 h1:LxRTdqBgXyBu7sM1kY8RXuYYA8OFmeLKowLGOAT0Yw0= | github.com/Autonomic-Cooperative/godotenv v1.3.1-0.20210731170023-c37c0920d1a4 h1:aYUdiI42a4fWfPoUr25XlaJrFEICv24+o/gWhqYS/jk= | ||||||
| github.com/Autonomic-Cooperative/godotenv v1.3.1/go.mod h1:oZRCMMRS318l07ei4DTqbZoOawfJlJ4yyo8juk2v4Rk= | github.com/Autonomic-Cooperative/godotenv v1.3.1-0.20210731170023-c37c0920d1a4/go.mod h1:oZRCMMRS318l07ei4DTqbZoOawfJlJ4yyo8juk2v4Rk= | ||||||
| github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= | github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= | ||||||
| github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= | github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= | ||||||
| github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= | github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= | ||||||
|  | |||||||
| @ -1,7 +1,14 @@ | |||||||
| package app | package app | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
|  | 	"context" | ||||||
|  | 	"fmt" | ||||||
|  | 	"strings" | ||||||
|  |  | ||||||
|  | 	"coopcloud.tech/abra/pkg/client/stack" | ||||||
| 	"coopcloud.tech/abra/pkg/config" | 	"coopcloud.tech/abra/pkg/config" | ||||||
|  | 	apiclient "github.com/docker/docker/client" | ||||||
|  | 	"github.com/sirupsen/logrus" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // Get retrieves an app | // Get retrieves an app | ||||||
| @ -16,5 +23,63 @@ func Get(appName string) (config.App, error) { | |||||||
| 		return config.App{}, err | 		return config.App{}, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("retrieved '%s' for '%s'", app, appName) | ||||||
|  |  | ||||||
| 	return app, nil | 	return app, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // deployedServiceSpec represents a deployed service of an app. | ||||||
|  | type deployedServiceSpec struct { | ||||||
|  | 	Name    string | ||||||
|  | 	Version string | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // VersionSpec represents a deployed app and associated metadata. | ||||||
|  | type VersionSpec map[string]deployedServiceSpec | ||||||
|  |  | ||||||
|  | // DeployedVersions lists metadata (e.g. versions) for deployed | ||||||
|  | func DeployedVersions(ctx context.Context, cl *apiclient.Client, app config.App) (VersionSpec, bool, error) { | ||||||
|  | 	services, err := stack.GetStackServices(ctx, cl, app.StackName()) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return VersionSpec{}, false, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	appSpec := make(VersionSpec) | ||||||
|  | 	for _, service := range services { | ||||||
|  | 		serviceName := ParseServiceName(service.Spec.Name) | ||||||
|  | 		label := fmt.Sprintf("coop-cloud.%s.%s.version", app.StackName(), serviceName) | ||||||
|  | 		if deployLabel, ok := service.Spec.Labels[label]; ok { | ||||||
|  | 			version, _ := ParseVersionLabel(deployLabel) | ||||||
|  | 			appSpec[serviceName] = deployedServiceSpec{Name: serviceName, Version: version} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	deployed := len(services) > 0 | ||||||
|  |  | ||||||
|  | 	if deployed { | ||||||
|  | 		logrus.Debugf("detected '%s' as deployed versions of '%s'", appSpec, app.Name) | ||||||
|  | 	} else { | ||||||
|  | 		logrus.Debugf("detected '%s' as not deployed", app.Name) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return appSpec, len(services) > 0, nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // ParseVersionLabel parses a $VERSION-$DIGEST app service label. | ||||||
|  | func ParseVersionLabel(label string) (string, string) { | ||||||
|  | 	// versions may look like v4.2-abcd or v4.2-alpine-abcd | ||||||
|  | 	idx := strings.LastIndex(label, "-") | ||||||
|  | 	version := label[:idx] | ||||||
|  | 	digest := label[idx+1:] | ||||||
|  | 	logrus.Debugf("parsed '%s' as version from '%s'", version, label) | ||||||
|  | 	logrus.Debugf("parsed '%s' as digest from '%s'", digest, label) | ||||||
|  | 	return version, digest | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // ParseVersionName parses a $STACK_NAME_$SERVICE_NAME service label. | ||||||
|  | func ParseServiceName(label string) string { | ||||||
|  | 	idx := strings.LastIndex(label, "_") | ||||||
|  | 	serviceName := label[idx+1:] | ||||||
|  | 	logrus.Debugf("parsed '%s' as service name from '%s'", serviceName, label) | ||||||
|  | 	return serviceName | ||||||
|  | } | ||||||
|  | |||||||
| @ -13,7 +13,9 @@ import ( | |||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
| 	"coopcloud.tech/abra/pkg/config" | 	"coopcloud.tech/abra/pkg/config" | ||||||
|  | 	"coopcloud.tech/abra/pkg/recipe" | ||||||
| 	"coopcloud.tech/abra/pkg/web" | 	"coopcloud.tech/abra/pkg/web" | ||||||
|  | 	"github.com/sirupsen/logrus" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // RecipeCatalogueURL is the only current recipe catalogue available. | // RecipeCatalogueURL is the only current recipe catalogue available. | ||||||
| @ -75,6 +77,8 @@ func (r RecipeMeta) LatestVersion() string { | |||||||
| 		version = tag | 		version = tag | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("choosing '%s' as latest version of '%s'", version, r.Name) | ||||||
|  |  | ||||||
| 	return version | 	return version | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -87,9 +91,11 @@ type RecipeCatalogue map[Name]RecipeMeta | |||||||
| // Flatten converts AppCatalogue to slice | // Flatten converts AppCatalogue to slice | ||||||
| func (r RecipeCatalogue) Flatten() []RecipeMeta { | func (r RecipeCatalogue) Flatten() []RecipeMeta { | ||||||
| 	recipes := make([]RecipeMeta, 0, len(r)) | 	recipes := make([]RecipeMeta, 0, len(r)) | ||||||
|  |  | ||||||
| 	for name := range r { | 	for name := range r { | ||||||
| 		recipes = append(recipes, r[name]) | 		recipes = append(recipes, r[name]) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return recipes | 	return recipes | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -116,9 +122,11 @@ func recipeCatalogueFSIsLatest() (bool, error) { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return false, err | 		return false, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	info, err := os.Stat(config.APPS_JSON) | 	info, err := os.Stat(config.APPS_JSON) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		if os.IsNotExist(err) { | 		if os.IsNotExist(err) { | ||||||
|  | 			logrus.Debugf("no recipe catalogue found in file system cache") | ||||||
| 			return false, nil | 			return false, nil | ||||||
| 		} | 		} | ||||||
| 		return false, err | 		return false, err | ||||||
| @ -128,9 +136,12 @@ func recipeCatalogueFSIsLatest() (bool, error) { | |||||||
| 	remoteModifiedTime := parsed.Unix() | 	remoteModifiedTime := parsed.Unix() | ||||||
|  |  | ||||||
| 	if localModifiedTime < remoteModifiedTime { | 	if localModifiedTime < remoteModifiedTime { | ||||||
|  | 		logrus.Debug("file system cached recipe catalogue is out-of-date") | ||||||
| 		return false, nil | 		return false, nil | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debug("file system cached recipe catalogue is up-to-date") | ||||||
|  |  | ||||||
| 	return true, nil | 	return true, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -144,12 +155,14 @@ func ReadRecipeCatalogue() (RecipeCatalogue, error) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if !recipeFSIsLatest { | 	if !recipeFSIsLatest { | ||||||
|  | 		logrus.Debugf("reading recipe catalogue from web to get latest") | ||||||
| 		if err := readRecipeCatalogueWeb(&recipes); err != nil { | 		if err := readRecipeCatalogueWeb(&recipes); err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| 		return recipes, nil | 		return recipes, nil | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("reading recipe catalogue from file system cache to get latest") | ||||||
| 	if err := readRecipeCatalogueFS(&recipes); err != nil { | 	if err := readRecipeCatalogueFS(&recipes); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| @ -163,9 +176,13 @@ func readRecipeCatalogueFS(target interface{}) error { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if err := json.Unmarshal(recipesJSONFS, &target); err != nil { | 	if err := json.Unmarshal(recipesJSONFS, &target); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("read recipe catalogue from file system cache in '%s'", config.APPS_JSON) | ||||||
|  |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -184,6 +201,8 @@ func readRecipeCatalogueWeb(target interface{}) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("read recipe catalogue from web at '%s'", RecipeCatalogueURL) | ||||||
|  |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -210,5 +229,29 @@ func VersionsOfService(recipe, serviceName string) ([]string, error) { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("detected versions '%s' for '%s'", strings.Join(versions, ", "), recipe) | ||||||
|  |  | ||||||
| 	return versions, nil | 	return versions, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // GetRecipeMeta retrieves the recipe metadata from the recipe catalogue. | ||||||
|  | func GetRecipeMeta(recipeName string) (RecipeMeta, error) { | ||||||
|  | 	catl, err := ReadRecipeCatalogue() | ||||||
|  | 	if err != nil { | ||||||
|  | 		return RecipeMeta{}, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	recipeMeta, ok := catl[recipeName] | ||||||
|  | 	if !ok { | ||||||
|  | 		err := fmt.Errorf("recipe '%s' does not exist?", recipeName) | ||||||
|  | 		return RecipeMeta{}, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if err := recipe.EnsureExists(recipeName); err != nil { | ||||||
|  | 		return RecipeMeta{}, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("recipe metadata retrieved for '%s'", recipeName) | ||||||
|  |  | ||||||
|  | 	return recipeMeta, nil | ||||||
|  | } | ||||||
|  | |||||||
| @ -48,5 +48,7 @@ func New(contextName string) (*client.Client, error) { | |||||||
| 		logrus.Fatalf("unable to create Docker client: %s", err) | 		logrus.Fatalf("unable to create Docker client: %s", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("created client for '%s'", contextName) | ||||||
|  |  | ||||||
| 	return cl, nil | 	return cl, nil | ||||||
| } | } | ||||||
|  | |||||||
| @ -10,6 +10,7 @@ import ( | |||||||
| 	"github.com/docker/cli/cli/context/docker" | 	"github.com/docker/cli/cli/context/docker" | ||||||
| 	contextStore "github.com/docker/cli/cli/context/store" | 	contextStore "github.com/docker/cli/cli/context/store" | ||||||
| 	"github.com/moby/term" | 	"github.com/moby/term" | ||||||
|  | 	"github.com/sirupsen/logrus" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type Context = contextStore.Metadata | type Context = contextStore.Metadata | ||||||
| @ -26,6 +27,7 @@ func CreateContext(contextName string, user string, port string) error { | |||||||
| 	if err := createContext(contextName, host); err != nil { | 	if err := createContext(contextName, host); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  | 	logrus.Debugf("created the '%s' context", contextName) | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -36,13 +38,16 @@ func createContext(name string, host string) error { | |||||||
| 		Endpoints: make(map[string]interface{}), | 		Endpoints: make(map[string]interface{}), | ||||||
| 		Name:      name, | 		Name:      name, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	contextTLSData := contextStore.ContextTLSData{ | 	contextTLSData := contextStore.ContextTLSData{ | ||||||
| 		Endpoints: make(map[string]contextStore.EndpointTLSData), | 		Endpoints: make(map[string]contextStore.EndpointTLSData), | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(host) | 	dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(host) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	contextMetadata.Endpoints[docker.DockerEndpoint] = dockerEP | 	contextMetadata.Endpoints[docker.DockerEndpoint] = dockerEP | ||||||
| 	if dockerTLS != nil { | 	if dockerTLS != nil { | ||||||
| 		contextTLSData.Endpoints[docker.DockerEndpoint] = *dockerTLS | 		contextTLSData.Endpoints[docker.DockerEndpoint] = *dockerTLS | ||||||
| @ -51,9 +56,11 @@ func createContext(name string, host string) error { | |||||||
| 	if err := s.CreateOrUpdate(contextMetadata); err != nil { | 	if err := s.CreateOrUpdate(contextMetadata); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if err := s.ResetTLSMaterial(name, &contextTLSData); err != nil { | 	if err := s.ResetTLSMaterial(name, &contextTLSData); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -61,6 +68,7 @@ func DeleteContext(name string) error { | |||||||
| 	if name == "default" { | 	if name == "default" { | ||||||
| 		return errors.New("context 'default' cannot be removed") | 		return errors.New("context 'default' cannot be removed") | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if _, err := GetContext(name); err != nil { | 	if _, err := GetContext(name); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @ -81,6 +89,7 @@ func GetContext(contextName string) (contextStore.Metadata, error) { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return contextStore.Metadata{}, err | 		return contextStore.Metadata{}, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return ctx, nil | 	return ctx, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | |||||||
| @ -18,7 +18,7 @@ import ( | |||||||
| func RunRemove(ctx context.Context, client *apiclient.Client, opts Remove) error { | func RunRemove(ctx context.Context, client *apiclient.Client, opts Remove) error { | ||||||
| 	var errs []string | 	var errs []string | ||||||
| 	for _, namespace := range opts.Namespaces { | 	for _, namespace := range opts.Namespaces { | ||||||
| 		services, err := getStackServices(ctx, client, namespace) | 		services, err := GetStackServices(ctx, client, namespace) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -47,7 +47,7 @@ func getAllStacksFilter() filters.Args { | |||||||
| 	return filter | 	return filter | ||||||
| } | } | ||||||
|  |  | ||||||
| func getStackServices(ctx context.Context, dockerclient client.APIClient, namespace string) ([]swarm.Service, error) { | func GetStackServices(ctx context.Context, dockerclient client.APIClient, namespace string) ([]swarm.Service, error) { | ||||||
| 	return dockerclient.ServiceList(ctx, types.ServiceListOptions{Filters: getStackServiceFilter(namespace)}) | 	return dockerclient.ServiceList(ctx, types.ServiceListOptions{Filters: getStackServiceFilter(namespace)}) | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -94,7 +94,7 @@ func GetAllDeployedServices(contextName string) StackStatus { | |||||||
|  |  | ||||||
| // pruneServices removes services that are no longer referenced in the source | // pruneServices removes services that are no longer referenced in the source | ||||||
| func pruneServices(ctx context.Context, cl *dockerclient.Client, namespace convert.Namespace, services map[string]struct{}) { | func pruneServices(ctx context.Context, cl *dockerclient.Client, namespace convert.Namespace, services map[string]struct{}) { | ||||||
| 	oldServices, err := getStackServices(ctx, cl, namespace.Name()) | 	oldServices, err := GetStackServices(ctx, cl, namespace.Name()) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logrus.Infof("Failed to list services: %s\n", err) | 		logrus.Infof("Failed to list services: %s\n", err) | ||||||
| 	} | 	} | ||||||
| @ -174,6 +174,7 @@ func deployCompose(ctx context.Context, cl *dockerclient.Client, opts Deploy, co | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return deployServices(ctx, cl, services, namespace, opts.SendRegistryAuth, opts.ResolveImage) | 	return deployServices(ctx, cl, services, namespace, opts.SendRegistryAuth, opts.ResolveImage) | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -290,7 +291,7 @@ func deployServices( | |||||||
| 	namespace convert.Namespace, | 	namespace convert.Namespace, | ||||||
| 	sendAuth bool, | 	sendAuth bool, | ||||||
| 	resolveImage string) error { | 	resolveImage string) error { | ||||||
| 	existingServices, err := getStackServices(ctx, cl, namespace.Name()) | 	existingServices, err := GetStackServices(ctx, cl, namespace.Name()) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -20,6 +20,8 @@ func UpdateTag(pattern, image, tag string) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("considering '%s' config(s) for tag update", strings.Join(composeFiles, ", ")) | ||||||
|  |  | ||||||
| 	for _, composeFile := range composeFiles { | 	for _, composeFile := range composeFiles { | ||||||
| 		opts := stack.Deploy{Composefiles: []string{composeFile}} | 		opts := stack.Deploy{Composefiles: []string{composeFile}} | ||||||
| 		emptyEnv := make(map[string]string) | 		emptyEnv := make(map[string]string) | ||||||
| @ -35,7 +37,7 @@ func UpdateTag(pattern, image, tag string) error { | |||||||
|  |  | ||||||
| 			img, _ := reference.ParseNormalizedNamed(service.Image) | 			img, _ := reference.ParseNormalizedNamed(service.Image) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				logrus.Fatal(err) | 				return err | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			composeImage := reference.Path(img) | 			composeImage := reference.Path(img) | ||||||
| @ -47,16 +49,20 @@ func UpdateTag(pattern, image, tag string) error { | |||||||
| 			} | 			} | ||||||
| 			composeTag := img.(reference.NamedTagged).Tag() | 			composeTag := img.(reference.NamedTagged).Tag() | ||||||
|  |  | ||||||
|  | 			logrus.Debugf("parsed '%s' from '%s'", composeTag, service.Image) | ||||||
|  |  | ||||||
| 			if image == composeImage { | 			if image == composeImage { | ||||||
| 				bytes, err := ioutil.ReadFile(composeFile) | 				bytes, err := ioutil.ReadFile(composeFile) | ||||||
| 				if err != nil { | 				if err != nil { | ||||||
| 					logrus.Fatal(err) | 					return err | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| 				old := fmt.Sprintf("%s:%s", composeImage, composeTag) | 				old := fmt.Sprintf("%s:%s", composeImage, composeTag) | ||||||
| 				new := fmt.Sprintf("%s:%s", composeImage, tag) | 				new := fmt.Sprintf("%s:%s", composeImage, tag) | ||||||
| 				replacedBytes := strings.Replace(string(bytes), old, new, -1) | 				replacedBytes := strings.Replace(string(bytes), old, new, -1) | ||||||
|  |  | ||||||
|  | 				logrus.Debugf("updating '%s' to '%s' in '%s'", old, new, compose.Filename) | ||||||
|  |  | ||||||
| 				if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0644); err != nil { | 				if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0644); err != nil { | ||||||
| 					return err | 					return err | ||||||
| 				} | 				} | ||||||
| @ -74,6 +80,8 @@ func UpdateLabel(pattern, serviceName, label string) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("considering '%s' config(s) for label update", strings.Join(composeFiles, ", ")) | ||||||
|  |  | ||||||
| 	for _, composeFile := range composeFiles { | 	for _, composeFile := range composeFiles { | ||||||
| 		opts := stack.Deploy{Composefiles: []string{composeFile}} | 		opts := stack.Deploy{Composefiles: []string{composeFile}} | ||||||
| 		emptyEnv := make(map[string]string) | 		emptyEnv := make(map[string]string) | ||||||
| @ -104,6 +112,9 @@ func UpdateLabel(pattern, serviceName, label string) error { | |||||||
|  |  | ||||||
| 				old := fmt.Sprintf("coop-cloud.${STACK_NAME}.%s.version=%s", service.Name, value) | 				old := fmt.Sprintf("coop-cloud.${STACK_NAME}.%s.version=%s", service.Name, value) | ||||||
| 				replacedBytes := strings.Replace(string(bytes), old, label, -1) | 				replacedBytes := strings.Replace(string(bytes), old, label, -1) | ||||||
|  |  | ||||||
|  | 				logrus.Debugf("updating '%s' to '%s' in '%s'", old, label, compose.Filename) | ||||||
|  |  | ||||||
| 				if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0644); err != nil { | 				if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0644); err != nil { | ||||||
| 					return err | 					return err | ||||||
| 				} | 				} | ||||||
|  | |||||||
| @ -13,6 +13,7 @@ import ( | |||||||
| 	loader "coopcloud.tech/abra/pkg/client/stack" | 	loader "coopcloud.tech/abra/pkg/client/stack" | ||||||
| 	stack "coopcloud.tech/abra/pkg/client/stack" | 	stack "coopcloud.tech/abra/pkg/client/stack" | ||||||
| 	composetypes "github.com/docker/cli/cli/compose/types" | 	composetypes "github.com/docker/cli/cli/compose/types" | ||||||
|  | 	"github.com/sirupsen/logrus" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // Type aliases to make code hints easier to understand | // Type aliases to make code hints easier to understand | ||||||
| @ -93,10 +94,14 @@ func readAppEnvFile(appFile AppFile, name AppName) (App, error) { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return App{}, fmt.Errorf("env file for '%s' couldn't be read: %s", name, err.Error()) | 		return App{}, fmt.Errorf("env file for '%s' couldn't be read: %s", name, err.Error()) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("read env '%s' from '%s'", env, appFile.Path) | ||||||
|  |  | ||||||
| 	app, err := newApp(env, name, appFile) | 	app, err := newApp(env, name, appFile) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return App{}, fmt.Errorf("env file for '%s' has issues: %s", name, err.Error()) | 		return App{}, fmt.Errorf("env file for '%s' has issues: %s", name, err.Error()) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return app, nil | 	return app, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -108,6 +113,7 @@ func newApp(env AppEnv, name string, appFile AppFile) (App, error) { | |||||||
| 	if !ok { | 	if !ok { | ||||||
| 		return App{}, errors.New("missing TYPE variable") | 		return App{}, errors.New("missing TYPE variable") | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return App{ | 	return App{ | ||||||
| 		Name:   name, | 		Name:   name, | ||||||
| 		Domain: domain, | 		Domain: domain, | ||||||
| @ -131,6 +137,9 @@ func LoadAppFiles(servers ...string) (AppFiles, error) { | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("collecting metadata from '%v' servers: '%s'", len(servers), servers) | ||||||
|  |  | ||||||
| 	for _, server := range servers { | 	for _, server := range servers { | ||||||
| 		serverDir := path.Join(ABRA_SERVER_FOLDER, server) | 		serverDir := path.Join(ABRA_SERVER_FOLDER, server) | ||||||
| 		files, err := getAllFilesInDirectory(serverDir) | 		files, err := getAllFilesInDirectory(serverDir) | ||||||
| @ -157,16 +166,19 @@ func GetApp(apps AppFiles, name AppName) (App, error) { | |||||||
| 	if !exists { | 	if !exists { | ||||||
| 		return App{}, fmt.Errorf("cannot find app with name '%s'", name) | 		return App{}, fmt.Errorf("cannot find app with name '%s'", name) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	app, err := readAppEnvFile(appFile, name) | 	app, err := readAppEnvFile(appFile, name) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return App{}, err | 		return App{}, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return app, nil | 	return app, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // GetApps returns a slice of Apps with their env files read from a given slice of AppFiles | // GetApps returns a slice of Apps with their env files read from a given slice of AppFiles | ||||||
| func GetApps(appFiles AppFiles) ([]App, error) { | func GetApps(appFiles AppFiles) ([]App, error) { | ||||||
| 	var apps []App | 	var apps []App | ||||||
|  |  | ||||||
| 	for name := range appFiles { | 	for name := range appFiles { | ||||||
| 		app, err := GetApp(appFiles, name) | 		app, err := GetApp(appFiles, name) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| @ -174,9 +186,63 @@ func GetApps(appFiles AppFiles) ([]App, error) { | |||||||
| 		} | 		} | ||||||
| 		apps = append(apps, app) | 		apps = append(apps, app) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return apps, nil | 	return apps, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // GetAppServiceNames retrieves a list of app service names. | ||||||
|  | func GetAppServiceNames(appName string) ([]string, error) { | ||||||
|  | 	var serviceNames []string | ||||||
|  |  | ||||||
|  | 	appFiles, err := LoadAppFiles("") | ||||||
|  | 	if err != nil { | ||||||
|  | 		return serviceNames, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	app, err := GetApp(appFiles, appName) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return serviceNames, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	composeFiles, err := GetAppComposeFiles(app.Type, app.Env) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return serviceNames, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	opts := stack.Deploy{Composefiles: composeFiles} | ||||||
|  | 	compose, err := GetAppComposeConfig(app.Type, opts, app.Env) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return serviceNames, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	for _, service := range compose.Services { | ||||||
|  | 		serviceNames = append(serviceNames, service.Name) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return serviceNames, nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // GetAppNames retrieves a list of app names. | ||||||
|  | func GetAppNames() ([]string, error) { | ||||||
|  | 	var appNames []string | ||||||
|  |  | ||||||
|  | 	appFiles, err := LoadAppFiles("") | ||||||
|  | 	if err != nil { | ||||||
|  | 		return appNames, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	apps, err := GetApps(appFiles) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return appNames, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	for _, app := range apps { | ||||||
|  | 		appNames = append(appNames, app.Name) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return appNames, nil | ||||||
|  | } | ||||||
|  |  | ||||||
| // CopyAppEnvSample copies the example env file for the app into the users env files | // CopyAppEnvSample copies the example env file for the app into the users env files | ||||||
| func CopyAppEnvSample(appType, appName, server string) error { | func CopyAppEnvSample(appType, appName, server string) error { | ||||||
| 	envSamplePath := path.Join(ABRA_DIR, "apps", appType, ".env.sample") | 	envSamplePath := path.Join(ABRA_DIR, "apps", appType, ".env.sample") | ||||||
| @ -195,6 +261,8 @@ func CopyAppEnvSample(appType, appName, server string) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("copied '%s' to '%s'", envSamplePath, appEnvPath) | ||||||
|  |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -205,13 +273,18 @@ func SanitiseAppName(name string) string { | |||||||
|  |  | ||||||
| // GetAppStatuses queries servers to check the deployment status of given apps | // GetAppStatuses queries servers to check the deployment status of given apps | ||||||
| func GetAppStatuses(appFiles AppFiles) (map[string]string, error) { | func GetAppStatuses(appFiles AppFiles) (map[string]string, error) { | ||||||
| 	servers := appFiles.GetServers() | 	statuses := map[string]string{} | ||||||
|  |  | ||||||
|  | 	servers, err := GetServers() | ||||||
|  | 	if err != nil { | ||||||
|  | 		return statuses, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	ch := make(chan stack.StackStatus, len(servers)) | 	ch := make(chan stack.StackStatus, len(servers)) | ||||||
| 	for _, server := range servers { | 	for _, server := range servers { | ||||||
| 		go func(s string) { ch <- stack.GetAllDeployedServices(s) }(server) | 		go func(s string) { ch <- stack.GetAllDeployedServices(s) }(server) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	statuses := map[string]string{} |  | ||||||
| 	for range servers { | 	for range servers { | ||||||
| 		status := <-ch | 		status := <-ch | ||||||
| 		for _, service := range status.Services { | 		for _, service := range status.Services { | ||||||
| @ -222,6 +295,8 @@ func GetAppStatuses(appFiles AppFiles) (map[string]string, error) { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("retrieved app statuses: '%s'", statuses) | ||||||
|  |  | ||||||
| 	return statuses, nil | 	return statuses, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -229,6 +304,7 @@ func GetAppStatuses(appFiles AppFiles) (map[string]string, error) { | |||||||
| // merged into a composetypes.Config while respecting the COMPOSE_FILE env var. | // merged into a composetypes.Config while respecting the COMPOSE_FILE env var. | ||||||
| func GetAppComposeFiles(recipe string, appEnv AppEnv) ([]string, error) { | func GetAppComposeFiles(recipe string, appEnv AppEnv) ([]string, error) { | ||||||
| 	if _, ok := appEnv["COMPOSE_FILE"]; !ok { | 	if _, ok := appEnv["COMPOSE_FILE"]; !ok { | ||||||
|  | 		logrus.Debug("no COMPOSE_FILE detected, loading all compose files") | ||||||
| 		pattern := fmt.Sprintf("%s/%s/compose**yml", APPS_DIR, recipe) | 		pattern := fmt.Sprintf("%s/%s/compose**yml", APPS_DIR, recipe) | ||||||
| 		composeFiles, err := filepath.Glob(pattern) | 		composeFiles, err := filepath.Glob(pattern) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| @ -239,10 +315,15 @@ func GetAppComposeFiles(recipe string, appEnv AppEnv) ([]string, error) { | |||||||
|  |  | ||||||
| 	var composeFiles []string | 	var composeFiles []string | ||||||
| 	composeFileEnvVar := appEnv["COMPOSE_FILE"] | 	composeFileEnvVar := appEnv["COMPOSE_FILE"] | ||||||
|  | 	envVars := strings.Split(composeFileEnvVar, ":") | ||||||
|  | 	logrus.Debugf("COMPOSE_FILE detected ('%s'), loading '%s'", composeFileEnvVar, envVars) | ||||||
| 	for _, file := range strings.Split(composeFileEnvVar, ":") { | 	for _, file := range strings.Split(composeFileEnvVar, ":") { | ||||||
| 		path := fmt.Sprintf("%s/%s/%s", APPS_DIR, recipe, file) | 		path := fmt.Sprintf("%s/%s/%s", APPS_DIR, recipe, file) | ||||||
| 		composeFiles = append(composeFiles, path) | 		composeFiles = append(composeFiles, path) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("retrieved '%s' configs for '%s'", strings.Join(composeFiles, ", "), recipe) | ||||||
|  |  | ||||||
| 	return composeFiles, nil | 	return composeFiles, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -254,5 +335,8 @@ func GetAppComposeConfig(recipe string, opts stack.Deploy, appEnv AppEnv) (*comp | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return &composetypes.Config{}, err | 		return &composetypes.Config{}, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("retrieved '%s' for '%s'", compose.Filename, recipe) | ||||||
|  |  | ||||||
| 	return compose, nil | 	return compose, nil | ||||||
| } | } | ||||||
|  | |||||||
| @ -20,42 +20,56 @@ var APPS_JSON = path.Join(ABRA_DIR, "apps.json") | |||||||
| var APPS_DIR = path.Join(ABRA_DIR, "apps") | var APPS_DIR = path.Join(ABRA_DIR, "apps") | ||||||
| var REPOS_BASE_URL = "https://git.coopcloud.tech/coop-cloud" | var REPOS_BASE_URL = "https://git.coopcloud.tech/coop-cloud" | ||||||
|  |  | ||||||
| func (a AppFiles) GetServers() []string { | // GetServers retrieves all servers. | ||||||
| 	var unique []string | func GetServers() ([]string, error) { | ||||||
| 	servers := make(map[string]struct{}) | 	var servers []string | ||||||
| 	for _, appFile := range a { |  | ||||||
| 		if _, ok := servers[appFile.Server]; !ok { | 	servers, err := getAllFoldersInDirectory(ABRA_SERVER_FOLDER) | ||||||
| 			servers[appFile.Server] = struct{}{} | 	if err != nil { | ||||||
| 			unique = append(unique, appFile.Server) | 		return servers, err | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	return unique |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("retrieved '%v' servers: '%s'", len(servers), servers) | ||||||
|  |  | ||||||
|  | 	return servers, nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // ReadEnv loads an app envivornment into a map. | ||||||
| func ReadEnv(filePath string) (AppEnv, error) { | func ReadEnv(filePath string) (AppEnv, error) { | ||||||
| 	var envFile AppEnv | 	var envFile AppEnv | ||||||
|  |  | ||||||
| 	envFile, err := godotenv.Read(filePath) | 	envFile, err := godotenv.Read(filePath) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("read '%s' from '%s'", envFile, filePath) | ||||||
|  |  | ||||||
| 	return envFile, nil | 	return envFile, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // ReadServerNames retrieves all server names. | ||||||
| func ReadServerNames() ([]string, error) { | func ReadServerNames() ([]string, error) { | ||||||
| 	serverNames, err := getAllFoldersInDirectory(ABRA_SERVER_FOLDER) | 	serverNames, err := getAllFoldersInDirectory(ABRA_SERVER_FOLDER) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("read '%s' from '%s'", strings.Join(serverNames, ","), ABRA_SERVER_FOLDER) | ||||||
|  |  | ||||||
| 	return serverNames, nil | 	return serverNames, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // getAllFilesInDirectory returns filenames of all files in directory | // getAllFilesInDirectory returns filenames of all files in directory | ||||||
| func getAllFilesInDirectory(directory string) ([]fs.FileInfo, error) { | func getAllFilesInDirectory(directory string) ([]fs.FileInfo, error) { | ||||||
| 	var realFiles []fs.FileInfo | 	var realFiles []fs.FileInfo | ||||||
|  |  | ||||||
| 	files, err := ioutil.ReadDir(directory) | 	files, err := ioutil.ReadDir(directory) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, file := range files { | 	for _, file := range files { | ||||||
| 		// Follow any symlinks | 		// Follow any symlinks | ||||||
| 		filePath := path.Join(directory, file.Name()) | 		filePath := path.Join(directory, file.Name()) | ||||||
| @ -71,14 +85,15 @@ func getAllFilesInDirectory(directory string) ([]fs.FileInfo, error) { | |||||||
| 				realFiles = append(realFiles, file) | 				realFiles = append(realFiles, file) | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return realFiles, nil | 	return realFiles, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // getAllFoldersInDirectory returns both folder and symlink paths | // getAllFoldersInDirectory returns both folder and symlink paths | ||||||
| func getAllFoldersInDirectory(directory string) ([]string, error) { | func getAllFoldersInDirectory(directory string) ([]string, error) { | ||||||
| 	var folders []string | 	var folders []string | ||||||
|  |  | ||||||
| 	files, err := ioutil.ReadDir(directory) | 	files, err := ioutil.ReadDir(directory) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| @ -86,6 +101,7 @@ func getAllFoldersInDirectory(directory string) ([]string, error) { | |||||||
| 	if len(files) == 0 { | 	if len(files) == 0 { | ||||||
| 		return nil, fmt.Errorf("directory is empty: '%s'", directory) | 		return nil, fmt.Errorf("directory is empty: '%s'", directory) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, file := range files { | 	for _, file := range files { | ||||||
| 		// Check if file is directory or symlink | 		// Check if file is directory or symlink | ||||||
| 		if file.IsDir() || file.Mode()&fs.ModeSymlink != 0 { | 		if file.IsDir() || file.Mode()&fs.ModeSymlink != 0 { | ||||||
| @ -99,12 +115,14 @@ func getAllFoldersInDirectory(directory string) ([]string, error) { | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return folders, nil | 	return folders, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // EnsureAbraDirExists checks for the abra config folder and throws error if not | // EnsureAbraDirExists checks for the abra config folder and throws error if not | ||||||
| func EnsureAbraDirExists() error { | func EnsureAbraDirExists() error { | ||||||
| 	if _, err := os.Stat(ABRA_DIR); os.IsNotExist(err) { | 	if _, err := os.Stat(ABRA_DIR); os.IsNotExist(err) { | ||||||
|  | 		logrus.Debugf("'%s' does not exist, creating it", ABRA_DIR) | ||||||
| 		if err := os.Mkdir(ABRA_DIR, 0777); err != nil { | 		if err := os.Mkdir(ABRA_DIR, 0777); err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| @ -112,6 +130,7 @@ func EnsureAbraDirExists() error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // ReadAbraShEnvVars reads env vars from an abra.sh recipe file. | ||||||
| func ReadAbraShEnvVars(abraSh string) (map[string]string, error) { | func ReadAbraShEnvVars(abraSh string) (map[string]string, error) { | ||||||
| 	envVars := make(map[string]string) | 	envVars := make(map[string]string) | ||||||
|  |  | ||||||
| @ -137,5 +156,7 @@ func ReadAbraShEnvVars(abraSh string) (map[string]string, error) { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("read '%s' from '%s'", envVars, abraSh) | ||||||
|  |  | ||||||
| 	return envVars, nil | 	return envVars, nil | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										92
									
								
								pkg/git/clone.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								pkg/git/clone.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,92 @@ | |||||||
|  | package git | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"fmt" | ||||||
|  | 	"os" | ||||||
|  | 	"strings" | ||||||
|  |  | ||||||
|  | 	"github.com/go-git/go-git/v5" | ||||||
|  | 	"github.com/go-git/go-git/v5/config" | ||||||
|  | 	"github.com/go-git/go-git/v5/plumbing" | ||||||
|  | 	"github.com/sirupsen/logrus" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | // Clone runs a git clone which accounts for different default branches. | ||||||
|  | func Clone(dir, url string) error { | ||||||
|  | 	if _, err := os.Stat(dir); os.IsNotExist(err) { | ||||||
|  | 		logrus.Debugf("'%s' does not exist, attempting to git clone from '%s'", dir, url) | ||||||
|  | 		_, err := git.PlainClone(dir, false, &git.CloneOptions{URL: url, Tags: git.AllTags}) | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Debugf("cloning from default branch failed, attempting from main branch") | ||||||
|  | 			_, err := git.PlainClone(dir, false, &git.CloneOptions{ | ||||||
|  | 				URL:           url, | ||||||
|  | 				Tags:          git.AllTags, | ||||||
|  | 				ReferenceName: plumbing.ReferenceName("refs/heads/main"), | ||||||
|  | 			}) | ||||||
|  | 			if err != nil { | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		logrus.Debugf("'%s' has been git cloned successfully", dir) | ||||||
|  | 	} else { | ||||||
|  | 		logrus.Debugf("'%s' already exists, doing nothing", dir) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // EnsureUpToDate ensures that a git repo on disk has the latest changes (git-fetch). | ||||||
|  | func EnsureUpToDate(dir string) error { | ||||||
|  | 	repo, err := git.PlainOpen(dir) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	branch := "master" | ||||||
|  | 	if _, err := repo.Branch("master"); err != nil { | ||||||
|  | 		if _, err := repo.Branch("main"); err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  | 		branch = "main" | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("choosing '%s' as main git branch for in '%s'", branch, dir) | ||||||
|  |  | ||||||
|  | 	worktree, err := repo.Worktree() | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	refName := fmt.Sprintf("refs/heads/%s", branch) | ||||||
|  | 	checkOutOpts := &git.CheckoutOptions{ | ||||||
|  | 		Create: false, | ||||||
|  | 		Force:  true, | ||||||
|  | 		Keep:   false, | ||||||
|  | 		Branch: plumbing.ReferenceName(refName), | ||||||
|  | 	} | ||||||
|  | 	if err := worktree.Checkout(checkOutOpts); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("successfully checked out '%s'", branch) | ||||||
|  |  | ||||||
|  | 	remote, err := repo.Remote("origin") | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	fetchOpts := &git.FetchOptions{ | ||||||
|  | 		RemoteName: "origin", | ||||||
|  | 		RefSpecs:   []config.RefSpec{"refs/heads/*:refs/remotes/origin/*"}, | ||||||
|  | 		Force:      true, | ||||||
|  | 	} | ||||||
|  | 	if err := remote.Fetch(fetchOpts); err != nil { | ||||||
|  | 		if !strings.Contains(err.Error(), "already up-to-date") { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("successfully fetched all changes in '%s'", dir) | ||||||
|  |  | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
| @ -2,7 +2,6 @@ package recipe | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"os" |  | ||||||
| 	"path" | 	"path" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 	"strings" | 	"strings" | ||||||
| @ -11,9 +10,11 @@ import ( | |||||||
| 	loader "coopcloud.tech/abra/pkg/client/stack" | 	loader "coopcloud.tech/abra/pkg/client/stack" | ||||||
| 	"coopcloud.tech/abra/pkg/compose" | 	"coopcloud.tech/abra/pkg/compose" | ||||||
| 	"coopcloud.tech/abra/pkg/config" | 	"coopcloud.tech/abra/pkg/config" | ||||||
|  | 	gitPkg "coopcloud.tech/abra/pkg/git" | ||||||
| 	composetypes "github.com/docker/cli/cli/compose/types" | 	composetypes "github.com/docker/cli/cli/compose/types" | ||||||
| 	"github.com/go-git/go-git/v5" | 	"github.com/go-git/go-git/v5" | ||||||
| 	"github.com/go-git/go-git/v5/plumbing" | 	"github.com/go-git/go-git/v5/plumbing" | ||||||
|  | 	"github.com/sirupsen/logrus" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // Recipe represents a recipe. | // Recipe represents a recipe. | ||||||
| @ -52,9 +53,14 @@ func Get(recipeName string) (Recipe, error) { | |||||||
| 		return Recipe{}, err | 		return Recipe{}, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	envSamplePath := path.Join(config.ABRA_DIR, "apps", recipeName, ".env.sample") | ||||||
|  | 	sampleEnv, err := config.ReadEnv(envSamplePath) | ||||||
|  | 	if err != nil { | ||||||
|  | 		logrus.Fatal(err) | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	opts := stack.Deploy{Composefiles: composeFiles} | 	opts := stack.Deploy{Composefiles: composeFiles} | ||||||
| 	emptyEnv := make(map[string]string) | 	config, err := loader.LoadComposefile(opts, sampleEnv) | ||||||
| 	config, err := loader.LoadComposefile(opts, emptyEnv) |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return Recipe{}, err | 		return Recipe{}, err | ||||||
| 	} | 	} | ||||||
| @ -65,23 +71,10 @@ func Get(recipeName string) (Recipe, error) { | |||||||
| // EnsureExists checks whether a recipe has been cloned locally or not. | // EnsureExists checks whether a recipe has been cloned locally or not. | ||||||
| func EnsureExists(recipe string) error { | func EnsureExists(recipe string) error { | ||||||
| 	recipeDir := path.Join(config.ABRA_DIR, "apps", strings.ToLower(recipe)) | 	recipeDir := path.Join(config.ABRA_DIR, "apps", strings.ToLower(recipe)) | ||||||
|  |  | ||||||
| 	if _, err := os.Stat(recipeDir); os.IsNotExist(err) { |  | ||||||
| 	url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, recipe) | 	url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, recipe) | ||||||
| 		_, err := git.PlainClone(recipeDir, false, &git.CloneOptions{URL: url, Tags: git.AllTags}) | 	if err := gitPkg.Clone(recipeDir, url); err != nil { | ||||||
| 		if err != nil { |  | ||||||
| 			// try with main branch because Git is being a Git |  | ||||||
| 			_, err := git.PlainClone(recipeDir, false, &git.CloneOptions{ |  | ||||||
| 				URL:           url, |  | ||||||
| 				Tags:          git.AllTags, |  | ||||||
| 				ReferenceName: plumbing.ReferenceName("refs/heads/main"), |  | ||||||
| 			}) |  | ||||||
| 			if err != nil { |  | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -99,6 +92,8 @@ func EnsureVersion(recipeName, version string) error { | |||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("read '%s' as tags for recipe '%s'", tags, recipeName) | ||||||
|  |  | ||||||
| 	var tagRef plumbing.ReferenceName | 	var tagRef plumbing.ReferenceName | ||||||
| 	if err := tags.ForEach(func(ref *plumbing.Reference) (err error) { | 	if err := tags.ForEach(func(ref *plumbing.Reference) (err error) { | ||||||
| 		if ref.Name().Short() == version { | 		if ref.Name().Short() == version { | ||||||
| @ -123,5 +118,7 @@ func EnsureVersion(recipeName, version string) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("successfully checked '%s' out to '%s' in '%s'", recipeName, tagRef, recipeDir) | ||||||
|  |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  | |||||||
| @ -19,6 +19,8 @@ func PassInsertSecret(secretValue, secretName, appName, server string) error { | |||||||
| 		secretValue, server, appName, secretName, | 		secretValue, server, appName, secretName, | ||||||
| 	) | 	) | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("attempting to run '%s'", cmd) | ||||||
|  |  | ||||||
| 	if err := exec.Command("bash", "-c", cmd).Run(); err != nil { | 	if err := exec.Command("bash", "-c", cmd).Run(); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @ -39,6 +41,8 @@ func PassRmSecret(secretName, appName, server string) error { | |||||||
| 		server, appName, secretName, | 		server, appName, secretName, | ||||||
| 	) | 	) | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("attempting to run '%s'", cmd) | ||||||
|  |  | ||||||
| 	if err := exec.Command("bash", "-c", cmd).Run(); err != nil { | 	if err := exec.Command("bash", "-c", cmd).Run(); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -12,6 +12,7 @@ import ( | |||||||
| 	"coopcloud.tech/abra/pkg/client" | 	"coopcloud.tech/abra/pkg/client" | ||||||
| 	"coopcloud.tech/abra/pkg/config" | 	"coopcloud.tech/abra/pkg/config" | ||||||
| 	"github.com/schultz-is/passgen" | 	"github.com/schultz-is/passgen" | ||||||
|  | 	"github.com/sirupsen/logrus" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // secretValue represents a parsed `SECRET_FOO=v1 # length=bar` env var config | // secretValue represents a parsed `SECRET_FOO=v1 # length=bar` env var config | ||||||
| @ -33,6 +34,8 @@ func GeneratePasswords(count, length uint) ([]string, error) { | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("generated '%s'", strings.Join(passwords, ", ")) | ||||||
|  |  | ||||||
| 	return passwords, nil | 	return passwords, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -50,17 +53,24 @@ func GeneratePassphrases(count uint) ([]string, error) { | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("generated '%s'", strings.Join(passphrases, ", ")) | ||||||
|  |  | ||||||
| 	return passphrases, nil | 	return passphrases, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // ReadSecretEnvVars reads secret env vars from an app env var config. | ||||||
| func ReadSecretEnvVars(appEnv config.AppEnv) map[string]string { | func ReadSecretEnvVars(appEnv config.AppEnv) map[string]string { | ||||||
| 	secretEnvVars := make(map[string]string) | 	secretEnvVars := make(map[string]string) | ||||||
|  |  | ||||||
| 	for envVar := range appEnv { | 	for envVar := range appEnv { | ||||||
| 		regex := regexp.MustCompile(`^SECRET.*VERSION.*`) | 		regex := regexp.MustCompile(`^SECRET.*VERSION.*`) | ||||||
| 		if string(regex.Find([]byte(envVar))) != "" { | 		if string(regex.Find([]byte(envVar))) != "" { | ||||||
| 			secretEnvVars[envVar] = appEnv[envVar] | 			secretEnvVars[envVar] = appEnv[envVar] | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("read '%s' as secrets from '%s'", secretEnvVars, appEnv) | ||||||
|  |  | ||||||
| 	return secretEnvVars | 	return secretEnvVars | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -68,7 +78,9 @@ func ReadSecretEnvVars(appEnv config.AppEnv) map[string]string { | |||||||
| func ParseSecretEnvVarName(secretEnvVar string) string { | func ParseSecretEnvVarName(secretEnvVar string) string { | ||||||
| 	withoutPrefix := strings.TrimPrefix(secretEnvVar, "SECRET_") | 	withoutPrefix := strings.TrimPrefix(secretEnvVar, "SECRET_") | ||||||
| 	withoutSuffix := strings.TrimSuffix(withoutPrefix, "_VERSION") | 	withoutSuffix := strings.TrimSuffix(withoutPrefix, "_VERSION") | ||||||
| 	return strings.ToLower(withoutSuffix) | 	name := strings.ToLower(withoutSuffix) | ||||||
|  | 	logrus.Debugf("parsed '%s' as name from '%s'", name, secretEnvVar) | ||||||
|  | 	return name | ||||||
| } | } | ||||||
|  |  | ||||||
| // TODO: should probably go in the config/app package? | // TODO: should probably go in the config/app package? | ||||||
| @ -76,7 +88,9 @@ func ParseGeneratedSecretName(secret string, appEnv config.App) string { | |||||||
| 	name := fmt.Sprintf("%s_", appEnv.StackName()) | 	name := fmt.Sprintf("%s_", appEnv.StackName()) | ||||||
| 	withoutAppName := strings.TrimPrefix(secret, name) | 	withoutAppName := strings.TrimPrefix(secret, name) | ||||||
| 	idx := strings.LastIndex(withoutAppName, "_") | 	idx := strings.LastIndex(withoutAppName, "_") | ||||||
| 	return withoutAppName[:idx] | 	parsed := withoutAppName[:idx] | ||||||
|  | 	logrus.Debugf("parsed '%s' as name from '%s'", parsed, secret) | ||||||
|  | 	return parsed | ||||||
| } | } | ||||||
|  |  | ||||||
| // TODO: should probably go in the config/app package? | // TODO: should probably go in the config/app package? | ||||||
| @ -85,9 +99,11 @@ func ParseSecretEnvVarValue(secret string) (secretValue, error) { | |||||||
| 	if len(values) == 0 { | 	if len(values) == 0 { | ||||||
| 		return secretValue{}, fmt.Errorf("unable to parse '%s'", secret) | 		return secretValue{}, fmt.Errorf("unable to parse '%s'", secret) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if len(values) == 1 { | 	if len(values) == 1 { | ||||||
| 		return secretValue{Version: values[0], Length: 0}, nil | 		return secretValue{Version: values[0], Length: 0}, nil | ||||||
| 	} else { | 	} | ||||||
|  |  | ||||||
| 	split := strings.Split(values[1], "=") | 	split := strings.Split(values[1], "=") | ||||||
| 	parsed := split[len(split)-1] | 	parsed := split[len(split)-1] | ||||||
| 	stripped := strings.ReplaceAll(parsed, " ", "") | 	stripped := strings.ReplaceAll(parsed, " ", "") | ||||||
| @ -96,9 +112,11 @@ func ParseSecretEnvVarValue(secret string) (secretValue, error) { | |||||||
| 		return secretValue{}, err | 		return secretValue{}, err | ||||||
| 	} | 	} | ||||||
| 	version := strings.ReplaceAll(values[0], " ", "") | 	version := strings.ReplaceAll(values[0], " ", "") | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("parsed version '%s' and length '%v' from '%s'", version, length, secret) | ||||||
|  |  | ||||||
| 	return secretValue{Version: version, Length: length}, nil | 	return secretValue{Version: version, Length: length}, nil | ||||||
| } | } | ||||||
| } |  | ||||||
|  |  | ||||||
| // GenerateSecrets generates secrets locally and sends them to a remote server for storage. | // GenerateSecrets generates secrets locally and sends them to a remote server for storage. | ||||||
| func GenerateSecrets(secretEnvVars map[string]string, appName, server string) (map[string]string, error) { | func GenerateSecrets(secretEnvVars map[string]string, appName, server string) (map[string]string, error) { | ||||||
| @ -114,6 +132,7 @@ func GenerateSecrets(secretEnvVars map[string]string, appName, server string) (m | |||||||
| 				return | 				return | ||||||
| 			} | 			} | ||||||
| 			secretRemoteName := fmt.Sprintf("%s_%s_%s", appName, secretName, secretValue.Version) | 			secretRemoteName := fmt.Sprintf("%s_%s_%s", appName, secretName, secretValue.Version) | ||||||
|  | 			logrus.Debugf("attempting to generate and store '%s' on '%s'", secretRemoteName, server) | ||||||
| 			if secretValue.Length > 0 { | 			if secretValue.Length > 0 { | ||||||
| 				passwords, err := GeneratePasswords(1, uint(secretValue.Length)) | 				passwords, err := GeneratePasswords(1, uint(secretValue.Length)) | ||||||
| 				if err != nil { | 				if err != nil { | ||||||
| @ -147,5 +166,7 @@ func GenerateSecrets(secretEnvVars map[string]string, appName, server string) (m | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	logrus.Debugf("generated and stored '%s' on '%s'", secrets, server) | ||||||
|  |  | ||||||
| 	return secrets, nil | 	return secrets, nil | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										21
									
								
								scripts/autocomplete/bash
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										21
									
								
								scripts/autocomplete/bash
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,21 @@ | |||||||
|  | #! /bin/bash | ||||||
|  |  | ||||||
|  | : ${PROG:=$(basename ${BASH_SOURCE})} | ||||||
|  |  | ||||||
|  | _cli_bash_autocomplete() { | ||||||
|  |   if [[ "${COMP_WORDS[0]}" != "source" ]]; then | ||||||
|  |     local cur opts base | ||||||
|  |     COMPREPLY=() | ||||||
|  |     cur="${COMP_WORDS[COMP_CWORD]}" | ||||||
|  |     if [[ "$cur" == "-"* ]]; then | ||||||
|  |       opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion ) | ||||||
|  |     else | ||||||
|  |       opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion ) | ||||||
|  |     fi | ||||||
|  |     COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||||||
|  |     return 0 | ||||||
|  |   fi | ||||||
|  | } | ||||||
|  |  | ||||||
|  | complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG | ||||||
|  | unset PROG | ||||||
							
								
								
									
										9
									
								
								scripts/autocomplete/powershell
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								scripts/autocomplete/powershell
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | |||||||
|  | $fn = $($MyInvocation.MyCommand.Name) | ||||||
|  | $name = $fn -replace "(.*)\.ps1$", '$1' | ||||||
|  | Register-ArgumentCompleter -Native -CommandName $name -ScriptBlock { | ||||||
|  |      param($commandName, $wordToComplete, $cursorPosition) | ||||||
|  |      $other = "$wordToComplete --generate-bash-completion" | ||||||
|  |          Invoke-Expression $other | ForEach-Object { | ||||||
|  |             [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) | ||||||
|  |          } | ||||||
|  |  } | ||||||
							
								
								
									
										23
									
								
								scripts/autocomplete/zsh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								scripts/autocomplete/zsh
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,23 @@ | |||||||
|  | #compdef $PROG | ||||||
|  |  | ||||||
|  | _cli_zsh_autocomplete() { | ||||||
|  |  | ||||||
|  |   local -a opts | ||||||
|  |   local cur | ||||||
|  |   cur=${words[-1]} | ||||||
|  |   if [[ "$cur" == "-"* ]]; then | ||||||
|  |     opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") | ||||||
|  |   else | ||||||
|  |     opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}") | ||||||
|  |   fi | ||||||
|  |  | ||||||
|  |   if [[ "${opts[1]}" != "" ]]; then | ||||||
|  |     _describe 'values' opts | ||||||
|  |   else | ||||||
|  |     _files | ||||||
|  |   fi | ||||||
|  |  | ||||||
|  |   return | ||||||
|  | } | ||||||
|  |  | ||||||
|  | compdef _cli_zsh_autocomplete $PROG | ||||||
							
								
								
									
										5
									
								
								scripts/installer/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								scripts/installer/README.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | |||||||
|  | # install.abra.coopcloud.tech | ||||||
|  |  | ||||||
|  | To deploy, run `make`. | ||||||
|  |  | ||||||
|  | You have to be an [Autonomic](https://autonomic.zone) member to do this. | ||||||
							
								
								
									
										38
									
								
								scripts/installer/compose.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								scripts/installer/compose.yml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,38 @@ | |||||||
|  | --- | ||||||
|  | version: "3.8" | ||||||
|  |  | ||||||
|  | services: | ||||||
|  |   app: | ||||||
|  |     image: "nginx:stable" | ||||||
|  |     configs: | ||||||
|  |       - source: abra_conf | ||||||
|  |         target: /etc/nginx/conf.d/abra.conf | ||||||
|  |       - source: abra_installer | ||||||
|  |         target: /var/www/abra-installer/installer | ||||||
|  |     volumes: | ||||||
|  |       - "public:/var/www/abra-installer" | ||||||
|  |     networks: | ||||||
|  |       - proxy | ||||||
|  |     deploy: | ||||||
|  |       update_config: | ||||||
|  |         failure_action: rollback | ||||||
|  |         order: start-first | ||||||
|  |       labels: | ||||||
|  |         - "traefik.enable=true" | ||||||
|  |         - "traefik.http.services.abra-installer.loadbalancer.server.port=80" | ||||||
|  |         - "traefik.http.routers.abra-installer.rule=Host(`install.abra.autonomic.zone`,`install.abra.coopcloud.tech`)" | ||||||
|  |         - "traefik.http.routers.abra-installer.entrypoints=web-secure" | ||||||
|  |         - "traefik.http.routers.abra-installer.tls.certresolver=production" | ||||||
|  |  | ||||||
|  | configs: | ||||||
|  |   abra_installer: | ||||||
|  |     file: installer | ||||||
|  |   abra_conf: | ||||||
|  |     file: nginx.conf | ||||||
|  |  | ||||||
|  | networks: | ||||||
|  |   proxy: | ||||||
|  |     external: true | ||||||
|  |  | ||||||
|  | volumes: | ||||||
|  |   public: | ||||||
							
								
								
									
										57
									
								
								scripts/installer/installer
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										57
									
								
								scripts/installer/installer
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,57 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  |  | ||||||
|  | ABRA_VERSION="0.1.3-alpha" | ||||||
|  | ABRA_RELEASE_URL="https://git.coopcloud.tech/api/v1/repos/coop-cloud/abra/releases/tags/$ABRA_VERSION" | ||||||
|  |  | ||||||
|  | function show_banner { | ||||||
|  |   echo "" | ||||||
|  |   echo "   ____                           ____ _                 _ " | ||||||
|  |   echo "  / ___|___         ___  _ __    / ___| | ___  _   _  __| |" | ||||||
|  |   echo " | |   / _ \ _____ / _ \| '_ \  | |   | |/ _ \| | | |/ _' |" | ||||||
|  |   echo " | |__| (_) |_____| (_) | |_) | | |___| | (_) | |_| | (_| |" | ||||||
|  |   echo "  \____\___/       \___/| .__/   \____|_|\___/ \__,_|\__,_|" | ||||||
|  |   echo "                        |_|" | ||||||
|  |   echo "" | ||||||
|  |   echo "" | ||||||
|  |   echo "          === Public interest infrastructure ===           " | ||||||
|  |   echo "" | ||||||
|  |   echo "" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function install_abra_release { | ||||||
|  |   mkdir -p "$HOME/.local/bin" | ||||||
|  |  | ||||||
|  |   if ! type "curl" > /dev/null 2>&1; then | ||||||
|  |     echo "'curl' is not installed, cannot proceed..." | ||||||
|  |     echo "perhaps try installing manually via the releases URL?" | ||||||
|  |     echo "https://git.coopcloud.tech/coop-cloud/abra/releases" | ||||||
|  |     exit 1 | ||||||
|  |   fi | ||||||
|  |  | ||||||
|  |   if ! type "curl" > /dev/null 2>&1; then | ||||||
|  |     error "'python3' is not installed, cannot proceed..." | ||||||
|  |     echo "perhaps try installing manually via the releases URL?" | ||||||
|  |     echo "https://git.coopcloud.tech/coop-cloud/abra/releases" | ||||||
|  |   fi | ||||||
|  |  | ||||||
|  |   # FIXME: support different architectures | ||||||
|  |   release_url=$(curl -s "$ABRA_RELEASE_URL" | | ||||||
|  |     python3 -c "import sys, json; \ | ||||||
|  |                 payload = json.load(sys.stdin); \ | ||||||
|  |                 url = [a['browser_download_url'] for a in payload['assets'] if 'x86_64' in a['name']][0]; \ | ||||||
|  |                 print(url)") | ||||||
|  |  | ||||||
|  |   echo "downloading $ABRA_VERSION x86_64 binary release for abra..." | ||||||
|  |   curl --progress-bar "$release_url" --output "$HOME/.local/bin/abra" | ||||||
|  |   chmod +x "$HOME/.local/bin/abra" | ||||||
|  |  | ||||||
|  |   echo "abra installed to $HOME/.local/bin/abra" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function run_installation { | ||||||
|  |   show_banner | ||||||
|  |   install_abra_release | ||||||
|  | } | ||||||
|  |  | ||||||
|  | run_installation "$@" | ||||||
|  | exit 0 | ||||||
							
								
								
									
										7
									
								
								scripts/installer/makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								scripts/installer/makefile
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,7 @@ | |||||||
|  | STACK := abra_installer_script | ||||||
|  |  | ||||||
|  | default: deploy | ||||||
|  |  | ||||||
|  | deploy: | ||||||
|  | 	@docker stack rm $(STACK) && \ | ||||||
|  | 		docker stack deploy -c compose.yml $(STACK) | ||||||
							
								
								
									
										10
									
								
								scripts/installer/nginx.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								scripts/installer/nginx.conf
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | |||||||
|  | server { | ||||||
|  |   listen         80 default_server; | ||||||
|  |   server_name    install.abra.autonomic.zone install.abra.coopcloud.tech; | ||||||
|  |  | ||||||
|  |   location / { | ||||||
|  |     root /var/www/abra-installer; | ||||||
|  |     add_header Content-Type text/plain; | ||||||
|  |     index installer; | ||||||
|  |   } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user