Skip to content

Commit

Permalink
add version command; fix get_server etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Anni committed Jan 31, 2025
1 parent 9f1721a commit 983fcbd
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ before:
builds:
- env:
- CGO_ENABLED=0
ldflags:
- -s -w -trimpath
- -X {{ .ModulePath }}/internal/version.Version={{.Version}}
- -X {{ .ModulePath }}/internal/version.Commit={{.Commit}}
- -X {{ .ModulePath }}/internal/version.Date={{.Date}}
- -X {{ .ModulePath }}/internal/version.GoVersion={{.GoVersion}}
goos:
- linux
- darwin
Expand Down
2 changes: 1 addition & 1 deletion cmd/delete_lab.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewDeleteLabCmd() *cobra.Command {
}
// Delete the lab using lab manager
if err := labSvc.Delete(labName, skipTimeCheck); err != nil {
return fmt.Errorf("failed to delete lab: %w", err)
return fmt.Errorf("error deleting lab: %w", err)
}

fmt.Printf("Successfully deleted lab %s\n", labName)
Expand Down
8 changes: 8 additions & 0 deletions cmd/get_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func NewGetKeyCmd() *cobra.Command {
}

func listKeys() error {
err := initProvider(useProvider)
if err != nil {
return err
}
keys, err := providerSvc.AllSSHKeys()
if err != nil {
return err
Expand Down Expand Up @@ -55,6 +59,10 @@ func listKeys() error {
}

func getKey(name string) error {
err := initProvider(useProvider)
if err != nil {
return err
}
key, err := providerSvc.GetSSHKey(name)
if err != nil {
return err
Expand Down
6 changes: 4 additions & 2 deletions cmd/get_lab.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ func getLab(labName string) error {
if err != nil {
return err
}
initLabManager()
fmt.Printf("Getting details for lab: %s\n", labName)
err = initLabManager()
if err != nil {
return err
}
lab, err := labSvc.Get(labName)
if err != nil {
return err
Expand Down
8 changes: 8 additions & 0 deletions cmd/get_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func NewGetServerCmd() *cobra.Command {
}

func listServers() error {
err := initProvider(useProvider)
if err != nil {
return err
}
servers, err := providerSvc.AllServers()
if err != nil {
return err
Expand All @@ -52,6 +56,10 @@ func listServers() error {
}

func getServer(serverID string) error {
err := initProvider(useProvider)
if err != nil {
return err
}
server, err := providerSvc.GetServer(serverID)
if err != nil {
return err
Expand Down
8 changes: 8 additions & 0 deletions cmd/get_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func NewGetVolumeCmd() *cobra.Command {
}

func listVolumes() error {
err := initProvider(useProvider)
if err != nil {
return err
}
volumes, err := providerSvc.AllVolumes()
if err != nil {
return err
Expand All @@ -53,6 +57,10 @@ func listVolumes() error {
}

func getVolume(volumeID string) error {
err := initProvider(useProvider)
if err != nil {
return err
}
volume, err := providerSvc.GetVolume(volumeID)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func NewRootCmd() *cobra.Command {
NewConfigCmd(),
NewCreateCmd(),
NewSyncCmd(),
NewVersionCmd(),
)

return cmd
Expand Down
23 changes: 23 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"fmt"
"runtime"

"github.com/pavelanni/storctl/internal/version"
"github.com/spf13/cobra"
)

func NewVersionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Print version information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Version: %s\n", version.Version)
fmt.Printf("Commit: %s\n", version.Commit)
fmt.Printf("Build Date: %s\n", version.Date)
fmt.Printf("Go Version: %s\n", version.GoVersion)
fmt.Printf("OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
},
}
}
47 changes: 47 additions & 0 deletions docs/adr/0010-using-limactl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Using limactl

## Status

Accepted

## Date

2024-01-29

## Context

- Need to work with virtual machines on a macOS or Linux host
- Lima is a tool of choice on macOS and also available on Linux
- Lima can use QEMU as a backend virtualization engine
- Lima is written in Go
- There is an option to use Lima's Go library or use the CLI tool `limactl` from inside our Go code
- There is also Colima that is a wrapper for Lima but it uses Docker instead of `containerd` as a containerization engine

## Decision

Use `limactl` CLI calls from inside Go code.

1. The Go library used by Lima developers is not created for external consumption.
To use it we would have to go deep into its ecosystem and import a lot of other dependencies.

2. The CLI interface is more stable so we are more safe in this case.

3. In our case, performance is not a significant factor, so there is not much gain in using the native Go library.

## Consequences

### Positive

- More stable interface
- Fewer imports/dependencies

### Negative

- Need to parse the command JSON output
- Slightly lower performance (but not visible by the end user)

## Related Decisions


## Notes

2 changes: 0 additions & 2 deletions internal/lab/lab.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ func (m *ManagerSvc) createLabLima(lab *types.Lab) error {
Format: false,
})
}
// DEBUG
fmt.Printf("Additional disks: %v\n", additionalDisks)
specServers := lab.Spec.Servers
for _, serverSpec := range specServers {
s := &types.Server{
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/lima/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func createVM(ctx context.Context, name, configPath string) error {
if ctx.Err() == context.DeadlineExceeded {
return fmt.Errorf("timeout while creating VM: %w", err)
}
return fmt.Errorf("creating VM: %w", err)
return fmt.Errorf("error creating VM: %w", err)
}

fmt.Printf("Successfully created VM %s\n", name)
Expand Down
8 changes: 8 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package version

var (
Version = "dev"
Commit = "none"
Date = "unknown"
GoVersion = "unknown"
)

0 comments on commit 983fcbd

Please sign in to comment.