2013-03-23 02:00:23 -04:00
|
|
|
// This is the main package for the `packer` application.
|
|
|
|
package main
|
|
|
|
|
2013-03-25 19:29:26 -04:00
|
|
|
import (
|
|
|
|
"github.com/mitchellh/packer/packer"
|
2013-05-07 14:50:42 -04:00
|
|
|
"github.com/mitchellh/packer/packer/plugin"
|
2013-04-20 21:00:03 -04:00
|
|
|
"fmt"
|
2013-05-08 12:46:37 -04:00
|
|
|
"log"
|
2013-03-25 19:29:26 -04:00
|
|
|
"os"
|
2013-05-07 14:50:42 -04:00
|
|
|
"os/exec"
|
2013-05-08 13:52:23 -04:00
|
|
|
"time"
|
2013-03-25 19:29:26 -04:00
|
|
|
)
|
2013-03-23 21:40:26 -04:00
|
|
|
|
2013-03-23 02:00:23 -04:00
|
|
|
func main() {
|
2013-05-07 16:40:49 -04:00
|
|
|
commands := map[string]string {
|
|
|
|
"build": "packer-build",
|
|
|
|
}
|
|
|
|
|
|
|
|
commandKeys := make([]string, 0, len(commands))
|
|
|
|
for k, _ := range commands {
|
|
|
|
commandKeys = append(commandKeys, k)
|
|
|
|
}
|
|
|
|
|
2013-04-21 22:04:35 -04:00
|
|
|
envConfig := packer.DefaultEnvironmentConfig()
|
2013-05-07 16:40:49 -04:00
|
|
|
envConfig.Commands = commandKeys
|
2013-05-08 02:09:34 -04:00
|
|
|
envConfig.CommandFunc = func(n string) (packer.Command, error) {
|
2013-05-08 12:46:37 -04:00
|
|
|
log.Printf("Loading command: %s\n", n)
|
2013-05-07 16:40:49 -04:00
|
|
|
commandBin, ok := commands[n]
|
|
|
|
if !ok {
|
2013-05-08 12:46:37 -04:00
|
|
|
log.Printf("Command not found: %s\n", n)
|
2013-05-08 02:09:34 -04:00
|
|
|
return nil, nil
|
2013-05-07 16:40:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return plugin.Command(exec.Command(commandBin))
|
2013-05-07 14:50:42 -04:00
|
|
|
}
|
2013-04-21 22:04:35 -04:00
|
|
|
|
|
|
|
env, err := packer.NewEnvironment(envConfig)
|
2013-04-20 21:00:03 -04:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "Packer initialization error: \n\n%s\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2013-05-08 02:09:34 -04:00
|
|
|
exitCode, _ := env.Cli(os.Args[1:])
|
2013-05-08 13:52:23 -04:00
|
|
|
time.Sleep(1 * time.Second)
|
2013-05-08 02:09:34 -04:00
|
|
|
os.Exit(exitCode)
|
2013-03-23 02:00:23 -04:00
|
|
|
}
|