Skip to content

Commit

Permalink
Merge pull request #159 from veertuinc/release/v3.2.1
Browse files Browse the repository at this point in the history
release/v3.2.1
  • Loading branch information
NorseGaud authored Aug 29, 2023
2 parents 6d83980 + dc7f2c9 commit af323f3
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export PATH := $(shell go env GOPATH)/bin:$(PATH)

.DEFAULT_GOAL := help

all: clean go.releaser anka.clean-images anka.clean-clones generate-docs
all: clean go.releaser anka.clean-images anka.clean-clones generate-docs install

#help: @ List available tasks on this project
help:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.0
3.2.1
13 changes: 7 additions & 6 deletions builder/anka/step_clone_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist
onError := func(err error) multistep.StepAction {
return ankaUtil.StepError(ui, state, err)
}
sourceVMTag := "latest"

doPull := config.AlwaysFetch

if config.SourceVMTag != "" {
sourceVMTag = config.SourceVMTag
sourceVMTag := fmt.Sprintf("%s tag", config.SourceVMTag)
if config.SourceVMTag == "" {
sourceVMTag = "latest tag"
}

s.client = state.Get("client").(client.Client)
Expand Down Expand Up @@ -73,7 +74,7 @@ func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist
}

if doPull {
ui.Say(fmt.Sprintf("Pulling source VM %s with tag %s from Anka Registry", config.SourceVMName, sourceVMTag))
ui.Say(fmt.Sprintf("Pulling source VM %s with %s from Anka Registry", config.SourceVMName, sourceVMTag))

registryParams := client.RegistryParams{
Remote: config.Remote,
Expand All @@ -86,14 +87,14 @@ func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist

registryPullParams := client.RegistryPullParams{
VMID: config.SourceVMName,
Tag: sourceVMTag,
Tag: config.SourceVMTag,
Local: false,
Shrink: false,
}

err := s.client.RegistryPull(registryParams, registryPullParams)
if err != nil {
return onError(fmt.Errorf("failed to pull vm %v with tag %v from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName, sourceVMTag))
return onError(fmt.Errorf("failed to pull vm %s with %s from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName, sourceVMTag))
}
}

Expand Down
62 changes: 52 additions & 10 deletions builder/anka/step_clone_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestCloneVMRun(t *testing.T) {
PackerBuilderType: "veertu-anka-vm-clone",
},
}
sourceVMTag := "latest"
sourceVMTag := ""
registryParams := client.RegistryParams{}
registryPullParams := client.RegistryPullParams{
VMID: config.SourceVMName,
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestCloneVMRun(t *testing.T) {
PackerBuilderType: "veertu-anka-vm-clone",
},
}
sourceVMTag := "latest"
sourceVMTag := ""
registryParams := client.RegistryParams{}
registryPullParams := client.RegistryPullParams{
VMID: config.SourceVMName,
Expand All @@ -211,10 +211,10 @@ func TestCloneVMRun(t *testing.T) {
ankaClient.EXPECT().Exists(config.SourceVMName).Return(false, nil).Times(1),
ankaClient.EXPECT().
RegistryPull(registryParams, registryPullParams).
Return(fmt.Errorf("failed to pull vm %v with tag %v from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName, sourceVMTag)).
Return(fmt.Errorf("failed to pull vm %v with latest tag from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName)).
Times(1),
ankaUtil.EXPECT().
StepError(ui, state, fmt.Errorf("failed to pull vm %v with tag %v from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName, sourceVMTag)).
StepError(ui, state, fmt.Errorf("failed to pull vm %v with latest tag from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName)).
Return(multistep.ActionHalt).
Times(1),
)
Expand All @@ -233,7 +233,7 @@ func TestCloneVMRun(t *testing.T) {
PackerBuilderType: "veertu-anka-vm-clone",
},
}
sourceVMTag := "latest"
sourceVMTag := ""
registryParams := client.RegistryParams{}
registryPullParams := client.RegistryPullParams{
VMID: config.SourceVMName,
Expand All @@ -255,12 +255,54 @@ func TestCloneVMRun(t *testing.T) {
)

mockui := packer.MockUi{}
mockui.Say(fmt.Sprintf("Pulling source VM %s with tag %s from Anka Registry", config.SourceVMName, sourceVMTag))
mockui.Say(fmt.Sprintf("Pulling source VM %s with latest tag from Anka Registry", config.SourceVMName))
mockui.Say(fmt.Sprintf("Cloning source VM %s into a new virtual machine: %s", sourceShowResponse.Name, step.vmName))

stepAction := step.Run(ctx, state)

assert.Equal(t, mockui.SayMessages[0].Message, "Pulling source VM source_foo with tag latest from Anka Registry")
assert.Equal(t, mockui.SayMessages[0].Message, "Pulling source VM source_foo with latest tag from Anka Registry")
assert.Equal(t, mockui.SayMessages[1].Message, "Cloning source VM source_foo into a new virtual machine: foo")
assert.Equal(t, multistep.ActionContinue, stepAction)
})

t.Run("pull from anka registry with specific tag", func(t *testing.T) {
sourceVMTag := "vanilla"
config := &Config{
AlwaysFetch: true,
VMName: "foo",
SourceVMName: "source_foo",
SourceVMTag: sourceVMTag,
PackerConfig: common.PackerConfig{
PackerBuilderType: "veertu-anka-vm-clone",
},
}
registryParams := client.RegistryParams{}
registryPullParams := client.RegistryPullParams{
VMID: config.SourceVMName,
Tag: sourceVMTag,
Local: false,
Shrink: false,
}

step.vmName = config.VMName

state.Put("vm_name", step.vmName)
state.Put("config", config)

gomock.InOrder(
ankaClient.EXPECT().RegistryPull(registryParams, registryPullParams).Return(nil).Times(1),
ankaClient.EXPECT().Show(config.SourceVMName).Return(sourceShowResponse, nil).Times(1),
ankaClient.EXPECT().Clone(client.CloneParams{VMName: step.vmName, SourceUUID: sourceShowResponse.UUID}).Return(nil).Times(1),
ankaClient.EXPECT().Show(step.vmName).Return(clonedShowResponse, nil).Times(1),
)

mockui := packer.MockUi{}
mockui.Say(fmt.Sprintf("Pulling source VM %s with vanilla tag from Anka Registry", config.SourceVMName))
mockui.Say(fmt.Sprintf("Cloning source VM %s into a new virtual machine: %s", sourceShowResponse.Name, step.vmName))

stepAction := step.Run(ctx, state)

assert.Equal(t, mockui.SayMessages[0].Message, "Pulling source VM source_foo with vanilla tag from Anka Registry")
assert.Equal(t, mockui.SayMessages[1].Message, "Cloning source VM source_foo into a new virtual machine: foo")
assert.Equal(t, multistep.ActionContinue, stepAction)
})
Expand All @@ -274,7 +316,7 @@ func TestCloneVMRun(t *testing.T) {
PackerBuilderType: "veertu-anka-vm-clone",
},
}
sourceVMTag := "latest"
sourceVMTag := ""
registryParams := client.RegistryParams{}
registryPullParams := client.RegistryPullParams{
VMID: config.SourceVMName,
Expand All @@ -291,10 +333,10 @@ func TestCloneVMRun(t *testing.T) {
gomock.InOrder(
ankaClient.EXPECT().
RegistryPull(registryParams, registryPullParams).
Return(fmt.Errorf("failed to pull vm %v with tag %v from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName, sourceVMTag)).
Return(fmt.Errorf("failed to pull vm %v with latest from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName)).
Times(1),
ankaUtil.EXPECT().
StepError(ui, state, fmt.Errorf("failed to pull vm %v with tag %v from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName, sourceVMTag)).
StepError(ui, state, fmt.Errorf("failed to pull vm %v with latest tag from registry (make sure to add it as the default: https://docs.veertu.com/anka/intel/command-line-reference/#registry-add)", config.SourceVMName)).
Return(multistep.ActionHalt).
Times(1),
)
Expand Down
2 changes: 1 addition & 1 deletion docs/builders/vm-clone.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ There are many configuration options available for the builder. They are segment

> This takes priority in Anka 3 and `registry-path` will be ignored.
* `source_vm_tag` (String) Specify the tag of the VM we want to clone instead of using the default.
* `source_vm_tag` (String) Specify the tag of the VM we want to clone instead of using the default. Also the tag to target when pulling from the registry (defaults to latest tag).

* `update_addons` (Boolean) (Anka 2 only) Update the vm addons. Defaults to false.

Expand Down
9 changes: 9 additions & 0 deletions examples/clone-existing.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// packer {
// required_plugins {
// veertu-anka = {
// version = "= v3.2.1"
// source = "github.com/veertuinc/veertu-anka"
// }
// }
// }

variable "source_vm_name" {
type = string
default = "anka-packer-base-macos"
Expand Down
42 changes: 42 additions & 0 deletions examples/pull-and-clone-existing.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// packer {
// required_plugins {
// veertu-anka = {
// version = "= v3.2.1"
// source = "github.com/veertuinc/veertu-anka"
// }
// }
// }

variable "source_vm_name" {
type = string
default = "anka-packer-base-macos"
}

variable "source_vm_tag" {
type = string
default = ""
}

variable "vm_name" {
type = string
default = "anka-packer-from-source"
}

source "veertu-anka-vm-clone" "anka-packer-from-source" {
vm_name = "${var.vm_name}"
source_vm_name = "${var.source_vm_name}"
source_vm_tag = "${var.source_vm_tag}"
}

build {
sources = [
"source.veertu-anka-vm-clone.anka-packer-from-source",
]

provisioner "shell" {
inline = [
"echo hello world",
"echo llamas rock"
]
}
}
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ go 1.19
require (
github.com/golang/mock v1.6.0
github.com/groob/plist v0.0.0-20220217120414-63fa881b19a5
github.com/hashicorp/hcl/v2 v2.14.1
github.com/hashicorp/packer-plugin-sdk v0.4.0
github.com/hashicorp/hcl/v2 v2.16.2
github.com/hashicorp/packer-plugin-sdk v0.5.1
github.com/mitchellh/mapstructure v1.5.0
github.com/zclconf/go-cty v1.10.0
github.com/zclconf/go-cty v1.12.1
gotest.tools/v3 v3.4.0
)

Expand Down Expand Up @@ -94,3 +94,5 @@ require (
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
)

replace github.com/zclconf/go-cty => github.com/nywilken/go-cty v1.12.1 // added by packer-sdc fix as noted in github.com/hashicorp/packer-plugin-sdk/issues/187
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+l
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/hcl/v2 v2.14.1 h1:x0BpjfZ+CYdbiz+8yZTQ+gdLO7IXvOut7Da+XJayx34=
github.com/hashicorp/hcl/v2 v2.14.1/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0=
github.com/hashicorp/hcl/v2 v2.16.2 h1:mpkHZh/Tv+xet3sy3F9Ld4FyI2tUpWe9x3XtPx9f1a0=
github.com/hashicorp/hcl/v2 v2.16.2/go.mod h1:JRmR89jycNkrrqnMmvPDMd56n1rQJ2Q6KocSLCMCXng=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY=
github.com/hashicorp/memberlist v0.2.2 h1:5+RffWKwqJ71YPu9mWsF7ZOscZmwfasdA8kbdC7AO2g=
github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE=
github.com/hashicorp/packer-plugin-sdk v0.4.0 h1:UyLYe0y02D9wkOQ3FeeZWyFg2+mx2vLuWRGUL5xt50I=
github.com/hashicorp/packer-plugin-sdk v0.4.0/go.mod h1:uNhU3pmjM2ejgHYce/g4J+sa5rh81iYQztpGvGa5FOs=
github.com/hashicorp/packer-plugin-sdk v0.5.1 h1:ucXGWru98LsQrAWq8cEnaNN2Dvqw0HtyupAwNzrfy44=
github.com/hashicorp/packer-plugin-sdk v0.5.1/go.mod h1:OKziA4fQodpIq5HzOpRNt+vLpRJae61Z4uVFbeMLgd8=
github.com/hashicorp/serf v0.9.5 h1:EBWvyu9tcRszt3Bxp3KNssBMP1KuHWyO51lz9+786iM=
github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk=
github.com/hashicorp/vault/api v1.0.5-0.20200519221902-385fac77e20f/go.mod h1:euTFbi2YJgwcju3imEt919lhJKF68nN1cQPq3aA+kBE=
Expand Down Expand Up @@ -330,6 +330,8 @@ github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7P
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/nywilken/go-cty v1.12.1 h1:4dEeVqhsX1RVfdLgu3CIMeft4ELm9qygMk7/kcpnfCs=
github.com/nywilken/go-cty v1.12.1/go.mod h1:jQhMnBcOB2DrBaV2awY4z+oSZTPc2dnnwGqYqFo86G0=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down Expand Up @@ -412,8 +414,6 @@ github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/zclconf/go-cty v1.10.0 h1:mp9ZXQeIcN8kAwuqorjH+Q+njbJKjLrvB2yIh4q7U+0=
github.com/zclconf/go-cty v1.10.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
Expand Down Expand Up @@ -518,7 +518,6 @@ golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
Expand Down

0 comments on commit af323f3

Please sign in to comment.