Compare commits
1 Commits
0.5.1-beta
...
fix-branch
Author | SHA1 | Date | |
---|---|---|---|
552ee5bbd9 |
@ -3,17 +3,17 @@ kind: pipeline
|
||||
name: coopcloud.tech/abra
|
||||
steps:
|
||||
- name: make check
|
||||
image: golang:1.19
|
||||
image: golang:1.18
|
||||
commands:
|
||||
- make check
|
||||
|
||||
- name: make build
|
||||
image: golang:1.19
|
||||
image: golang:1.18
|
||||
commands:
|
||||
- make build
|
||||
|
||||
- name: make test
|
||||
image: golang:1.19
|
||||
image: golang:1.18
|
||||
commands:
|
||||
- make test
|
||||
|
||||
@ -45,7 +45,7 @@ steps:
|
||||
event: tag
|
||||
|
||||
- name: release
|
||||
image: golang:1.19
|
||||
image: golang:1.18
|
||||
environment:
|
||||
GITEA_TOKEN:
|
||||
from_secret: goreleaser_gitea_token
|
||||
|
@ -39,10 +39,8 @@ changelog:
|
||||
sort: desc
|
||||
filters:
|
||||
exclude:
|
||||
- "^Merge"
|
||||
- "^Revert"
|
||||
- "^WIP:"
|
||||
- "^style:"
|
||||
- "^test:"
|
||||
- "^tests:"
|
||||
- "^chore:"
|
||||
- "^Revert"
|
||||
|
@ -1,11 +1,10 @@
|
||||
# authors
|
||||
|
||||
> 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:
|
||||
> 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
|
||||
|
||||
- 3wordchant
|
||||
- decentral1se
|
||||
- frando
|
||||
- kawaiipunk
|
||||
- knoflook
|
||||
- roxxers
|
||||
|
@ -25,6 +25,21 @@ import (
|
||||
"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{
|
||||
Name: "command",
|
||||
Aliases: []string{"cmd"},
|
||||
@ -41,23 +56,21 @@ Example:
|
||||
|
||||
abra app cmd example.com app create_user -- me@example.com
|
||||
`,
|
||||
ArgsUsage: "<domain> [<service>] <command> [-- <args>]",
|
||||
ArgsUsage: "<domain> [<service>] <command>",
|
||||
Flags: []cli.Flag{
|
||||
internal.DebugFlag,
|
||||
internal.LocalCmdFlag,
|
||||
internal.RemoteUserFlag,
|
||||
localCmdFlag,
|
||||
remoteUserFlag,
|
||||
},
|
||||
BashComplete: autocomplete.AppNameComplete,
|
||||
Before: internal.SubCommandBefore,
|
||||
Action: func(c *cli.Context) error {
|
||||
app := internal.ValidateApp(c)
|
||||
|
||||
if internal.LocalCmd && internal.RemoteUser != "" {
|
||||
internal.ShowSubcommandHelpAndError(c, errors.New("cannot use --local & --user together"))
|
||||
if localCmd && remoteUser != "" {
|
||||
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")
|
||||
if _, err := os.Stat(abraSh); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
@ -66,7 +79,21 @@ Example:
|
||||
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)
|
||||
if err := ensureCommand(abraSh, app.Recipe, cmdName); err != nil {
|
||||
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 {
|
||||
bytes, err := ioutil.ReadFile(abraSh)
|
||||
if err != nil {
|
||||
@ -206,9 +214,9 @@ func runCmdRemote(app config.App, abraSh, serviceName, cmdName, cmdArgs string)
|
||||
Tty: true,
|
||||
}
|
||||
|
||||
if internal.RemoteUser != "" {
|
||||
logrus.Debugf("running command with user %s", internal.RemoteUser)
|
||||
execCreateOpts.User = internal.RemoteUser
|
||||
if remoteUser != "" {
|
||||
logrus.Debugf("running command with user %s", remoteUser)
|
||||
execCreateOpts.User = remoteUser
|
||||
}
|
||||
|
||||
// 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,
|
||||
}
|
||||
|
||||
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
|
||||
var SSHFailMsg = `
|
||||
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
|
||||
func EnsureDomainsResolveSameIPv4(domainName, server string) (string, error) {
|
||||
if server == "default" || server == "local" {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
var ipv4 string
|
||||
|
||||
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",
|
||||
"ignoreDeps": [
|
||||
"github.com/urfave/cli"
|
||||
]
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||
}
|
||||
|
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
|
||||
|
||||
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() {
|
||||
ABRA="$(pwd)/../../abra"
|
||||
INSTALLER_URL="https://git.coopcloud.tech/coop-cloud/abra/raw/branch/main/scripts/installer/installer"
|
||||
|
@ -16,7 +16,7 @@ run_test () {
|
||||
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
|
||||
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