Skip to content

Commit

Permalink
Merge pull request #123 from veertuinc/release/v2.3.2
Browse files Browse the repository at this point in the history
release/v2.3.2
  • Loading branch information
NorseGaud authored Aug 5, 2022
2 parents 9c4d205 + 428f7d1 commit 25ffaba
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 261 deletions.
2 changes: 0 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ updates:
day: "tuesday"
assignees:
- "NorseGaud"
- "asafg6"
reviewers:
- "NorseGaud"
- "asafg6"
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ _testmain.go
*.prof

.DS_Store
install-anka-packer*.log
install-anka-packer*.log

docs.zip
26 changes: 19 additions & 7 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ before:
builds:
# A separated build to run the packer-plugins-check only once for a linux_amd64 binary
-
id: build
id: build1
mod_timestamp: '{{ .CommitTimestamp }}'
hooks:
post:
- cmd: bash -c "packer-sdc plugin-check {{ .ProjectName }}_v{{ .Version }}_{{ .Env.PACKER_CI_PROJECT_API_VERSION }}_{{ .Os }}_{{ .Arch }}"
- cmd: bash -c "chmod +x {{ .ProjectName }}_v{{ .Version }}_{{ .Env.PACKER_CI_PROJECT_API_VERSION }}_{{ .Os }}_{{ .Arch }}"
dir: "{{ dir .Path }}"
- cmd: bash -c "chmod +x {{ .ProjectName }}_v{{ .Version }}_{{ .Env.PACKER_CI_PROJECT_API_VERSION }}_{{ .Os }}_{{ .Arch }}; ls -lah $(pwd)/{{ .ProjectName }}_v{{ .Version }}_{{ .Env.PACKER_CI_PROJECT_API_VERSION }}_{{ .Os }}_{{ .Arch }}"
dir: "{{ dir .Path }}"
- cmd: bash -c "cp -rfp {{ dir .Path }}/{{ .ProjectName }}_v{{ .Version }}_{{ .Env.PACKER_CI_PROJECT_API_VERSION }}_{{ .Os }}_{{ .Arch }} ./{{ .ProjectName }} && make validate-examples"
- cmd: bash -c "cp -rfp {{ dir .Path }}/{{ .ProjectName }}_v{{ .Version }}_{{ .Env.PACKER_CI_PROJECT_API_VERSION }}_{{ .Os }}_{{ .Arch }} ./{{ .ProjectName }}"
- cmd: bash -c "make validate-examples"
- cmd: bash -c "packer-sdc plugin-check {{ .ProjectName }}"
flags:
- -trimpath #removes all file system paths from the compiled executable
ldflags:
- '-s -w -X main.commit={{ .Commit }} -X main.version={{ .Version }}'
goos:
- linux
- darwin
goarch:
- amd64
binary: '{{ .ProjectName }}_v{{ .Version }}_{{ .Env.PACKER_CI_PROJECT_API_VERSION }}_{{ .Os }}_{{ .Arch }}'
Expand All @@ -39,9 +39,21 @@ builds:
ldflags:
- '-s -w -X main.commit={{ .Commit }} -X main.version={{ .Version }}'
goos:
- darwin
- linux
goarch:
- amd64
binary: '{{ .ProjectName }}_v{{ .Version }}_{{ .Env.PACKER_CI_PROJECT_API_VERSION }}_{{ .Os }}_{{ .Arch }}'
no_unique_dist_dir: true
-
id: build3
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath #removes all file system paths from the compiled executable
ldflags:
- '-s -w -X main.commit={{ .Commit }} -X main.version={{ .Version }}'
goos:
- darwin
goarch:
- arm64
binary: '{{ .ProjectName }}_v{{ .Version }}_{{ .Env.PACKER_CI_PROJECT_API_VERSION }}_{{ .Os }}_{{ .Arch }}'
no_unique_dist_dir: true
Expand Down
25 changes: 19 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
WORKDIR := $(shell pwd)
LATEST-GIT-SHA := $(shell git rev-parse HEAD)
VERSION := $(shell cat VERSION)
FLAGS := -X main.commit=$(LATEST-GIT-SHA) -X main.version=$(VERSION)
BIN := packer-plugin-veertu-anka
ARCH := amd64
ARCH := $(shell arch)
ifeq ($(ARCH), i386)
ARCH = amd64
endif
OS_TYPE ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
BIN_FULL ?= bin/$(BIN)_$(OS_TYPE)_$(ARCH)
HASHICORP_PACKER_PLUGIN_SDK_VERSION?=$(shell go list -m github.com/hashicorp/packer-plugin-sdk | cut -d " " -f2)
export PATH := $(shell go env GOPATH)/bin:$(PATH)

.PHONY: go.lint validate-examples go.test test clean anka.clean-images

.DEFAULT_GOAL := help

all: go.lint clean go.hcl2spec go.build go.test install validate-examples anka.clean-images anka.clean-clones uninstall
all: clean go.releaser anka.clean-images anka.clean-clones generate-docs

#help: @ List available tasks on this project
help:
Expand All @@ -36,9 +41,16 @@ go.build:
GOARCH=$(ARCH) go build $(RACE) -ldflags "$(FLAGS)" -o $(BIN_FULL)
chmod +x $(BIN_FULL)

go.releaser:
git tag -d "$(VERSION)" 2>/dev/null || true
git tag -a "$(VERSION)" -m "Version $(VERSION)"
echo "LATEST TAG: $$(git describe --tags --abbrev=0)"
PACKER_CI_PROJECT_API_VERSION=$$(go run . describe 2>/dev/null | jq -r '.api_version') goreleaser release --rm-dist

#validate-examples: @ Run `packer validate` against example packer definitions using the built package
validate-examples:
for file in $(ls examples/ | grep hcl); do packer validate examples/$file; done
cp -rfp $(WORKDIR)/examples /tmp/
for file in $$(ls $(WORKDIR)/examples/ | grep hcl); do echo $$file; packer validate $(WORKDIR)/examples/$$file; done

#install: @ Copy the binary to the packer plugins folder
install:
Expand Down Expand Up @@ -66,10 +78,12 @@ build-mac:

#create-test: @ Run `packer build` with the default .pkr.hcl file
create-test: lint install
PACKER_LOG=1 packer build examples/create-from-installer.pkr.hcl
PACKER_LOG=1 packer build $(WORKDIR)/examples/create-from-installer.pkr.hcl

#clean: @ Remove the plugin binary
clean:
rm -f docs.zip
rm -rf dist
rm -f $(BIN_FULL)

#anka.clean-images: @ Remove all anka images with `anka delete`
Expand All @@ -95,5 +109,4 @@ go.hcl2spec: install-packer-sdc

#generate-docs: @ Generate packer docs
generate-docs: install-packer-sdc
@pushd dist/; packer-sdc renderdocs -src ../docs -partials docs-partials/ -dst docs/
@/bin/sh -c "[ -d dist/docs ] && zip -r docs.zip docs/"
@pushd dist/; packer-sdc renderdocs -src ../docs -partials docs-partials/ -dst docs/ && /bin/sh -c "[ -d docs ] && zip -r docs.zip docs/"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is a [Packer](https://www.packer.io/) Plugin for building images that work

- Note that this plugin does not manage VM templates. Once it creates a Template, it is up to you to use it or delete it.

- For use with the post-processor, it's important to use `anka registry add` to [set your default registry on the machine building your templates/tags](https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#registry-add).
- For use with the post-processor, it's important to use `anka registry add` to [set your default registry on the machine building your templates/tags](https://docs.veertu.com/anka/intel/command-line-reference/#registry-add).
## v2.0.0 Breaking Changes

- Plugin will only work with Packer v1.7 or later.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.1
2.3.2
2 changes: 1 addition & 1 deletion builder/anka/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
}

if license.LicenseType == "com.veertu.anka.develop" {
log.Printf("developer license present, can only stop vms: https://ankadocs.veertu.com/docs/licensing/#anka-license-feature-differences")
log.Printf("developer license present, can only stop vms: https://docs.veertu.com/anka/licensing/#anka-license-feature-differences")
b.config.StopVM = true
}

Expand Down
2 changes: 1 addition & 1 deletion builder/anka/step_clone_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist

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://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#registry-add)", config.SourceVMName, sourceVMTag))
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))
}
}

Expand Down
8 changes: 4 additions & 4 deletions builder/anka/step_clone_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#registry-add)", config.SourceVMName, sourceVMTag)).
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)).
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://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#registry-add)", config.SourceVMName, sourceVMTag)).
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)).
Return(multistep.ActionHalt).
Times(1),
)
Expand Down Expand Up @@ -291,10 +291,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://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#registry-add)", config.SourceVMName, sourceVMTag)).
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)).
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://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#registry-add)", config.SourceVMName, sourceVMTag)).
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)).
Return(multistep.ActionHalt).
Times(1),
)
Expand Down
30 changes: 15 additions & 15 deletions client/client_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
AnkaVMNotFoundExceptionErrorCode = 3
)

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#clone
// https://docs.veertu.com/anka/intel/command-line-reference/#clone
type CloneParams struct {
VMName string
SourceUUID string
Expand All @@ -36,7 +36,7 @@ func (c *AnkaClient) Clone(params CloneParams) error {
return nil
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#cp
// https://docs.veertu.com/anka/intel/command-line-reference/#cp
type CopyParams struct {
Src string
Dst string
Expand All @@ -56,7 +56,7 @@ type CreateParams struct {
VCPUCount string
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#create
// https://docs.veertu.com/anka/intel/command-line-reference/#create
type CreateResponse struct {
UUID string `json:"uuid"`
Name string `json:"name"`
Expand Down Expand Up @@ -91,7 +91,7 @@ func (c *AnkaClient) Create(params CreateParams, outputStreamer chan string) (Cr
return response, nil
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#delete
// https://docs.veertu.com/anka/intel/command-line-reference/#delete
type DeleteParams struct {
VMName string
}
Expand All @@ -108,7 +108,7 @@ func (c *AnkaClient) Delete(params DeleteParams) error {
return err
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#describe
// https://docs.veertu.com/anka/intel/command-line-reference/#describe
type DescribeResponse struct {
Name string `json:"name"`
Version int `json:"version"`
Expand Down Expand Up @@ -185,7 +185,7 @@ func (c *AnkaClient) Describe(vmName string) (DescribeResponse, error) {
return response, nil
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#show
// https://docs.veertu.com/anka/intel/command-line-reference/#show
func (c *AnkaClient) Exists(vmName string) (bool, error) {
_, err := c.Show(vmName)
if err == nil {
Expand All @@ -201,7 +201,7 @@ func (c *AnkaClient) Exists(vmName string) (bool, error) {
return false, err
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#license
// https://docs.veertu.com/anka/intel/command-line-reference/#license
type LicenseResponse struct {
LicenseType string `json:"license_type"`
Status string `json:"status"`
Expand All @@ -223,7 +223,7 @@ func (c *AnkaClient) License() (LicenseResponse, error) {
return response, nil
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#modify
// https://docs.veertu.com/anka/intel/command-line-reference/#modify
func (c *AnkaClient) Modify(vmName string, command string, property string, flags ...string) error {
ankaCommand := []string{"modify", vmName, command, property}
ankaCommand = append(ankaCommand, flags...)
Expand All @@ -240,7 +240,7 @@ func (c *AnkaClient) Modify(vmName string, command string, property string, flag
return nil
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#run
// https://docs.veertu.com/anka/intel/command-line-reference/#run
type RunParams struct {
VMName string
Volume string
Expand All @@ -266,7 +266,7 @@ func (c *AnkaClient) Run(params RunParams) (int, error) {
return runner.Wait()
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#show
// https://docs.veertu.com/anka/intel/command-line-reference/#show
type ShowResponse struct {
UUID string `json:"uuid"`
Name string `json:"name"`
Expand Down Expand Up @@ -313,7 +313,7 @@ func (c *AnkaClient) Show(vmName string) (ShowResponse, error) {
return response, nil
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#start
// https://docs.veertu.com/anka/intel/command-line-reference/#start
type StartParams struct {
VMName string
}
Expand All @@ -323,7 +323,7 @@ func (c *AnkaClient) Start(params StartParams) error {
return err
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#stop
// https://docs.veertu.com/anka/intel/command-line-reference/#stop
type StopParams struct {
VMName string
Force bool
Expand Down Expand Up @@ -360,7 +360,7 @@ func (c *AnkaClient) Stop(params StopParams) error {
return err
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#suspend
// https://docs.veertu.com/anka/intel/command-line-reference/#suspend
type SuspendParams struct {
VMName string
}
Expand All @@ -370,15 +370,15 @@ func (c *AnkaClient) Suspend(params SuspendParams) error {
return err
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#start
// https://docs.veertu.com/anka/intel/command-line-reference/#start
func (c *AnkaClient) UpdateAddons(vmName string) error {
args := []string{"start", "--update-addons", vmName}

_, err := runAnkaCommand(args...)
return err
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#version
// https://docs.veertu.com/anka/intel/command-line-reference/#version
type VersionResponse struct {
Status string `json:"status"`
Body VersionResponseBody `json:"body"`
Expand Down
12 changes: 8 additions & 4 deletions client/client_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type RegistryParams struct {
HostArch string
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#registry-list
// https://docs.veertu.com/anka/intel/command-line-reference/#registry-list
type RegistryListResponse struct {
Latest string `json:"latest"`
ID string `json:"id"`
Expand Down Expand Up @@ -102,6 +102,7 @@ func (c *AnkaClient) RegistryListRepos() (RegistryListReposResponse, error) {
func (c *AnkaClient) RegistryListReposArm64() (RegistryListReposResponse, error) {
var response RegistryListReposResponse
var responseArm64 RegistryListReposResponseArm64
var port string

output, err := runRegistryCommand(RegistryParams{}, "list-repos")
if err != nil {
Expand All @@ -125,11 +126,14 @@ func (c *AnkaClient) RegistryListReposArm64() (RegistryListReposResponse, error)
}

s := strings.Split(u.Host, ":")
if len(s) == 2 {
port = s[1]
}
a := RegistryRemote{
Scheme: u.Scheme,
Default: remote.Default,
Host: s[0],
Port: s[1],
Port: port,
}
tmpBody[remote.Name] = a
}
Expand Down Expand Up @@ -179,7 +183,7 @@ func (c *AnkaClient) RegistryPull(registryParams RegistryParams, pullParams Regi
return nil
}

// https://ankadocs.veertu.com/docs/anka-virtualization/command-reference/#registry-push
// https://docs.veertu.com/anka/intel/command-line-reference/#registry-push
type RegistryPushParams struct {
VMID string
Tag string
Expand Down Expand Up @@ -225,7 +229,7 @@ func (c *AnkaClient) RegistryPush(registryParams RegistryParams, pushParams Regi
return nil
}

// https://ankadocs.veertu.com/docs/anka-build-cloud/working-with-registry-and-api/#revert
// https://docs.veertu.com/anka/anka-build-cloud/working-with-registry-and-api/#revert
func (c *AnkaClient) RegistryRevert(url string, id string) error {
response, err := registryRESTRequest("DELETE", fmt.Sprintf("%s/registry/revert?id=%s", url, id), nil)
if err != nil {
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 @@ -29,7 +29,7 @@ packer {

## Important Notes

- **In Anka 3.0** we now require a tagged source VM before cloning in order to share the underlying .ank image and optimize disk space. If your source VM is not tagged yet, we will assign one . **We highly recommend pushing this VM Template/Tag to your registry so [disk usage is optimized](https://docs.veertu.com/anka/arm/getting-started/creating-your-first-vm/#disk-optimization).**
- **In Anka 3.0** we now require a tagged source VM before cloning in order to share the underlying .ank image and optimize disk space. If your source VM is not tagged yet, we will assign one . **We highly recommend pushing this VM Template/Tag to your registry so [disk usage is optimized](https://docs.veertu.com/anka/apple/getting-started/creating-your-first-vm/#disk-optimization).**

## Configuration Reference

Expand Down
2 changes: 1 addition & 1 deletion docs/post-processors/anka-registry-push.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Whether or not to forcefully push, regardless of a tag already existing

## Other

When using `packer build -force`, the post-processor will issue a [revert API call](https://ankadocs.veertu.com/docs/anka-build-cloud/working-with-registry-and-api/#revert) to remove the existing tag before pushing the new.
When using `packer build -force`, the post-processor will issue a [revert API call](https://docs.veertu.com/anka/anka-build-cloud/working-with-registry-and-api/#revert) to remove the existing tag before pushing the new.

## Example

Expand Down
Loading

0 comments on commit 25ffaba

Please sign in to comment.