This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
85 changed files
with
5,438 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# .github/workflows/release.yaml | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
permissions: | ||
contents: write | ||
packages: write | ||
|
||
jobs: | ||
releases-matrix: | ||
name: Release Go Binary | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
goos: [linux] | ||
goarch: [amd64, arm64] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: wangyoucao577/go-release-action@v1 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
goos: ${{ matrix.goos }} | ||
goarch: ${{ matrix.goarch }} | ||
binary_name: "jumpstarter" | ||
extra_files: LICENSE README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
VERSION := $(shell git describe --tags --always) | ||
LDFLAGS := -ldflags="-X 'github.com/jumpstarter-dev/jumpstarter/cmd.VERSION=${VERSION}'" | ||
|
||
jumpstarter: main.go pkg/drivers/dutlink-board/*.go pkg/runner/* pkg/harness/*.go cmd/*.go pkg/tools/*.go pkg/drivers/sd-wire/*.go pkg/console/*.go | ||
go build ${LDFLAGS} | ||
|
||
containers: | ||
podman build ./containers/ -f Containerfile -t quay.io/mangelajo/jumpstarter:latest | ||
podman build ./containers/ -f Containerfile.guestfs -t quay.io/mangelajo/guestfs-tools:latest | ||
|
||
push-containers: containers | ||
podman push quay.io/mangelajo/jumpstarter:latest | ||
podman push quay.io/mangelajo/guestfs-tools:latest | ||
|
||
fmt: | ||
gofmt -w -s . | ||
|
||
all: jumpstarter | ||
|
||
.PHONY: all fmt containers push-containers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright © 2023 Miguel Angel Ajo Pelayo <[email protected] | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/fatih/color" | ||
"github.com/jumpstarter-dev/jumpstarter/pkg/harness" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// powerCmd represents the listDevices command | ||
var attachStorage = &cobra.Command{ | ||
Use: "attach-storage", | ||
Short: "Attaches storage to the device", | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil { | ||
handleErrorAsFatal(err) | ||
} | ||
|
||
driver := cmd.Flag("driver").Value.String() | ||
device, err := harness.FindDevice(driver, args[0]) | ||
handleErrorAsFatal(err) | ||
color.Set(COLOR_CMD_INFO) | ||
fmt.Printf("💾 Attaching storage for %s ... ", args[0]) | ||
color.Unset() | ||
|
||
err = device.AttachStorage(false) | ||
handleErrorAsFatal(err) | ||
time.Sleep(2 * time.Second) // detach/attach cycle to power cycle | ||
err = device.AttachStorage(true) | ||
handleErrorAsFatal(err) | ||
color.Set(COLOR_CMD_INFO) | ||
fmt.Println("done") | ||
color.Unset() | ||
|
||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(attachStorage) | ||
attachStorage.Flags().StringP("driver", "d", "", "Only list devices for the specified driver") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
Copyright © 2023 Miguel Angel Ajo Pelayo <[email protected] | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/fatih/color" | ||
"github.com/jumpstarter-dev/jumpstarter/pkg/harness" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/term" | ||
) | ||
|
||
// powerCmd represents the listDevices command | ||
var consoleCmd = &cobra.Command{ | ||
Use: "console", | ||
Short: "Console output from a device", | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil { | ||
handleErrorAsFatal(err) | ||
} | ||
|
||
driver := cmd.Flag("driver").Value.String() | ||
device, err := harness.FindDevice(driver, args[0]) | ||
handleErrorAsFatal(err) | ||
|
||
serialConsole(device) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(consoleCmd) | ||
consoleCmd.Flags().StringP("driver", "d", "", "Only devices for the specified driver") | ||
} | ||
|
||
func serialConsole(device harness.Device) { | ||
serial, err := device.Console() | ||
handleErrorAsFatal(err) | ||
defer serial.Close() | ||
|
||
color.Set(COLOR_CMD_INFO) | ||
fmt.Println("💻 Entering console: Press Ctrl-B 3 times to exit console") | ||
color.Unset() | ||
runConsole(serial) | ||
} | ||
|
||
func runConsole(serial io.ReadWriteCloser) { | ||
for { | ||
oldState, err := term.MakeRaw(int(os.Stdin.Fd())) | ||
if err != nil { | ||
handleErrorAsFatal(err) | ||
} | ||
defer func() { | ||
term.Restore(int(os.Stdin.Fd()), oldState) | ||
// reset terminal and clear screen | ||
fmt.Print("\033c\033[2J\033[H") | ||
|
||
}() | ||
// TODO: this will result in the output of the serial console exit command | ||
// we need to control console via DTR instead | ||
go io.Copy(os.Stdout, serial) | ||
ctrlBCount := 0 | ||
for { | ||
var b []byte = make([]byte, 1) | ||
_, err := os.Stdin.Read(b) | ||
if err != nil { | ||
handleErrorAsFatal(err) | ||
} | ||
if b[0] == 2 { | ||
ctrlBCount++ | ||
if ctrlBCount == 3 { | ||
return | ||
} | ||
} else { | ||
ctrlBCount = 0 | ||
} | ||
serial.Write(b) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright © 2023 Miguel Angel Ajo Pelayo <[email protected] | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/jumpstarter-dev/jumpstarter/pkg/harness" | ||
"github.com/jumpstarter-dev/jumpstarter/pkg/tools" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// powerCmd represents the listDevices command | ||
var createAnsibleInventory = &cobra.Command{ | ||
Use: "create-ansible-inventory", | ||
Short: "Create an ansible inventory file", | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil { | ||
handleErrorAsFatal(err) | ||
} | ||
|
||
driver := cmd.Flag("driver").Value.String() | ||
user := cmd.Flag("user").Value.String() | ||
sshKey := cmd.Flag("ssh-key").Value.String() | ||
|
||
device, err := harness.FindDevice(driver, args[0]) | ||
handleErrorAsFatal(err) | ||
err = tools.CreateAnsibleInventory(device, os.Stdout, user, sshKey) | ||
handleErrorAsFatal(err) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(createAnsibleInventory) | ||
createAnsibleInventory.Flags().StringP("driver", "d", "", "Only devices for the specified driver") | ||
createAnsibleInventory.Flags().StringP("user", "u", "root", "The user for the ansible inventory file") | ||
createAnsibleInventory.Flags().StringP("ssh-key", "k", "", "The ssh key to use for the ansible inventory file") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright © 2023 Miguel Angel Ajo Pelayo <[email protected] | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/fatih/color" | ||
"github.com/jumpstarter-dev/jumpstarter/pkg/harness" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// powerCmd represents the listDevices command | ||
var detachStorage = &cobra.Command{ | ||
Use: "detach-storage", | ||
Short: "Detaches storage from the device", | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil { | ||
handleErrorAsFatal(err) | ||
} | ||
|
||
driver := cmd.Flag("driver").Value.String() | ||
device, err := harness.FindDevice(driver, args[0]) | ||
handleErrorAsFatal(err) | ||
|
||
color.Set(COLOR_CMD_INFO) | ||
fmt.Printf("💾 Detaching storage for %s ... ", args[0]) | ||
color.Unset() | ||
|
||
err = device.AttachStorage(false) | ||
handleErrorAsFatal(err) | ||
|
||
color.Set(COLOR_CMD_INFO) | ||
fmt.Println("done") | ||
color.Unset() | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(detachStorage) | ||
detachStorage.Flags().StringP("driver", "d", "", "Only list devices for the specified driver") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright © 2023 Miguel Angel Ajo Pelayo <[email protected] | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/fatih/color" | ||
"github.com/jumpstarter-dev/jumpstarter/pkg/harness" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// powerCmd represents the listDevices command | ||
var getConfig = &cobra.Command{ | ||
Use: "get-config", | ||
Short: "Changes a device config parameter", | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil { | ||
handleErrorAsFatal(err) | ||
} | ||
|
||
device_id := args[0] | ||
k := "" | ||
if len(args) > 1 { | ||
k = strings.ToLower(args[1]) | ||
} | ||
|
||
driver := cmd.Flag("driver").Value.String() | ||
device, err := harness.FindDevice(driver, device_id) | ||
handleErrorAsFatal(err) | ||
|
||
cfg, err := device.GetConfig() | ||
|
||
handleErrorAsFatal(err) | ||
|
||
if k != "" { | ||
if v, ok := cfg[k]; ok { | ||
fmt.Println(v) | ||
} else { | ||
color.Set(color.FgRed) | ||
fmt.Println("Not found") | ||
color.Unset() | ||
os.Exit(1) | ||
} | ||
} else { | ||
for k, v := range cfg { | ||
fmt.Printf("%s: %s\n", k, v) | ||
} | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(getConfig) | ||
getConfig.Flags().StringP("driver", "d", "", "Only list devices for the specified driver") | ||
} |
Oops, something went wrong.