Skip to content

Commit

Permalink
quick fix
Browse files Browse the repository at this point in the history
  • Loading branch information
NorseGaud committed Apr 4, 2024
1 parent 9b3fe71 commit c248248
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.rdb
anklet.yaml
config.y*
dist
27 changes: 12 additions & 15 deletions internal/anka/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"encoding/json"
"fmt"
"log/slog"
"os"
"os/exec"
"path/filepath"
"sync"
"time"

Expand All @@ -23,7 +23,6 @@ type AnkaJson struct {
}

type Cli struct {
Plugin string
License struct {
Product string
LicenseType string
Expand All @@ -42,8 +41,6 @@ func GetAnkaCLIFromContext(ctx context.Context) *Cli {
}

func NewCLI(ctx context.Context) (*Cli, error) {
service := config.GetServiceFromContext(ctx)

cli := &Cli{}

cmd := exec.Command("anka")
Expand Down Expand Up @@ -78,9 +75,6 @@ func NewCLI(ctx context.Context) (*Cli, error) {
return nil, fmt.Errorf("anka license type is not supported %+v", license.Body)
}

// do not set anything plugin specific in here
cli.Plugin = service.Plugin

return cli, nil
}

Expand Down Expand Up @@ -171,8 +165,9 @@ func (cli *Cli) AnkaRegistryPull(ctx context.Context, template string, tag strin

func (cli *Cli) AnkaDelete(ctx context.Context, vm *VM) error {
logger := logging.GetLoggerFromContext(ctx)
deleteOutput, err := cli.ExecuteParseJson(ctx, "anka", "delete", "--yes", vm.Name)
deleteOutput, err := cli.ExecuteParseJson(ctx, "anka", "-j", "delete", "--yes", vm.Name)
if err != nil {
logger.ErrorContext(ctx, "error executing anka delete", "err", err)
return err
}
logger.DebugContext(ctx, "successfully deleted vm", "std", deleteOutput.Message)
Expand Down Expand Up @@ -247,19 +242,21 @@ func (cli *Cli) AnkaCopy(ctx context.Context, filesToCopyIn ...string) error {
}
logger := logging.GetLoggerFromContext(ctx)
vm := GetAnkaVmFromContext(ctx)
rootDir, err := os.Getwd()
if err != nil {
return err
}
for _, file := range filesToCopyIn {
copyOutput, err := cli.ExecuteParseJson(ctx, "anka", "-j", "cp", "-a", fmt.Sprintf("%s/plugins/%s/%s", rootDir, cli.Plugin, file), fmt.Sprintf("%s:", vm.Name))
for _, hostLevelFile := range filesToCopyIn {
// handle symlinks
realPath, err := filepath.EvalSymlinks(hostLevelFile)
if err != nil {
return fmt.Errorf("error evaluating symlink for %s: %w", hostLevelFile, err)
}
hostLevelFile = realPath
copyOutput, err := cli.ExecuteParseJson(ctx, "anka", "-j", "cp", "-a", hostLevelFile, fmt.Sprintf("%s:", vm.Name))
if err != nil {
return err
}
if copyOutput.Status != "OK" {
return fmt.Errorf("error copying into vm: %s", copyOutput.Message)
}
logger.DebugContext(ctx, "successfully copied file into vm", "file", file)
logger.DebugContext(ctx, "successfully copied file into vm", "file", hostLevelFile)
}

return nil
Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func main() {
if err != nil {
panic(fmt.Sprintf("unable to create anka cli: %v", err))
}
ankaCLI.Plugin = service.Plugin

serviceCtx = context.WithValue(serviceCtx, config.ContextKey("ankacli"), ankaCLI)

Expand Down
7 changes: 4 additions & 3 deletions plugins/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,15 @@ func Run(ctx context.Context, logger *slog.Logger) {
globals := config.GetGlobalsFromContext(ctx)
logger.InfoContext(ctx, "installing github runner inside of vm")
err = ankaCLI.AnkaCopy(ctx,
globals.PluginsPath+"github/install-runner.bash",
globals.PluginsPath+"github/register-runner.bash",
globals.PluginsPath+"github/start-runner.bash",
globals.PluginsPath+"/github/install-runner.bash",
globals.PluginsPath+"/github/register-runner.bash",
globals.PluginsPath+"/github/start-runner.bash",
)
if err != nil {
logger.ErrorContext(ctx, "error executing anka copy", "err", err)
return
}

ankRunScriptOutput, err := ankaCLI.ExecuteAndParseJsonOnError(ctx,
"anka", "-j", "run", vm.Name, "./install-runner.bash",
)
Expand Down

0 comments on commit c248248

Please sign in to comment.