Add vagrant-cloud post-processor support for the vagrant builder

pull/7397/head
Vadym Haidamaka 7 years ago
parent 535dfd9333
commit 4855bc79c9

@ -15,14 +15,16 @@ const BuilderId = "vagrant"
type artifact struct {
OutputDir string
BoxName string
Provider string
}
// NewArtifact returns a vagrant artifact containing the .box file
func NewArtifact(dir string) (packer.Artifact, error) {
func NewArtifact(provider, dir string) packer.Artifact {
return &artifact{
OutputDir: dir,
BoxName: "package.box",
}, nil
Provider: provider,
}
}
func (*artifact) BuilderId() string {
@ -30,15 +32,15 @@ func (*artifact) BuilderId() string {
}
func (a *artifact) Files() []string {
return []string{a.BoxName}
return []string{filepath.Join(a.OutputDir, a.BoxName)}
}
func (a *artifact) Id() string {
return filepath.Join(a.OutputDir, a.BoxName)
return a.Provider
}
func (a *artifact) String() string {
return fmt.Sprintf("Vagrant box is %s", a.Id())
return fmt.Sprintf("Vagrant box '%s' for '%s' provider", a.BoxName, a.Provider)
}
func (a *artifact) State(name string) interface{} {

@ -20,13 +20,11 @@ func TestArtifactId(t *testing.T) {
a := &artifact{
OutputDir: "/my/dir",
BoxName: "package.box",
Provider: "virtualbox",
}
expected := "/my/dir/package.box"
if runtime.GOOS == "windows" {
expected = strings.Replace(expected, "/", "\\", -1)
}
if strings.Compare(a.Id(), expected) != 0 {
expected := "virtualbox"
if a.Id() != expected {
t.Fatalf("artifact ID should match: expected: %s received: %s", expected, a.Id())
}
}
@ -35,8 +33,9 @@ func TestArtifactString(t *testing.T) {
a := &artifact{
OutputDir: "/my/dir",
BoxName: "package.box",
Provider: "virtualbox",
}
expected := "Vagrant box is /my/dir/package.box"
expected := "Vagrant box 'package.box' for 'virtualbox' provider"
if runtime.GOOS == "windows" {
expected = strings.Replace(expected, "/", "\\", -1)
}

@ -264,7 +264,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
return nil, errors.New("Build was halted.")
}
return NewArtifact(b.config.OutputDir)
return NewArtifact(b.config.Provider, b.config.OutputDir), nil
}
// Cancel.

@ -1,7 +1,7 @@
// vagrant_cloud implements the packer.PostProcessor interface and adds a
// post-processor that uploads artifacts from the vagrant post-processor
// to Vagrant Cloud (vagrantcloud.com) or manages self hosted boxes on the
// Vagrant Cloud
// and vagrant builder to Vagrant Cloud (vagrantcloud.com) or manages
// self hosted boxes on the Vagrant Cloud
package vagrantcloud
import (
@ -17,6 +17,11 @@ import (
"github.com/hashicorp/packer/template/interpolate"
)
var builtins = map[string]string{
"mitchellh.post-processor.vagrant": "vagrant",
"vagrant": "vagrant",
}
const VAGRANT_CLOUD_URL = "https://vagrantcloud.com/api/v1"
type Config struct {
@ -113,16 +118,15 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
}
func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) {
// Only accepts input from the vagrant post-processor
if artifact.BuilderId() != "mitchellh.post-processor.vagrant" {
if _, ok := builtins[artifact.BuilderId()]; !ok {
return nil, false, fmt.Errorf(
"Unknown artifact type, requires box from vagrant post-processor: %s", artifact.BuilderId())
"Unknown artifact type, requires box from vagrant post-processor or vagrant builder: %s", artifact.BuilderId())
}
// We assume that there is only one .box file to upload
if !strings.HasSuffix(artifact.Files()[0], ".box") {
return nil, false, fmt.Errorf(
"Unknown files in artifact from vagrant post-processor: %s", artifact.Files())
"Unknown files in artifact, vagrant box is required: %s", artifact.Files())
}
if p.warnAtlasToken {

@ -61,6 +61,10 @@ one, by using `global_id` instead of `source_box`.
to Vagrant, this is the name to give it. If left blank, will default to
"packer_" plus your buildname.
- `provider` (string) - The vagrant [provider](docs/post-processors/vagrant.html).
This parameter is required to use vagrant builder with the `vagrant-cloud`
post-processor. Defaults to unset.
- `checksum` (string) - The checksum for the .box file. The type of the
checksum is specified with `checksum_type`, documented below.

@ -1,9 +1,9 @@
---
description: |
The Packer Vagrant Cloud post-processor receives a Vagrant box from the
`vagrant` post-processor and pushes it to Vagrant Cloud. Vagrant Cloud hosts
and serves boxes to Vagrant, allowing you to version and distribute boxes to an
organization in a simple way.
`vagrant` post-processor or vagrant builder and pushes it to Vagrant Cloud.
Vagrant Cloud hosts and serves boxes to Vagrant, allowing you to version and
distribute boxes to an organization in a simple way.
layout: docs
page_title: 'Vagrant Cloud - Post-Processors'
sidebar_current: 'docs-post-processors-vagrant-cloud'
@ -14,9 +14,9 @@ sidebar_current: 'docs-post-processors-vagrant-cloud'
Type: `vagrant-cloud`
The Packer Vagrant Cloud post-processor receives a Vagrant box from the
`vagrant` post-processor and pushes it to Vagrant Cloud. [Vagrant
Cloud](https://app.vagrantup.com/boxes/search) hosts and serves boxes to
Vagrant, allowing you to version and distribute boxes to an organization in a
`vagrant` post-processor or vagrant builder and pushes it to Vagrant Cloud.
[Vagrant Cloud](https://app.vagrantup.com/boxes/search) hosts and serves boxes
to Vagrant, allowing you to version and distribute boxes to an organization in a
simple way.
You'll need to be familiar with Vagrant Cloud, have an upgraded account to

Loading…
Cancel
Save