mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-31 12:04:27 -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
|
@ -37,6 +37,7 @@ go_binary(
|
|||
"darwin_arm64",
|
||||
"linux_amd64",
|
||||
"linux_arm64",
|
||||
"windows_amd64",
|
||||
]
|
||||
for edition in [
|
||||
"oss",
|
||||
|
|
|
@ -20,6 +20,8 @@ go_library(
|
|||
"mini.go",
|
||||
"minidown.go",
|
||||
"miniup.go",
|
||||
"miniup_cross.go",
|
||||
"miniup_linux_amd64.go",
|
||||
"recover.go",
|
||||
"spinner.go",
|
||||
"status.go",
|
||||
|
@ -88,9 +90,16 @@ go_library(
|
|||
"@org_golang_google_grpc//:go_default_library",
|
||||
"@org_golang_google_grpc//connectivity",
|
||||
"@org_golang_x_mod//semver",
|
||||
"@org_golang_x_sys//unix",
|
||||
"@org_uber_go_zap//zapcore",
|
||||
],
|
||||
] + select({
|
||||
"@io_bazel_rules_go//go/platform:android_amd64": [
|
||||
"@org_golang_x_sys//unix",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:linux_amd64": [
|
||||
"@org_golang_x_sys//unix",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)
|
||||
|
||||
go_test(
|
||||
|
|
|
@ -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
|
||||
|
|
21
cli/internal/cmd/miniup_cross.go
Normal file
21
cli/internal/cmd/miniup_cross.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
//go:build !linux || !amd64
|
||||
|
||||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// checkSystemRequirements checks if the system meets the requirements for running a MiniConstellation cluster.
|
||||
// This will always fail on non-linux/amd64 platforms.
|
||||
func (m *miniUpCmd) checkSystemRequirements(_ io.Writer) error {
|
||||
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)
|
||||
}
|
87
cli/internal/cmd/miniup_linux_amd64.go
Normal file
87
cli/internal/cmd/miniup_linux_amd64.go
Normal file
|
@ -0,0 +1,87 @@
|
|||
//go:build linux && amd64
|
||||
|
||||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
|
@ -12,6 +12,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
slashpath "path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
|
@ -58,7 +59,8 @@ func prepareUpgradeWorkspace(rootDir string, fileHandler file.Handler, oldWorkin
|
|||
|
||||
// terraformCopier copies the embedded Terraform files into the workspace.
|
||||
func terraformCopier(fileHandler file.Handler, rootDir, workingDir string) error {
|
||||
return fs.WalkDir(terraformFS, rootDir, func(path string, d fs.DirEntry, err error) error {
|
||||
goEmbedRootDir := filepath.ToSlash(rootDir)
|
||||
return fs.WalkDir(terraformFS, goEmbedRootDir, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -66,11 +68,13 @@ func terraformCopier(fileHandler file.Handler, rootDir, workingDir string) error
|
|||
return nil
|
||||
}
|
||||
|
||||
content, err := terraformFS.ReadFile(path)
|
||||
goEmbedPath := filepath.ToSlash(path)
|
||||
content, err := terraformFS.ReadFile(goEmbedPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fileName := strings.Replace(filepath.Join(workingDir, path), rootDir+"/", "", 1)
|
||||
// normalize
|
||||
fileName := strings.Replace(slashpath.Join(workingDir, path), goEmbedRootDir+"/", "", 1)
|
||||
if err := fileHandler.Write(fileName, content, file.OptMkdirAll); errors.Is(err, afero.ErrFileExists) {
|
||||
// If a file already exists, check if it is identical. If yes, continue and don't write anything to disk.
|
||||
// If no, don't overwrite it and instead throw an error. The affected file could be from a different version,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue