Compare commits

...

11 Commits

11 changed files with 107 additions and 49 deletions

View File

@ -14,12 +14,12 @@ builds:
dir: cmd/abra dir: cmd/abra
goos: goos:
- linux - linux
- darwin
ldflags: ldflags:
- "-X 'main.Commit={{ .Commit }}'" - "-X 'main.Commit={{ .Commit }}'"
- "-X 'main.Version={{ .Version }}'" - "-X 'main.Version={{ .Version }}'"
archives: archives:
- replacements: - replacements:
linux: Linux
386: i386 386: i386
amd64: x86_64 amd64: x86_64
format: binary format: binary
@ -32,4 +32,8 @@ changelog:
filters: filters:
exclude: exclude:
- "^docs:" - "^docs:"
- "^refactor:"
- "^style:"
- "^test:" - "^test:"
- "^tests:"
- "^chore:"

View File

@ -9,6 +9,7 @@ import (
"coopcloud.tech/abra/cli/catalogue" "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"
"coopcloud.tech/abra/pkg/config"
logrusStack "github.com/Gurpartap/logrus-stack" logrusStack "github.com/Gurpartap/logrus-stack"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -84,7 +85,13 @@ func RunApp(version, commit string) {
return nil 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 { if err := app.Run(os.Args); err != nil {
logrus.Fatal(err) logrus.Fatal(err)

View File

@ -4,6 +4,30 @@ import (
"github.com/urfave/cli/v2" "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. // RecipeCommand defines all recipe related sub-commands.
var RecipeCommand = &cli.Command{ var RecipeCommand = &cli.Command{
Name: "recipe", Name: "recipe",

View File

@ -33,30 +33,6 @@ var DryFlag = &cli.BoolFlag{
Destination: &Dry, 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 CommitMessage string
var CommitMessageFlag = &cli.StringFlag{ var CommitMessageFlag = &cli.StringFlag{
Name: "commit-message", Name: "commit-message",

View File

@ -3,14 +3,12 @@ package server
import ( import (
"context" "context"
"errors" "errors"
"os"
"os/user" "os/user"
"path"
"strings" "strings"
"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/server"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
@ -30,10 +28,14 @@ var serverAddCommand = &cli.Command{
Description: ` Description: `
This command adds a new server that abra will communicate with, to deploy apps. 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 If "--local" is passed, then Abra assumes that the current local server is
your server. You should have SSH access to this server, Abra will assume port intended as the target server.
22 and will use your current system username to make an initial connection. You
can use the <user> and <port> arguments to adjust this. 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: For example:
@ -44,9 +46,6 @@ Abra will construct the following SSH connection string then:
ssh://globemodem@varia.zone:12345 ssh://globemodem@varia.zone:12345
All communication between Abra and the server will use this SSH connection. 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"}, Aliases: []string{"a"},
Flags: []cli.Flag{ Flags: []cli.Flag{
@ -67,7 +66,10 @@ NOTE: If you specify --local, none of the above applies 🙃
domainName := "default" domainName := "default"
if local { 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 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.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 return nil
}, },

View File

@ -45,7 +45,11 @@ var serverListCommand = &cli.Command{
} }
} }
if len(row) == 0 { if len(row) == 0 {
row = []string{serverName, "UNKNOWN"} if serverName == "default" {
row = []string{serverName, "local"}
} else {
row = []string{serverName, "unknown"}
}
} }
table.Append(row) table.Append(row)
} }

View File

@ -3,18 +3,20 @@ package compose
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
"coopcloud.tech/abra/pkg/client/stack" "coopcloud.tech/abra/pkg/client/stack"
loader "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" composetypes "github.com/docker/cli/cli/compose/types"
"github.com/docker/distribution/reference" "github.com/docker/distribution/reference"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
// UpdateTag updates an image tag in-place on file system local compose files. // 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) composeFiles, err := filepath.Glob(pattern)
if err != nil { if err != nil {
return err return err
@ -24,8 +26,14 @@ func UpdateTag(pattern, image, tag string) error {
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)
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 { if err != nil {
return err 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. // 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) composeFiles, err := filepath.Glob(pattern)
if err != nil { if err != nil {
return err return err
@ -84,8 +92,14 @@ func UpdateLabel(pattern, serviceName, label string) error {
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)
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 { if err != nil {
return err return err
} }

View File

@ -26,7 +26,7 @@ type Recipe struct {
// UpdateLabel updates a recipe label // UpdateLabel updates a recipe label
func (r Recipe) UpdateLabel(serviceName, label string) error { func (r Recipe) UpdateLabel(serviceName, label string) error {
pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, r.Name) 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 err
} }
return nil return nil
@ -35,7 +35,7 @@ func (r Recipe) UpdateLabel(serviceName, label string) error {
// UpdateTag updates a recipe tag // UpdateTag updates a recipe tag
func (r Recipe) UpdateTag(image, tag string) error { func (r Recipe) UpdateTag(image, tag string) error {
pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, r.Name) 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 err
} }
return nil return nil

24
pkg/server/server.go Normal file
View 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
}

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/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" ABRA_RELEASE_URL="https://git.coopcloud.tech/api/v1/repos/coop-cloud/abra/releases/tags/$ABRA_VERSION"
function show_banner { function show_banner {

View File