forked from toolshed/abra
		
	Compare commits
	
		
			11 Commits
		
	
	
		
			0.1.5-alph
			...
			0.1.6-alph
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 700f89425a | |||
| 8cc0a350e6 | |||
| 46e67fa420 | |||
| cacbb5a0f1 | |||
| e7046a15aa | |||
| c1fd97c427 | |||
| 2f218bd99f | |||
| 48290aa316 | |||
| db5cbfa992 | |||
| 4c11e813e8 | |||
| 
						
						
							
						
						6ae75e013a
	
				 | 
					
					
						
@ -14,12 +14,12 @@ builds:
 | 
			
		||||
    dir: cmd/abra
 | 
			
		||||
    goos:
 | 
			
		||||
      - linux
 | 
			
		||||
      - darwin
 | 
			
		||||
    ldflags:
 | 
			
		||||
      - "-X 'main.Commit={{ .Commit }}'"
 | 
			
		||||
      - "-X 'main.Version={{ .Version }}'"
 | 
			
		||||
archives:
 | 
			
		||||
  - replacements:
 | 
			
		||||
      linux: Linux
 | 
			
		||||
      386: i386
 | 
			
		||||
      amd64: x86_64
 | 
			
		||||
    format: binary
 | 
			
		||||
@ -32,4 +32,8 @@ changelog:
 | 
			
		||||
  filters:
 | 
			
		||||
    exclude:
 | 
			
		||||
      - "^docs:"
 | 
			
		||||
      - "^refactor:"
 | 
			
		||||
      - "^style:"
 | 
			
		||||
      - "^test:"
 | 
			
		||||
      - "^tests:"
 | 
			
		||||
      - "^chore:"
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@ import (
 | 
			
		||||
	"coopcloud.tech/abra/cli/catalogue"
 | 
			
		||||
	"coopcloud.tech/abra/cli/recipe"
 | 
			
		||||
	"coopcloud.tech/abra/cli/server"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/config"
 | 
			
		||||
	logrusStack "github.com/Gurpartap/logrus-stack"
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
	"github.com/urfave/cli/v2"
 | 
			
		||||
@ -84,7 +85,13 @@ func RunApp(version, commit string) {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	logrus.Debugf("Flying abra version '%s', commit '%s', enjoy the ride", version, commit)
 | 
			
		||||
	if err := os.Mkdir(config.ABRA_DIR, 0755); err != nil {
 | 
			
		||||
		if !os.IsExist(err) {
 | 
			
		||||
			logrus.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	logrus.Debugf("abra version '%s', commit '%s'", version, commit)
 | 
			
		||||
 | 
			
		||||
	if err := app.Run(os.Args); err != nil {
 | 
			
		||||
		logrus.Fatal(err)
 | 
			
		||||
 | 
			
		||||
@ -4,6 +4,30 @@ import (
 | 
			
		||||
	"github.com/urfave/cli/v2"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var Major bool
 | 
			
		||||
var MajorFlag = &cli.BoolFlag{
 | 
			
		||||
	Name:        "major",
 | 
			
		||||
	Value:       false,
 | 
			
		||||
	Aliases:     []string{"ma", "x"},
 | 
			
		||||
	Destination: &Major,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var Minor bool
 | 
			
		||||
var MinorFlag = &cli.BoolFlag{
 | 
			
		||||
	Name:        "minor",
 | 
			
		||||
	Value:       false,
 | 
			
		||||
	Aliases:     []string{"mi", "y"},
 | 
			
		||||
	Destination: &Minor,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var Patch bool
 | 
			
		||||
var PatchFlag = &cli.BoolFlag{
 | 
			
		||||
	Name:        "patch",
 | 
			
		||||
	Value:       false,
 | 
			
		||||
	Aliases:     []string{"p", "z"},
 | 
			
		||||
	Destination: &Patch,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RecipeCommand defines all recipe related sub-commands.
 | 
			
		||||
var RecipeCommand = &cli.Command{
 | 
			
		||||
	Name:      "recipe",
 | 
			
		||||
 | 
			
		||||
@ -33,30 +33,6 @@ var DryFlag = &cli.BoolFlag{
 | 
			
		||||
	Destination: &Dry,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var Major bool
 | 
			
		||||
var MajorFlag = &cli.BoolFlag{
 | 
			
		||||
	Name:        "major",
 | 
			
		||||
	Value:       false,
 | 
			
		||||
	Aliases:     []string{"ma", "x"},
 | 
			
		||||
	Destination: &Major,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var Minor bool
 | 
			
		||||
var MinorFlag = &cli.BoolFlag{
 | 
			
		||||
	Name:        "minor",
 | 
			
		||||
	Value:       false,
 | 
			
		||||
	Aliases:     []string{"mi", "y"},
 | 
			
		||||
	Destination: &Minor,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var Patch bool
 | 
			
		||||
var PatchFlag = &cli.BoolFlag{
 | 
			
		||||
	Name:        "patch",
 | 
			
		||||
	Value:       false,
 | 
			
		||||
	Aliases:     []string{"p", "z"},
 | 
			
		||||
	Destination: &Patch,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var CommitMessage string
 | 
			
		||||
var CommitMessageFlag = &cli.StringFlag{
 | 
			
		||||
	Name:        "commit-message",
 | 
			
		||||
 | 
			
		||||
@ -3,14 +3,12 @@ package server
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/user"
 | 
			
		||||
	"path"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"coopcloud.tech/abra/cli/internal"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/client"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/config"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/server"
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
	"github.com/urfave/cli/v2"
 | 
			
		||||
)
 | 
			
		||||
@ -30,10 +28,14 @@ var serverAddCommand = &cli.Command{
 | 
			
		||||
	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.
 | 
			
		||||
If "--local" is passed, then Abra assumes that the current local server is
 | 
			
		||||
intended as the target server.
 | 
			
		||||
 | 
			
		||||
Otherwise, you may specify a remote server. 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:
 | 
			
		||||
 | 
			
		||||
@ -44,9 +46,6 @@ 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.
 | 
			
		||||
 | 
			
		||||
NOTE: If you specify --local, none of the above applies 🙃
 | 
			
		||||
 | 
			
		||||
`,
 | 
			
		||||
	Aliases: []string{"a"},
 | 
			
		||||
	Flags: []cli.Flag{
 | 
			
		||||
@ -67,7 +66,10 @@ NOTE: If you specify --local, none of the above applies 🙃
 | 
			
		||||
		domainName := "default"
 | 
			
		||||
 | 
			
		||||
		if local {
 | 
			
		||||
			os.Mkdir(path.Join(config.ABRA_DIR, "servers", domainName), 0755)
 | 
			
		||||
			if err := server.CreateServerDir(domainName); err != nil {
 | 
			
		||||
				logrus.Fatal(err)
 | 
			
		||||
			}
 | 
			
		||||
			logrus.Info("local server has been added")
 | 
			
		||||
			return nil
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -124,9 +126,12 @@ NOTE: If you specify --local, none of the above applies 🙃
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		logrus.Debugf("remote connection to '%s' is definitely up", domainName)
 | 
			
		||||
		logrus.Infof("server at '%s' has been added", domainName)
 | 
			
		||||
 | 
			
		||||
		os.Mkdir(path.Join(config.ABRA_DIR, "servers", domainName), 0755)
 | 
			
		||||
		if err := server.CreateServerDir(domainName); err != nil {
 | 
			
		||||
			logrus.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		logrus.Infof("server at '%s' has been added", domainName)
 | 
			
		||||
 | 
			
		||||
		return nil
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
@ -45,7 +45,11 @@ var serverListCommand = &cli.Command{
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			if len(row) == 0 {
 | 
			
		||||
				row = []string{serverName, "UNKNOWN"}
 | 
			
		||||
				if serverName == "default" {
 | 
			
		||||
					row = []string{serverName, "local"}
 | 
			
		||||
				} else {
 | 
			
		||||
					row = []string{serverName, "unknown"}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			table.Append(row)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -3,18 +3,20 @@ package compose
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"path"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"coopcloud.tech/abra/pkg/client/stack"
 | 
			
		||||
	loader "coopcloud.tech/abra/pkg/client/stack"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/config"
 | 
			
		||||
	composetypes "github.com/docker/cli/cli/compose/types"
 | 
			
		||||
	"github.com/docker/distribution/reference"
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// UpdateTag updates an image tag in-place on file system local compose files.
 | 
			
		||||
func UpdateTag(pattern, image, tag string) error {
 | 
			
		||||
func UpdateTag(pattern, image, tag, recipeName string) error {
 | 
			
		||||
	composeFiles, err := filepath.Glob(pattern)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
@ -24,8 +26,14 @@ func UpdateTag(pattern, image, tag string) error {
 | 
			
		||||
 | 
			
		||||
	for _, composeFile := range composeFiles {
 | 
			
		||||
		opts := stack.Deploy{Composefiles: []string{composeFile}}
 | 
			
		||||
		emptyEnv := make(map[string]string)
 | 
			
		||||
		compose, err := loader.LoadComposefile(opts, emptyEnv)
 | 
			
		||||
 | 
			
		||||
		envSamplePath := path.Join(config.ABRA_DIR, "apps", recipeName, ".env.sample")
 | 
			
		||||
		sampleEnv, err := config.ReadEnv(envSamplePath)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		compose, err := loader.LoadComposefile(opts, sampleEnv)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
@ -74,7 +82,7 @@ func UpdateTag(pattern, image, tag string) error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateLabel updates a label in-place on file system local compose files.
 | 
			
		||||
func UpdateLabel(pattern, serviceName, label string) error {
 | 
			
		||||
func UpdateLabel(pattern, serviceName, label, recipeName string) error {
 | 
			
		||||
	composeFiles, err := filepath.Glob(pattern)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
@ -84,8 +92,14 @@ func UpdateLabel(pattern, serviceName, label string) error {
 | 
			
		||||
 | 
			
		||||
	for _, composeFile := range composeFiles {
 | 
			
		||||
		opts := stack.Deploy{Composefiles: []string{composeFile}}
 | 
			
		||||
		emptyEnv := make(map[string]string)
 | 
			
		||||
		compose, err := loader.LoadComposefile(opts, emptyEnv)
 | 
			
		||||
 | 
			
		||||
		envSamplePath := path.Join(config.ABRA_DIR, "apps", recipeName, ".env.sample")
 | 
			
		||||
		sampleEnv, err := config.ReadEnv(envSamplePath)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		compose, err := loader.LoadComposefile(opts, sampleEnv)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -26,7 +26,7 @@ type Recipe struct {
 | 
			
		||||
// UpdateLabel updates a recipe label
 | 
			
		||||
func (r Recipe) UpdateLabel(serviceName, label string) error {
 | 
			
		||||
	pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, r.Name)
 | 
			
		||||
	if err := compose.UpdateLabel(pattern, serviceName, label); err != nil {
 | 
			
		||||
	if err := compose.UpdateLabel(pattern, serviceName, label, r.Name); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
@ -35,7 +35,7 @@ func (r Recipe) UpdateLabel(serviceName, label string) error {
 | 
			
		||||
// UpdateTag updates a recipe tag
 | 
			
		||||
func (r Recipe) UpdateTag(image, tag string) error {
 | 
			
		||||
	pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, r.Name)
 | 
			
		||||
	if err := compose.UpdateTag(pattern, image, tag); err != nil {
 | 
			
		||||
	if err := compose.UpdateTag(pattern, image, tag, r.Name); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										24
									
								
								pkg/server/server.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								pkg/server/server.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,24 @@
 | 
			
		||||
package server
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
	"path"
 | 
			
		||||
 | 
			
		||||
	"coopcloud.tech/abra/pkg/config"
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// CreateServerDir creates a server directory under ~/.abra.
 | 
			
		||||
func CreateServerDir(serverName string) error {
 | 
			
		||||
	serverPath := path.Join(config.ABRA_DIR, "servers", serverName)
 | 
			
		||||
 | 
			
		||||
	if err := os.Mkdir(serverPath, 0755); err != nil {
 | 
			
		||||
		if !os.IsExist(err) {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		logrus.Infof("'%s' already exists, moving on...", serverPath)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
ABRA_VERSION="0.1.5-alpha"
 | 
			
		||||
ABRA_VERSION="0.1.6-alpha"
 | 
			
		||||
ABRA_RELEASE_URL="https://git.coopcloud.tech/api/v1/repos/coop-cloud/abra/releases/tags/$ABRA_VERSION"
 | 
			
		||||
 | 
			
		||||
function show_banner {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										0
									
								
								tests/resources/test_folder/cruft.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/resources/test_folder/cruft.txt
									
									
									
									
									
										Normal file
									
								
							
		Reference in New Issue
	
	Block a user