Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change default mac runner from x86 to arm64 #1630

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ jobs:
make test | tee ${TEST_RESULTS}/go-test.out
build-mac:
macos:
xcode: "15.3.0"
xcode: "15.4.0"
resource_class: macos.m1.medium.gen1
environment:
TEST_RESULTS: /tmp/test-results
steps:
- checkout
- run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- run: brew update && brew install go && brew tap nanovms/homebrew-qemu && brew install nanovms/homebrew-qemu/qemu && brew install wget && brew install protoc-gen-go-grpc
- run: go install github.com/jstemmer/go-junit-report@latest
- run: wget https://github.com/bufbuild/buf/releases/download/v1.13.1/buf-Darwin-x86_64 && sudo mv buf-Darwin-x86_64 /usr/local/bin/buf && sudo chmod +x /usr/local/bin/buf
# - run: brew install bufbuild/buf/buf
- run: wget https://github.com/bufbuild/buf/releases/download/v1.13.1/buf-Darwin-arm64 && sudo mv buf-Darwin-arm64 /usr/local/bin/buf && sudo chmod +x /usr/local/bin/buf
- run: go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
- run: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
- run: curl -L https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v2.15.0/protoc-gen-openapiv2-v2.15.0-darwin-x86_64 -o ~/go/bin/protoc-gen-openapiv2 && chmod +x ~/go/bin/protoc-gen-openapiv2
- run: curl -L https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v2.15.0/protoc-gen-grpc-gateway-v2.15.0-darwin-x86_64 -o ~/go/bin/protoc-gen-grpc-gateway && chmod +x ~/go/bin/protoc-gen-grpc-gateway
- run: curl -L https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v2.15.0/protoc-gen-openapiv2-v2.15.0-darwin-arm64 -o ~/go/bin/protoc-gen-openapiv2 && chmod +x ~/go/bin/protoc-gen-openapiv2
- run: curl -L https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v2.15.0/protoc-gen-grpc-gateway-v2.15.0-darwin-arm64 -o ~/go/bin/protoc-gen-grpc-gateway && chmod +x ~/go/bin/protoc-gen-grpc-gateway
- run: make deps
- run: make generate PATH=$PATH:~/go/bin
- run: mkdir -p $TEST_RESULTS
- run: go run ops.go update
- run: go run ops.go update --arm
- run:
name: macbuild
command: |
Expand Down
2 changes: 2 additions & 0 deletions cmd/cmd_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
)

func TestCmdBuild(t *testing.T) {
stubUpdate()

programPath := testutils.BuildBasicProgram()
defer os.Remove(programPath)

Expand Down
27 changes: 27 additions & 0 deletions cmd/cmd_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,35 @@ import (
"os"
"testing"

// FIXME: why are there 2 pkgs here?
"github.com/nanovms/ops/cmd"
"github.com/stretchr/testify/assert"
)

// FIXME
// memoize
func stubAMDUpdate() error {
upPkgCmd := cmd.UpdateCommand()
return upPkgCmd.Execute()
}

func stubARMUpdate() error {
upPkgCmd := cmd.UpdateCommand()
upPkgCmd.SetArgs([]string{"--arm"})
return upPkgCmd.Execute()
}

func stubUpdate() error {
upPkgCmd := cmd.UpdateCommand()

a := cmd.ArchPath()
if a != "" {
upPkgCmd.SetArgs([]string{"--arm"})
}

return upPkgCmd.Execute()
}

func TestListPkgCommand(t *testing.T) {
listPkgCmd := cmd.PackageCommands()

Expand Down Expand Up @@ -50,6 +75,8 @@ func TestPkgDescribeCommand(t *testing.T) {

func TestLoad(t *testing.T) {

stubAMDUpdate()

getPkgCmd := cmd.PackageCommands()

program := buildNodejsProgram()
Expand Down
3 changes: 3 additions & 0 deletions cmd/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
)

func TestRunCommand(t *testing.T) {

stubUpdate()

programPath := testutils.BuildBasicProgram()
defer os.Remove(programPath)

Expand Down
1 change: 0 additions & 1 deletion cmd/cmd_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,4 @@ func updateCommandHandler(cmd *cobra.Command, args []string) {
api.UpdateLocalRelease(remote)
fmt.Printf("Update nanos to %s version.\n", remote)
}
os.Exit(0)
}
3 changes: 0 additions & 3 deletions cmd/cmd_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ func TestAttachVolumeCommand(t *testing.T) {

attachVolumeCmd.SetArgs([]string{"attach", instanceName, volumeName, "does not matter"})

// FIXME: tests prob. should not be spawning
time.Sleep(1 * time.Second)

err := attachVolumeCmd.Execute()

assert.Nil(t, err)
Expand Down
10 changes: 8 additions & 2 deletions cmd/flags_nanos_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ type NanosVersionCommandFlags struct {
NanosVersion string
}

// FIXME - no need for sep pkgs; now having to export this because of
// this issue.
func ArchPath() string {
return archPath()
}

func archPath() string {
if runtime.GOARCH == "arm64" || lepton.AltGOARCH == "arm64" {
return "arm"
Expand All @@ -28,13 +34,13 @@ func (flags *NanosVersionCommandFlags) MergeToConfig(config *types.Config) (err

if nanosVersion != "" {
var exists bool
exists, err = lepton.CheckNanosVersionExists(nanosVersion)
arch := archPath()
exists, err = lepton.CheckNanosVersionExists(nanosVersion, arch)
if err != nil {
return err
}

if !exists {
arch := archPath()
err = lepton.DownloadReleaseImages(nanosVersion, arch)
if err != nil {
return
Expand Down
57 changes: 54 additions & 3 deletions cmd/flags_nanos_version_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"os"
"path"
"strings"
"testing"

"github.com/nanovms/ops/lepton"
Expand All @@ -23,9 +25,45 @@ func TestCreateVersionFlags(t *testing.T) {
assert.Equal(t, versionFlags.NanosVersion, "0.1.37")
}

// stubs a 'release'
func stubRelease(versionPath string) error {
err := os.MkdirAll(versionPath, 0750)
if err != nil {
return err
}

f, err := os.OpenFile(versionPath+"/kernel.img", os.O_RDONLY|os.O_CREATE, 0644)
if err != nil {
return err
}
f.Close()

if !strings.Contains(versionPath, "-arm") {
f, err := os.OpenFile(versionPath+"/boot.img", os.O_RDONLY|os.O_CREATE, 0644)
if err != nil {
return err
}
f.Close()
}

return nil
}

func TestVersionFlagsMergeToConfig(t *testing.T) {

versionPath := path.Join(lepton.GetOpsHome(), "0.1.37")

a := archPath()

if a != "" {
versionPath = versionPath + "-" + a
}

err := stubRelease(versionPath)
if err != nil {
t.Fatal(err)
}

currentOpsPath := path.Join(lepton.GetOpsHome(), lepton.LocalReleaseVersion)

t.Run("if nano-version flag is enabled should set boot and kernel paths", func(t *testing.T) {
Expand All @@ -37,9 +75,14 @@ func TestVersionFlagsMergeToConfig(t *testing.T) {

versionFlags := NewNanosVersionCommandFlags(flagSet)

boot := path.Join(versionPath, "boot.img")
if a != "" {
boot = ""
}

c := &types.Config{}
expected := &types.Config{
Boot: path.Join(versionPath, "boot.img"),
Boot: boot,
Kernel: path.Join(versionPath, "kernel.img"),
}

Expand All @@ -59,12 +102,20 @@ func TestVersionFlagsMergeToConfig(t *testing.T) {

versionFlags := NewNanosVersionCommandFlags(flagSet)

cBoot := currentOpsPath + "/boot.img"
vBoot := versionPath + "/boot.img"

if a != "" {
cBoot = ""
vBoot = ""
}

c := &types.Config{
Kernel: currentOpsPath + "/kernel.img",
Boot: currentOpsPath + "/boot.img",
Boot: cBoot,
}
expected := &types.Config{
Boot: versionPath + "/boot.img",
Boot: vBoot,
Kernel: versionPath + "/kernel.img",
}

Expand Down
6 changes: 5 additions & 1 deletion lepton/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,11 @@ func DownloadCommonFiles() error {
}

// CheckNanosVersionExists verifies whether version exists in filesystem
func CheckNanosVersionExists(version string) (bool, error) {
func CheckNanosVersionExists(version string, arch string) (bool, error) {
if arch != "" {
version = version + "-" + arch
}

_, err := os.Stat(path.Join(GetOpsHome(), version))
if err != nil && os.IsNotExist(err) {
return false, nil
Expand Down
18 changes: 8 additions & 10 deletions provider/onprem/onprem_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,13 @@ func (p *OnPrem) StartInstance(ctx *lepton.Context, instancename string) error {
`{ "execute": "cont" }`,
}

executeQMP(commands, last)
return nil
return executeQMP(commands, last)
}

func executeQMP(commands []string, last string) {
c, err := net.Dial("tcp", "localhost:"+last)
func executeQMP(commands []string, last string) error {
c, err := net.Dial("tcp", "127.0.0.1:"+last)
if err != nil {
fmt.Println(err)
return err
}
defer c.Close()

Expand All @@ -592,6 +591,8 @@ func executeQMP(commands []string, last string) {
os.Exit(1)
}
}

return nil
}

// RebootInstance from on premise
Expand All @@ -608,9 +609,7 @@ func (p *OnPrem) RebootInstance(ctx *lepton.Context, instancename string) error
`{ "execute": "system_reset" }`,
}

executeQMP(commands, last)

return nil
return executeQMP(commands, last)
}

// StopInstance from on premise
Expand All @@ -627,8 +626,7 @@ func (p *OnPrem) StopInstance(ctx *lepton.Context, instancename string) error {
`{ "execute": "stop" }`,
}

executeQMP(commands, last)
return nil
return executeQMP(commands, last)
}

// DeleteInstance from on premise
Expand Down
1 change: 1 addition & 0 deletions provider/onprem/onprem_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func (op *OnPrem) DetachVolume(ctx *lepton.Context, instanceName string, volumeN
c, err := net.Dial("tcp", "localhost:"+last)
if err != nil {
fmt.Println(err)
return err
}
defer c.Close()

Expand Down