allow to skip a post processor
This commit is contained in:
parent
905db043c4
commit
4bf3cd44fc
@ -102,7 +102,7 @@ func TestBuildExceptFileCommaFlags(t *testing.T) {
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"-except=chocolate",
|
||||
"-except=chocolate,apple",
|
||||
filepath.Join(testFixture("build-only"), "template.json"),
|
||||
}
|
||||
|
||||
@ -112,12 +112,12 @@ func TestBuildExceptFileCommaFlags(t *testing.T) {
|
||||
fatalCommand(t, c.Meta)
|
||||
}
|
||||
|
||||
for _, f := range []string{"chocolate.txt"} {
|
||||
for _, f := range []string{"chocolate.txt", "apple.txt"} {
|
||||
if fileExists(f) {
|
||||
t.Errorf("Expected NOT to find %s", f)
|
||||
}
|
||||
}
|
||||
for _, f := range []string{"vanilla.txt", "cherry.txt", "apple.txt", "peach.txt"} {
|
||||
for _, f := range []string{"vanilla.txt", "cherry.txt", "peach.txt"} {
|
||||
if !fileExists(f) {
|
||||
t.Errorf("Expected to find %s", f)
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/hashicorp/packer/helper/flag-kv"
|
||||
"github.com/hashicorp/packer/helper/flag-slice"
|
||||
kvflag "github.com/hashicorp/packer/helper/flag-kv"
|
||||
sliceflag "github.com/hashicorp/packer/helper/flag-slice"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/template"
|
||||
)
|
||||
@ -31,9 +31,7 @@ type Meta struct {
|
||||
Version string
|
||||
|
||||
// These are set by command-line flags
|
||||
flagBuildExcept []string
|
||||
flagBuildOnly []string
|
||||
flagVars map[string]string
|
||||
flagVars map[string]string
|
||||
}
|
||||
|
||||
// Core returns the core for the given template given the configured
|
||||
@ -59,7 +57,7 @@ func (m *Meta) BuildNames(c *packer.Core) []string {
|
||||
// TODO: test
|
||||
|
||||
// Filter the "only"
|
||||
if len(m.flagBuildOnly) > 0 {
|
||||
if len(m.CoreConfig.Only) > 0 {
|
||||
// Build a set of all the available names
|
||||
nameSet := make(map[string]struct{})
|
||||
for _, n := range c.BuildNames() {
|
||||
@ -67,8 +65,8 @@ func (m *Meta) BuildNames(c *packer.Core) []string {
|
||||
}
|
||||
|
||||
// Build our result set which we pre-allocate some sane number
|
||||
result := make([]string, 0, len(m.flagBuildOnly))
|
||||
for _, n := range m.flagBuildOnly {
|
||||
result := make([]string, 0, len(m.CoreConfig.Only))
|
||||
for _, n := range m.CoreConfig.Only {
|
||||
if _, ok := nameSet[n]; ok {
|
||||
result = append(result, n)
|
||||
}
|
||||
@ -78,10 +76,10 @@ func (m *Meta) BuildNames(c *packer.Core) []string {
|
||||
}
|
||||
|
||||
// Filter the "except"
|
||||
if len(m.flagBuildExcept) > 0 {
|
||||
if len(m.CoreConfig.Except) > 0 {
|
||||
// Build a set of the things we don't want
|
||||
nameSet := make(map[string]struct{})
|
||||
for _, n := range m.flagBuildExcept {
|
||||
for _, n := range m.CoreConfig.Except {
|
||||
nameSet[n] = struct{}{}
|
||||
}
|
||||
|
||||
@ -111,8 +109,8 @@ func (m *Meta) FlagSet(n string, fs FlagSetFlags) *flag.FlagSet {
|
||||
// FlagSetBuildFilter tells us to enable the settings for selecting
|
||||
// builds we care about.
|
||||
if fs&FlagSetBuildFilter != 0 {
|
||||
f.Var((*sliceflag.StringFlag)(&m.flagBuildExcept), "except", "")
|
||||
f.Var((*sliceflag.StringFlag)(&m.flagBuildOnly), "only", "")
|
||||
f.Var((*sliceflag.StringFlag)(&m.CoreConfig.Except), "except", "")
|
||||
f.Var((*sliceflag.StringFlag)(&m.CoreConfig.Only), "only", "")
|
||||
}
|
||||
|
||||
// FlagSetVars tells us what variables to use
|
||||
|
@ -21,10 +21,12 @@
|
||||
],
|
||||
"post-processors": [
|
||||
{
|
||||
"name": "apple",
|
||||
"type": "shell-local",
|
||||
"inline": ["touch apple.txt"]
|
||||
},
|
||||
{
|
||||
"name": "peach",
|
||||
"type": "shell-local",
|
||||
"inline": ["touch peach.txt"]
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/hashicorp/go-version"
|
||||
multierror "github.com/hashicorp/go-multierror"
|
||||
version "github.com/hashicorp/go-version"
|
||||
"github.com/hashicorp/packer/template"
|
||||
"github.com/hashicorp/packer/template/interpolate"
|
||||
)
|
||||
@ -20,6 +20,9 @@ type Core struct {
|
||||
builds map[string]*template.Builder
|
||||
version string
|
||||
secrets []string
|
||||
|
||||
except []string
|
||||
only []string
|
||||
}
|
||||
|
||||
// CoreConfig is the structure for initializing a new Core. Once a CoreConfig
|
||||
@ -30,6 +33,10 @@ type CoreConfig struct {
|
||||
Variables map[string]string
|
||||
SensitiveVariables []string
|
||||
Version string
|
||||
|
||||
// These are set by command-line flags
|
||||
Except []string
|
||||
Only []string
|
||||
}
|
||||
|
||||
// The function type used to lookup Builder implementations.
|
||||
@ -61,6 +68,8 @@ func NewCore(c *CoreConfig) (*Core, error) {
|
||||
components: c.Components,
|
||||
variables: c.Variables,
|
||||
version: c.Version,
|
||||
only: c.Only,
|
||||
except: c.Except,
|
||||
}
|
||||
|
||||
if err := result.validate(); err != nil {
|
||||
@ -126,7 +135,7 @@ func (c *Core) Build(n string) (Build, error) {
|
||||
provisioners := make([]coreBuildProvisioner, 0, len(c.Template.Provisioners))
|
||||
for _, rawP := range c.Template.Provisioners {
|
||||
// If we're skipping this, then ignore it
|
||||
if rawP.Skip(rawName) {
|
||||
if rawP.OnlyExcept.Skip(rawName) {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -172,7 +181,11 @@ func (c *Core) Build(n string) (Build, error) {
|
||||
current := make([]coreBuildPostProcessor, 0, len(rawPs))
|
||||
for _, rawP := range rawPs {
|
||||
// If we skip, ignore
|
||||
if rawP.Skip(rawName) {
|
||||
rawP.OnlyExcept.Except = append(rawP.OnlyExcept.Except, c.except...)
|
||||
if rawP.OnlyExcept.Skip(rawName) {
|
||||
continue
|
||||
}
|
||||
if rawP.OnlyExcept.Skip(rawP.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
multierror "github.com/hashicorp/go-multierror"
|
||||
"github.com/hashicorp/packer/packer/tmp"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
@ -149,6 +149,7 @@ func (r *rawTemplate) Template() (*Template, error) {
|
||||
delete(c, "only")
|
||||
delete(c, "keep_input_artifact")
|
||||
delete(c, "type")
|
||||
delete(c, "name")
|
||||
if len(c) > 0 {
|
||||
pp.Config = c
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
multierror "github.com/hashicorp/go-multierror"
|
||||
)
|
||||
|
||||
// Template represents the parsed template that is used to configure
|
||||
@ -40,6 +40,7 @@ type Builder struct {
|
||||
type PostProcessor struct {
|
||||
OnlyExcept `mapstructure:",squash"`
|
||||
|
||||
Name string
|
||||
Type string
|
||||
KeepInputArtifact bool `mapstructure:"keep_input_artifact"`
|
||||
Config map[string]interface{}
|
||||
|
Loading…
x
Reference in New Issue
Block a user