Compare commits
1 Commits
0.5.1-beta
...
fix-branch
Author | SHA1 | Date | |
---|---|---|---|
552ee5bbd9 |
@ -3,17 +3,17 @@ kind: pipeline
|
|||||||
name: coopcloud.tech/abra
|
name: coopcloud.tech/abra
|
||||||
steps:
|
steps:
|
||||||
- name: make check
|
- name: make check
|
||||||
image: golang:1.19
|
image: golang:1.18
|
||||||
commands:
|
commands:
|
||||||
- make check
|
- make check
|
||||||
|
|
||||||
- name: make build
|
- name: make build
|
||||||
image: golang:1.19
|
image: golang:1.18
|
||||||
commands:
|
commands:
|
||||||
- make build
|
- make build
|
||||||
|
|
||||||
- name: make test
|
- name: make test
|
||||||
image: golang:1.19
|
image: golang:1.18
|
||||||
commands:
|
commands:
|
||||||
- make test
|
- make test
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ steps:
|
|||||||
event: tag
|
event: tag
|
||||||
|
|
||||||
- name: release
|
- name: release
|
||||||
image: golang:1.19
|
image: golang:1.18
|
||||||
environment:
|
environment:
|
||||||
GITEA_TOKEN:
|
GITEA_TOKEN:
|
||||||
from_secret: goreleaser_gitea_token
|
from_secret: goreleaser_gitea_token
|
||||||
|
@ -39,10 +39,8 @@ changelog:
|
|||||||
sort: desc
|
sort: desc
|
||||||
filters:
|
filters:
|
||||||
exclude:
|
exclude:
|
||||||
- "^Merge"
|
|
||||||
- "^Revert"
|
|
||||||
- "^WIP:"
|
- "^WIP:"
|
||||||
- "^style:"
|
- "^style:"
|
||||||
- "^test:"
|
- "^test:"
|
||||||
- "^tests:"
|
- "^tests:"
|
||||||
- "^chore:"
|
- "^Revert"
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
# authors
|
# authors
|
||||||
|
|
||||||
> If you're looking at this and you hack on `abra` and you're not listed here,
|
> If you're looking at this and you hack on Abra and you're not listed here,
|
||||||
> please do add yourself! This is a community project, let's show some :heart:
|
> please do add yourself! This is a community project, let's show
|
||||||
|
|
||||||
- 3wordchant
|
- 3wordchant
|
||||||
- decentral1se
|
- decentral1se
|
||||||
- frando
|
|
||||||
- kawaiipunk
|
- kawaiipunk
|
||||||
- knoflook
|
- knoflook
|
||||||
- roxxers
|
- roxxers
|
||||||
|
@ -25,6 +25,21 @@ import (
|
|||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var localCmd bool
|
||||||
|
var localCmdFlag = &cli.BoolFlag{
|
||||||
|
Name: "local, l",
|
||||||
|
Usage: "Run command locally",
|
||||||
|
Destination: &localCmd,
|
||||||
|
}
|
||||||
|
|
||||||
|
var remoteUser string
|
||||||
|
var remoteUserFlag = &cli.StringFlag{
|
||||||
|
Name: "user, u",
|
||||||
|
Value: "",
|
||||||
|
Usage: "User to run command within a service context",
|
||||||
|
Destination: &remoteUser,
|
||||||
|
}
|
||||||
|
|
||||||
var appCmdCommand = cli.Command{
|
var appCmdCommand = cli.Command{
|
||||||
Name: "command",
|
Name: "command",
|
||||||
Aliases: []string{"cmd"},
|
Aliases: []string{"cmd"},
|
||||||
@ -41,23 +56,21 @@ Example:
|
|||||||
|
|
||||||
abra app cmd example.com app create_user -- me@example.com
|
abra app cmd example.com app create_user -- me@example.com
|
||||||
`,
|
`,
|
||||||
ArgsUsage: "<domain> [<service>] <command> [-- <args>]",
|
ArgsUsage: "<domain> [<service>] <command>",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
internal.DebugFlag,
|
internal.DebugFlag,
|
||||||
internal.LocalCmdFlag,
|
localCmdFlag,
|
||||||
internal.RemoteUserFlag,
|
remoteUserFlag,
|
||||||
},
|
},
|
||||||
BashComplete: autocomplete.AppNameComplete,
|
BashComplete: autocomplete.AppNameComplete,
|
||||||
Before: internal.SubCommandBefore,
|
Before: internal.SubCommandBefore,
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
app := internal.ValidateApp(c)
|
app := internal.ValidateApp(c)
|
||||||
|
|
||||||
if internal.LocalCmd && internal.RemoteUser != "" {
|
if localCmd && remoteUser != "" {
|
||||||
internal.ShowSubcommandHelpAndError(c, errors.New("cannot use --local & --user together"))
|
internal.ShowSubcommandHelpAndError(c, errors.New("cannot use --local & <user> together"))
|
||||||
}
|
}
|
||||||
|
|
||||||
hasCmdArgs, parsedCmdArgs := parseCmdArgs(c.Args(), internal.LocalCmd)
|
|
||||||
|
|
||||||
abraSh := path.Join(config.RECIPES_DIR, app.Recipe, "abra.sh")
|
abraSh := path.Join(config.RECIPES_DIR, app.Recipe, "abra.sh")
|
||||||
if _, err := os.Stat(abraSh); err != nil {
|
if _, err := os.Stat(abraSh); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
@ -66,7 +79,21 @@ Example:
|
|||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if internal.LocalCmd {
|
var parsedCmdArgs string
|
||||||
|
var cmdArgsIdx int
|
||||||
|
var hasCmdArgs bool
|
||||||
|
for idx, arg := range c.Args() {
|
||||||
|
if arg == "--" {
|
||||||
|
cmdArgsIdx = idx
|
||||||
|
hasCmdArgs = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if hasCmdArgs && idx > cmdArgsIdx {
|
||||||
|
parsedCmdArgs += fmt.Sprintf("%s ", c.Args().Get(idx))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if localCmd {
|
||||||
cmdName := c.Args().Get(1)
|
cmdName := c.Args().Get(1)
|
||||||
if err := ensureCommand(abraSh, app.Recipe, cmdName); err != nil {
|
if err := ensureCommand(abraSh, app.Recipe, cmdName); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
@ -129,25 +156,6 @@ Example:
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCmdArgs(args []string, isLocal bool) (bool, string) {
|
|
||||||
var (
|
|
||||||
parsedCmdArgs string
|
|
||||||
hasCmdArgs bool
|
|
||||||
)
|
|
||||||
|
|
||||||
if isLocal {
|
|
||||||
if len(args) > 2 {
|
|
||||||
return true, fmt.Sprintf("%s ", strings.Join(args[2:], " "))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if len(args) > 3 {
|
|
||||||
return true, fmt.Sprintf("%s ", strings.Join(args[3:], " "))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasCmdArgs, parsedCmdArgs
|
|
||||||
}
|
|
||||||
|
|
||||||
func ensureCommand(abraSh, recipeName, execCmd string) error {
|
func ensureCommand(abraSh, recipeName, execCmd string) error {
|
||||||
bytes, err := ioutil.ReadFile(abraSh)
|
bytes, err := ioutil.ReadFile(abraSh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -206,9 +214,9 @@ func runCmdRemote(app config.App, abraSh, serviceName, cmdName, cmdArgs string)
|
|||||||
Tty: true,
|
Tty: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
if internal.RemoteUser != "" {
|
if remoteUser != "" {
|
||||||
logrus.Debugf("running command with user %s", internal.RemoteUser)
|
logrus.Debugf("running command with user %s", remoteUser)
|
||||||
execCreateOpts.User = internal.RemoteUser
|
execCreateOpts.User = remoteUser
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: avoid instantiating a new CLI
|
// FIXME: avoid instantiating a new CLI
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestParseCmdArgs(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
input []string
|
|
||||||
shouldParse bool
|
|
||||||
expectedOutput string
|
|
||||||
}{
|
|
||||||
// `--` is not parsed when passed in from the command-line e.g. -- foo bar baz
|
|
||||||
// so we need to eumlate that as missing when testing if bash args are passed in
|
|
||||||
// see https://git.coopcloud.tech/coop-cloud/organising/issues/336 for more
|
|
||||||
{[]string{"foo.com", "app", "test"}, false, ""},
|
|
||||||
{[]string{"foo.com", "app", "test", "foo"}, true, "foo "},
|
|
||||||
{[]string{"foo.com", "app", "test", "foo", "bar", "baz"}, true, "foo bar baz "},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
ok, parsed := parseCmdArgs(test.input, false)
|
|
||||||
if ok != test.shouldParse {
|
|
||||||
t.Fatalf("[%s] should not parse", strings.Join(test.input, " "))
|
|
||||||
}
|
|
||||||
if parsed != test.expectedOutput {
|
|
||||||
t.Fatalf("%s does not match %s", parsed, test.expectedOutput)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -353,21 +353,6 @@ var AllTagsFlag = &cli.BoolFlag{
|
|||||||
Destination: &AllTags,
|
Destination: &AllTags,
|
||||||
}
|
}
|
||||||
|
|
||||||
var LocalCmd bool
|
|
||||||
var LocalCmdFlag = &cli.BoolFlag{
|
|
||||||
Name: "local, l",
|
|
||||||
Usage: "Run command locally",
|
|
||||||
Destination: &LocalCmd,
|
|
||||||
}
|
|
||||||
|
|
||||||
var RemoteUser string
|
|
||||||
var RemoteUserFlag = &cli.StringFlag{
|
|
||||||
Name: "user, u",
|
|
||||||
Value: "",
|
|
||||||
Usage: "User to run command within a service context",
|
|
||||||
Destination: &RemoteUser,
|
|
||||||
}
|
|
||||||
|
|
||||||
// SSHFailMsg is a hopefully helpful SSH failure message
|
// SSHFailMsg is a hopefully helpful SSH failure message
|
||||||
var SSHFailMsg = `
|
var SSHFailMsg = `
|
||||||
Woops, Abra is unable to connect to connect to %s.
|
Woops, Abra is unable to connect to connect to %s.
|
||||||
|
@ -65,10 +65,6 @@ func EnsureIPv4(domainName string) (string, error) {
|
|||||||
|
|
||||||
// EnsureDomainsResolveSameIPv4 ensures that domains resolve to the same ipv4 address
|
// EnsureDomainsResolveSameIPv4 ensures that domains resolve to the same ipv4 address
|
||||||
func EnsureDomainsResolveSameIPv4(domainName, server string) (string, error) {
|
func EnsureDomainsResolveSameIPv4(domainName, server string) (string, error) {
|
||||||
if server == "default" || server == "local" {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var ipv4 string
|
var ipv4 string
|
||||||
|
|
||||||
domainIPv4, err := EnsureIPv4(domainName)
|
domainIPv4, err := EnsureIPv4(domainName)
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
package test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RmServerAppRecipe deletes the test server / app / recipe.
|
|
||||||
func RmServerAppRecipe() {
|
|
||||||
testAppLink := os.ExpandEnv("$HOME/.abra/servers/foo.com")
|
|
||||||
if err := os.Remove(testAppLink); err != nil {
|
|
||||||
logrus.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
testRecipeLink := os.ExpandEnv("$HOME/.abra/recipes/test")
|
|
||||||
if err := os.Remove(testRecipeLink); err != nil {
|
|
||||||
logrus.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MkServerAppRecipe symlinks the test server / app / recipe.
|
|
||||||
func MkServerAppRecipe() {
|
|
||||||
RmServerAppRecipe()
|
|
||||||
|
|
||||||
testAppDir := os.ExpandEnv("$PWD/../../tests/resources/testapp")
|
|
||||||
testAppLink := os.ExpandEnv("$HOME/.abra/servers/foo.com")
|
|
||||||
if err := os.Symlink(testAppDir, testAppLink); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
testRecipeDir := os.ExpandEnv("$PWD/../../tests/resources/testrecipe")
|
|
||||||
testRecipeLink := os.ExpandEnv("$HOME/.abra/recipes/test")
|
|
||||||
if err := os.Symlink(testRecipeDir, testRecipeLink); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,3 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||||
"ignoreDeps": [
|
|
||||||
"github.com/urfave/cli"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
1
tests/integration/.gitignore
vendored
1
tests/integration/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
logs
|
|
@ -1,14 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
source ./testfunctions.sh
|
|
||||||
source ./common.sh
|
|
||||||
|
|
||||||
create_server_app_recipe
|
|
||||||
|
|
||||||
run_test '$ABRA app cmd foo.com test --local'
|
|
||||||
|
|
||||||
run_test '$ABRA app cmd foo.com test --local -- foo'
|
|
||||||
|
|
||||||
run_test '$ABRA app cmd foo.com test --local -- foo bar baz'
|
|
||||||
|
|
||||||
clean_server_app_recipe
|
|
@ -2,16 +2,6 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
create_server_app_recipe() {
|
|
||||||
ln -srf ../resources/testapp ~/.abra/servers/foo.com
|
|
||||||
ln -srf ../resources/testrecipe ~/.abra/recipes
|
|
||||||
}
|
|
||||||
|
|
||||||
clean_server_app_recipe() {
|
|
||||||
unlink ~/.abra/servers/foo.com
|
|
||||||
unlink ~/.abra/recipes/testrecipe
|
|
||||||
}
|
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
ABRA="$(pwd)/../../abra"
|
ABRA="$(pwd)/../../abra"
|
||||||
INSTALLER_URL="https://git.coopcloud.tech/coop-cloud/abra/raw/branch/main/scripts/installer/installer"
|
INSTALLER_URL="https://git.coopcloud.tech/coop-cloud/abra/raw/branch/main/scripts/installer/installer"
|
||||||
|
@ -16,7 +16,7 @@ run_test () {
|
|||||||
echo $logfile
|
echo $logfile
|
||||||
}
|
}
|
||||||
|
|
||||||
testScripts=("app.sh" "autocomplete.sh" "catalogue.sh" "install.sh" "recipe.sh" "records.sh" "server.sh", "cmd.sh")
|
testScripts=("app.sh" "autocomplete.sh" "catalogue.sh" "install.sh" "recipe.sh" "records.sh" "server.sh")
|
||||||
|
|
||||||
for i in "${testScripts[@]}"; do
|
for i in "${testScripts[@]}"; do
|
||||||
cmd="./$i $res_dir${i/sh/log}"
|
cmd="./$i $res_dir${i/sh/log}"
|
||||||
|
@ -1 +0,0 @@
|
|||||||
TYPE=test
|
|
@ -1 +0,0 @@
|
|||||||
.
|
|
@ -1,5 +0,0 @@
|
|||||||
test(){
|
|
||||||
echo "1: $1"
|
|
||||||
echo "2: $2"
|
|
||||||
echo "all: $@"
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
version: "3.8"
|
|
||||||
|
|
||||||
services:
|
|
||||||
app: []
|
|
Reference in New Issue
Block a user