cli: add windows amd64 build target (#1835)

This commit is contained in:
Malte Poll 2023-05-30 12:02:43 +02:00 committed by GitHub
parent 6d5e7e1f7c
commit 60b125cb59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 135 additions and 86 deletions

View File

@ -1808,8 +1808,8 @@ def go_dependencies():
build_file_generation = "on",
build_file_proto_mode = "disable_global",
importpath = "github.com/edgelesssys/go-tdx-qpl",
sum = "h1:uQMmc/B1RGE2VeSsh/NqjRgEheqp1cjy8ELIDTFpaUw=",
version = "v0.0.0-20230307140231-bb361f158928",
sum = "h1:Q2TI34V/NCLGQQkdc0/KmPx/7ix9YnGDUQDT+gqvDw0=",
version = "v0.0.0-20230530085549-fd2878a4dead",
)
go_repository(

View File

@ -37,6 +37,7 @@ go_binary(
"darwin_arm64",
"linux_amd64",
"linux_arm64",
"windows_amd64",
]
for edition in [
"oss",

View File

@ -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(

View File

@ -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

View 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)
}

View 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
}

View File

@ -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,

2
go.mod
View File

@ -70,7 +70,7 @@ require (
github.com/docker/docker v23.0.3+incompatible
github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/api v0.0.0
github.com/edgelesssys/go-azguestattestation v0.0.0-20230303085714-62ede861d33f
github.com/edgelesssys/go-tdx-qpl v0.0.0-20230307140231-bb361f158928
github.com/edgelesssys/go-tdx-qpl v0.0.0-20230530085549-fd2878a4dead
github.com/fsnotify/fsnotify v1.6.0
github.com/go-playground/locales v0.14.1
github.com/go-playground/universal-translator v0.18.1

4
go.sum
View File

@ -422,8 +422,8 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/edgelesssys/go-azguestattestation v0.0.0-20230303085714-62ede861d33f h1:J9k1gV8YA5beC6jANKQy5O7UtaKS3ueuanxUan5Y5NU=
github.com/edgelesssys/go-azguestattestation v0.0.0-20230303085714-62ede861d33f/go.mod h1:hX9gZBSvliJcBEAyrJDh7990hLRg/Is+6PBpDZWSMoc=
github.com/edgelesssys/go-tdx-qpl v0.0.0-20230307140231-bb361f158928 h1:uQMmc/B1RGE2VeSsh/NqjRgEheqp1cjy8ELIDTFpaUw=
github.com/edgelesssys/go-tdx-qpl v0.0.0-20230307140231-bb361f158928/go.mod h1:IC72qyykUIWl0ZmSk53L4xbLCFDBEGZVaujUmPQOEyw=
github.com/edgelesssys/go-tdx-qpl v0.0.0-20230530085549-fd2878a4dead h1:Q2TI34V/NCLGQQkdc0/KmPx/7ix9YnGDUQDT+gqvDw0=
github.com/edgelesssys/go-tdx-qpl v0.0.0-20230530085549-fd2878a4dead/go.mod h1:IC72qyykUIWl0ZmSk53L4xbLCFDBEGZVaujUmPQOEyw=
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/emicklei/go-restful/v3 v3.10.1 h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ=
github.com/emicklei/go-restful/v3 v3.10.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=

View File

@ -125,7 +125,7 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/api v0.0.0 // indirect
github.com/edgelesssys/go-azguestattestation v0.0.0-20230303085714-62ede861d33f // indirect
github.com/edgelesssys/go-tdx-qpl v0.0.0-20230307140231-bb361f158928 // indirect
github.com/edgelesssys/go-tdx-qpl v0.0.0-20230530085549-fd2878a4dead // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect

View File

@ -389,8 +389,8 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/edgelesssys/go-azguestattestation v0.0.0-20230303085714-62ede861d33f h1:J9k1gV8YA5beC6jANKQy5O7UtaKS3ueuanxUan5Y5NU=
github.com/edgelesssys/go-azguestattestation v0.0.0-20230303085714-62ede861d33f/go.mod h1:hX9gZBSvliJcBEAyrJDh7990hLRg/Is+6PBpDZWSMoc=
github.com/edgelesssys/go-tdx-qpl v0.0.0-20230307140231-bb361f158928 h1:uQMmc/B1RGE2VeSsh/NqjRgEheqp1cjy8ELIDTFpaUw=
github.com/edgelesssys/go-tdx-qpl v0.0.0-20230307140231-bb361f158928/go.mod h1:IC72qyykUIWl0ZmSk53L4xbLCFDBEGZVaujUmPQOEyw=
github.com/edgelesssys/go-tdx-qpl v0.0.0-20230530085549-fd2878a4dead h1:Q2TI34V/NCLGQQkdc0/KmPx/7ix9YnGDUQDT+gqvDw0=
github.com/edgelesssys/go-tdx-qpl v0.0.0-20230530085549-fd2878a4dead/go.mod h1:IC72qyykUIWl0ZmSk53L4xbLCFDBEGZVaujUmPQOEyw=
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/emicklei/go-restful/v3 v3.10.1 h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ=
github.com/emicklei/go-restful/v3 v3.10.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=