From 759261dcf148ead99aa55a740779ca2419179455 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 25 Mar 2013 16:29:26 -0700 Subject: [PATCH] Bad commit message --- packer.go | 36 ++++-------------------------------- packer/build.go | 14 ++++++++++++++ packer/template.go | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 32 deletions(-) create mode 100644 packer/build.go create mode 100644 packer/template.go diff --git a/packer.go b/packer.go index 8f648ec07..67259a9cc 100644 --- a/packer.go +++ b/packer.go @@ -1,40 +1,12 @@ // This is the main package for the `packer` application. package main -import "github.com/mitchellh/packer/packer" -import "os" - -type RawTemplate struct { - Name string - Builders []map[string]interface{} - Provisioners []map[string]interface{} - Outputs []map[string]interface{} -} - -type Builder interface { - ConfigInterface() interface{} - Prepare() - Build() -} - -type Build interface { - Hook(name string) -} +import ( + "github.com/mitchellh/packer/packer" + "os" +) func main() { env := packer.NewEnvironment() os.Exit(env.Cli(os.Args[1:])) - /* - file, _ := ioutil.ReadFile("example.json") - - var tpl RawTemplate - json.Unmarshal(file, &tpl) - fmt.Printf("%#v\n", tpl) - - builderType, ok := tpl.Builders[0]["type"].(Build) - if !ok { - panic("OH NOES") - } - fmt.Printf("TYPE: %v\n", builderType) - */ } diff --git a/packer/build.go b/packer/build.go new file mode 100644 index 000000000..c707be974 --- /dev/null +++ b/packer/build.go @@ -0,0 +1,14 @@ +package packer + +// A build struct represents a single build job, the result of which should +// be a single machine image artifact. This artifact may be comprised of +// multiple files, of course, but it should be for only a single provider +// (such as VirtualBox, EC2, etc.). +type Build struct { + name string + builder Builder +} + +type Builder interface { + Prepare() +} diff --git a/packer/template.go b/packer/template.go new file mode 100644 index 000000000..0f2cf5327 --- /dev/null +++ b/packer/template.go @@ -0,0 +1,38 @@ +package packer + +import "encoding/json" + +// The rawTemplate struct represents the structure of a template read +// directly from a file. The builders and other components map just to +// "interface{}" pointers since we actually don't know what their contents +// are until we read the "type" field. +type rawTemplate struct { + Name string + Builders []map[string]interface{} + Provisioners []map[string]interface{} + Outputs []map[string]interface{} +} + +type Template struct { + Name string + Builders map[string]rawBuilderConfig +} + +// The rawBuilderConfig struct represents a raw, unprocessed builder +// configuration. It contains the name of the builder as well as the +// raw configuration. If requested, this is used to compile into a full +// builder configuration at some point. +type rawBuilderConfig struct { + builderName string + rawConfig interface{} +} + +func parseTemplate(data []byte) error { + var rawTpl rawTemplate + err := json.Unmarshal(data, &rawTpl) + if err != nil { + return err + } + + return nil +}