mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-03 23:04:53 -04:00
cli: add windows amd64 build target (#1835)
This commit is contained in:
parent
6d5e7e1f7c
commit
60b125cb59
11 changed files with 135 additions and 86 deletions
|
@ -7,15 +7,10 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/cli/internal/cloudcmd"
|
||||
"github.com/edgelesssys/constellation/v2/cli/internal/libvirt"
|
||||
|
@ -29,7 +24,6 @@ import (
|
|||
"github.com/edgelesssys/constellation/v2/internal/license"
|
||||
"github.com/spf13/afero"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func newMiniUpCmd() *cobra.Command {
|
||||
|
@ -112,73 +106,6 @@ func (m *miniUpCmd) up(cmd *cobra.Command, creator cloudCreator, spinner spinner
|
|||
return nil
|
||||
}
|
||||
|
||||
// checkSystemRequirements checks if the system meets the requirements for running a MiniConstellation cluster.
|
||||
// We do so by verifying that the host:
|
||||
// - arch/os is linux/amd64.
|
||||
// - has access to /dev/kvm.
|
||||
// - has at least 4 CPU cores.
|
||||
// - has at least 4GB of memory.
|
||||
// - has at least 20GB of free disk space.
|
||||
func (m *miniUpCmd) checkSystemRequirements(out io.Writer) error {
|
||||
// check arch/os
|
||||
if runtime.GOARCH != "amd64" || runtime.GOOS != "linux" {
|
||||
return fmt.Errorf("creation of a QEMU based Constellation is not supported for %s/%s, a linux/amd64 platform is required", runtime.GOOS, runtime.GOARCH)
|
||||
}
|
||||
|
||||
m.log.Debugf("Checked arch and os")
|
||||
// check if /dev/kvm exists
|
||||
if _, err := os.Stat("/dev/kvm"); err != nil {
|
||||
return fmt.Errorf("unable to access KVM device: %w", err)
|
||||
}
|
||||
m.log.Debugf("Checked that /dev/kvm exists")
|
||||
// check CPU cores
|
||||
if runtime.NumCPU() < 4 {
|
||||
return fmt.Errorf("insufficient CPU cores: %d, at least 4 cores are required by MiniConstellation", runtime.NumCPU())
|
||||
}
|
||||
if runtime.NumCPU() < 6 {
|
||||
fmt.Fprintf(out, "WARNING: Only %d CPU cores available. This may cause performance issues.\n", runtime.NumCPU())
|
||||
}
|
||||
m.log.Debugf("Checked CPU cores - there are %d", runtime.NumCPU())
|
||||
|
||||
// check memory
|
||||
f, err := os.Open("/proc/meminfo")
|
||||
if err != nil {
|
||||
return fmt.Errorf("determining available memory: failed to open /proc/meminfo: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
var memKB int
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
if strings.HasPrefix(scanner.Text(), "MemTotal:") {
|
||||
_, err = fmt.Sscanf(scanner.Text(), "MemTotal:%d", &memKB)
|
||||
if err != nil {
|
||||
return fmt.Errorf("determining available memory: failed to parse /proc/meminfo: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
m.log.Debugf("Scanned for available memory")
|
||||
memGB := memKB / 1024 / 1024
|
||||
if memGB < 4 {
|
||||
return fmt.Errorf("insufficient memory: %dGB, at least 4GB of memory are required by MiniConstellation", memGB)
|
||||
}
|
||||
if memGB < 6 {
|
||||
fmt.Fprintln(out, "WARNING: Less than 6GB of memory available. This may cause performance issues.")
|
||||
}
|
||||
m.log.Debugf("Checked available memory, you have %dGB available", memGB)
|
||||
|
||||
var stat unix.Statfs_t
|
||||
if err := unix.Statfs(".", &stat); err != nil {
|
||||
return err
|
||||
}
|
||||
freeSpaceGB := stat.Bavail * uint64(stat.Bsize) / 1024 / 1024 / 1024
|
||||
if freeSpaceGB < 20 {
|
||||
return fmt.Errorf("insufficient disk space: %dGB, at least 20GB of disk space are required by MiniConstellation", freeSpaceGB)
|
||||
}
|
||||
m.log.Debugf("Checked for free space available, you have %dGB available", freeSpaceGB)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// prepareConfig reads a given config, or creates a new minimal QEMU config.
|
||||
func (m *miniUpCmd) prepareConfig(cmd *cobra.Command, fileHandler file.Handler, flags upFlags) (*config.Config, error) {
|
||||
// check for existing config
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue