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

Add screen based boot mechanism #113

Merged
merged 20 commits into from
Jun 7, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/build_plugin_binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
defaults:
run:
working-directory: ~/go/src/github.com/Parallels/packer-plugin-parallels
runs-on: ubuntu-latest
runs-on: macos-latest
container:
image: docker.mirror.hashicorp.services/cimg/go:1.18
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go-test-darwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ permissions:

jobs:
get-go-version:
runs-on: ubuntu-latest
runs-on: macos-latest
outputs:
go-version: ${{ steps.get-go-version.outputs.go-version }}
steps:
Expand All @@ -41,6 +41,6 @@ jobs:
go-version: ${{ needs.get-go-version.outputs.go-version }}
- run: |
echo "Testing with Go ${{ needs.get-go-version.outputs.go-version }}"
go test -race -count 1 ./... -timeout=3m
CGO_ENABLED=1 CC=clang go test -race -count 1 ./... -timeout=3m


8 changes: 4 additions & 4 deletions .github/workflows/go-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ permissions:

jobs:
get-go-version:
runs-on: ubuntu-latest
runs-on: macos-latest
outputs:
go-version: ${{ steps.get-go-version.outputs.go-version }}
steps:
Expand All @@ -42,16 +42,16 @@ jobs:
check-lint:
needs:
- get-go-version
runs-on: ubuntu-latest
runs-on: macos-latest
name: Lint check
steps:
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
- uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5 # v3.4.0
- uses: golangci/golangci-lint-action@v6 # v3.4.0
with:
version: v1.47.3
version: v1.57.0
only-new-issues: true
check-fmt:
needs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ permissions:
packages: read
jobs:
get-go-version:
runs-on: ubuntu-latest
runs-on: macos-latest
outputs:
go-version: ${{ steps.get-go-version.outputs.go-version }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1.18.8
1.22.3

15 changes: 15 additions & 0 deletions .web-docs/components/builder/macvm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ communicator is "ssh".

<!-- Code generated from the comments of the Config struct in builder/parallels/macvm/config.go; DO NOT EDIT MANUALLY -->

- `boot_screen_config` (parallelscommon.BootScreensConfig) - Screens and it's boot configs
A screen is considered matched if all the matching strings are present in the screen.
The first matching screen will be considered & boot config of that screen will be used.
If matching strings are empty, then it is considered as empty screen,
which will be considered when none of the other screens are matched (You can use this screen to -
make system wait for some time / execute a common boot command etc.).
If more than one empty screen is found, then it is considered as an error.

- `ocr_library` (string) - OCR library to use. Two options are currently supported: "tesseract" and "vision".
"tesseract" uses the Tesseract OCR library to recognize text. A manual installation of -
Tesseract is required for this to work.
"vision" uses the Apple Vision library to recognize text, which is included in macOS. It might -
cause problems in macOS 13 or older VMs.
Defaults to "vision".

- `vm_name` (string) - This is the name of the MACVM directory for the new
virtual machine, without the file extension. By default this is
"packer-BUILDNAME", where "BUILDNAME" is the name of the build.
Expand Down
11 changes: 7 additions & 4 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
NAME=parallels
BINARY=packer-plugin-${NAME}
PLUGIN_FQN="$(shell grep -E '^module' <go.mod | sed -E 's/module *//')"
OS=$(uname go env GOOS)
PLUGIN_FQN=$(shell grep -E '^module' <go.mod | sed -E 's/module *//')

COUNT?=1
TEST?=$(shell go list ./...)
HASHICORP_PACKER_PLUGIN_SDK_VERSION?=$(shell go list -m github.com/hashicorp/packer-plugin-sdk | cut -d " " -f2)
PLUGIN_PATH=$(shell echo "${PLUGIN_FQN}" | sed 's/packer-plugin-//')
PACKER_FOLDER=$(shell dirname $(shell which packer))
VERSION=$(shell grep -E '^\tVersion = ' <./version/version.go | sed -E 's/\tVersion = *//')

.PHONY: dev

build:
@go build -o ${BINARY}

dev:
@go build -ldflags="-X '${PLUGIN_FQN}/version.VersionPrerelease=dev'" -o '${BINARY}'
packer plugins install --path ${BINARY} "$(shell echo "${PLUGIN_FQN}" | sed 's/packer-plugin-//')"
@./scripts/build_debug.sh

test:
@go test -race -count $(COUNT) $(TEST) -timeout=3m

install-packer-sdc: ## Install packer sofware development command
@go install github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc@${HASHICORP_PACKER_PLUGIN_SDK_VERSION}
go install github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc@${HASHICORP_PACKER_PLUGIN_SDK_VERSION}

plugin-check: install-packer-sdc build
@packer-sdc plugin-check ${BINARY}
Expand Down
54 changes: 54 additions & 0 deletions builder/parallels/common/boot_screen_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) Parallels International GmBH
// SPDX-License-Identifier: MPL-2.0

//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type BootScreenConfig

package common

import (
"fmt"
"strings"

"github.com/hashicorp/packer-plugin-sdk/bootcommand"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
)

type BootScreensConfig []BootScreenConfig

type BootScreenConfig struct {
// BootConfig for this screen
bootcommand.BootConfig `mapstructure:",squash"`
// Screen name to identify
ScreenName string `mapstructure:"screen_name"`
// Strings present in the screen to identify this screen
MatchingStrings []string `mapstructure:"matching_strings"`
// Specifies if the current screen is the last screen
// Screen based boot will stop after this screen
IsLastScreen bool `mapstructure:"is_last_screen"`
}

func (c *BootScreenConfig) Prepare(ctx *interpolate.Context) (errs []error) {
// Prepare bootconfig first
errs = append(errs, c.BootConfig.Prepare(ctx)...)

if len(c.ScreenName) == 0 {
errs = append(errs,
fmt.Errorf("screen name should not be empty"))
}

if len(errs) > 0 {
return errs
}

// Convert all matching strings to lowercase
for i, matchingString := range c.MatchingStrings {
c.MatchingStrings[i] = strings.ToLower(matchingString)
}

return nil
}

func (c *BootScreenConfig) FlatBootCommand() string {
return strings.Join(c.BootCommand, "")
}
41 changes: 41 additions & 0 deletions builder/parallels/common/boot_screen_config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions builder/parallels/common/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type Driver interface {
// Prlctl executes the given Prlctl command
Prlctl(...string) error

// PrlctlGet executes the given Prlctl command and returns the output
PrlctlGet(...string) (string, error)

// Get the path to the Parallels Tools ISO for the given flavor.
ToolsISOPath(string) (string, error)

Expand Down
8 changes: 7 additions & 1 deletion builder/parallels/common/driver_9.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ func (d *Parallels9Driver) Stop(name string) error {

// Prlctl executes the specified "prlctl" command.
func (d *Parallels9Driver) Prlctl(args ...string) error {
_, err := d.PrlctlGet(args...)
return err
}

// PrlctlGet executes the given "prlctl" command and returns the output
func (d *Parallels9Driver) PrlctlGet(args ...string) (string, error) {
var stdout, stderr bytes.Buffer

log.Printf("Executing prlctl: %#v", args)
Expand All @@ -328,7 +334,7 @@ func (d *Parallels9Driver) Prlctl(args ...string) error {
log.Printf("stdout: %s", stdoutString)
log.Printf("stderr: %s", stderrString)

return err
return stdoutString, err
}

// Verify raises an error if the builder could not be used on that host machine.
Expand Down
4 changes: 4 additions & 0 deletions builder/parallels/common/driver_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,7 @@ func (d *DriverMock) ToolsISOPath(flavor string) (string, error) {
d.ToolsISOPathFlavor = flavor
return d.ToolsISOPathResult, d.ToolsISOPathErr
}

func (d *DriverMock) PrlctlGet(...string) (string, error) {
return "", nil
}
Loading
Loading