Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
a803af70
Commit
a803af70
authored
May 08, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the build command into the actual build command
parent
6633f3df
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
76 deletions
+78
-76
command/build/command.go
command/build/command.go
+32
-3
command/build/command_test.go
command/build/command_test.go
+46
-0
packer/build_command.go
packer/build_command.go
+0
-42
packer/build_command_test.go
packer/build_command_test.go
+0
-31
No files found.
command/build/command.go
View file @
a803af70
package
build
package
build
import
"github.com/mitchellh/packer/packer"
import
(
"github.com/mitchellh/packer/packer"
"io/ioutil"
)
type
Command
byte
type
Command
byte
func
(
Command
)
Run
(
env
packer
.
Environment
,
arg
[]
string
)
int
{
func
(
Command
)
Run
(
env
packer
.
Environment
,
args
[]
string
)
int
{
env
.
Ui
()
.
Say
(
"YO!"
)
if
len
(
args
)
!=
1
{
// TODO: Error message
return
1
}
// Read the file into a byte array so that we can parse the template
tplData
,
err
:=
ioutil
.
ReadFile
(
args
[
0
])
if
err
!=
nil
{
// TODO: Error message
return
1
}
// Parse the template into a machine-usable format
_
,
err
=
packer
.
ParseTemplate
(
tplData
)
if
err
!=
nil
{
// TODO: error message
return
1
}
// Go through each builder and compile the builds that we care about
//builds := make([]Build, 0, len(tpl.Builders))
//for name, rawConfig := range tpl.Builders {
//builder := env.Builder(name, rawConfig)
//build := env.Build(name, builder)
//builds = append(builds, build)
//}
return
0
return
0
}
}
...
...
command/build/command_test.go
View file @
a803af70
package
build
package
build
import
(
"bytes"
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"testing"
)
func
testEnvironment
()
packer
.
Environment
{
config
:=
packer
.
DefaultEnvironmentConfig
()
config
.
Ui
=
&
packer
.
ReaderWriterUi
{
new
(
bytes
.
Buffer
),
new
(
bytes
.
Buffer
),
}
env
,
err
:=
packer
.
NewEnvironment
(
config
)
if
err
!=
nil
{
panic
(
err
)
}
return
env
}
func
TestCommand_Run_NoArgs
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
command
:=
new
(
Command
)
result
:=
command
.
Run
(
testEnvironment
(),
make
([]
string
,
0
))
assert
.
Equal
(
result
,
1
,
"no args should error"
)
}
func
TestCommand_Run_MoreThanOneArg
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
command
:=
new
(
Command
)
args
:=
[]
string
{
"one"
,
"two"
}
result
:=
command
.
Run
(
testEnvironment
(),
args
)
assert
.
Equal
(
result
,
1
,
"More than one arg should fail"
)
}
func
TestCommand_Run_MissingFile
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
command
:=
new
(
Command
)
args
:=
[]
string
{
"i-better-not-exist"
}
result
:=
command
.
Run
(
testEnvironment
(),
args
)
assert
.
Equal
(
result
,
1
,
"a non-existent file should error"
)
}
packer/build_command.go
deleted
100644 → 0
View file @
6633f3df
package
packer
import
(
"io/ioutil"
)
type
buildCommand
byte
func
(
buildCommand
)
Run
(
env
Environment
,
args
[]
string
)
int
{
if
len
(
args
)
!=
1
{
// TODO: Error message
return
1
}
// Read the file into a byte array so that we can parse the template
tplData
,
err
:=
ioutil
.
ReadFile
(
args
[
0
])
if
err
!=
nil
{
// TODO: Error message
return
1
}
// Parse the template into a machine-usable format
_
,
err
=
ParseTemplate
(
tplData
)
if
err
!=
nil
{
// TODO: error message
return
1
}
// Go through each builder and compile the builds that we care about
//builds := make([]Build, 0, len(tpl.Builders))
//for name, rawConfig := range tpl.Builders {
//builder := env.Builder(name, rawConfig)
//build := env.Build(name, builder)
//builds = append(builds, build)
//}
return
0
}
func
(
buildCommand
)
Synopsis
()
string
{
return
"build machines images from Packer template"
}
packer/build_command_test.go
deleted
100644 → 0
View file @
6633f3df
package
packer
import
(
"cgl.tideland.biz/asserts"
"testing"
)
func
TestBuildCommand_Run_NoArgs
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
command
:=
new
(
buildCommand
)
result
:=
command
.
Run
(
testEnvironment
(),
make
([]
string
,
0
))
assert
.
Equal
(
result
,
1
,
"no args should error"
)
}
func
TestBuildCommand_Run_MoreThanOneArg
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
command
:=
new
(
buildCommand
)
args
:=
[]
string
{
"one"
,
"two"
}
result
:=
command
.
Run
(
testEnvironment
(),
args
)
assert
.
Equal
(
result
,
1
,
"More than one arg should fail"
)
}
func
TestBuildCommand_Run_MissingFile
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
command
:=
new
(
buildCommand
)
args
:=
[]
string
{
"i-better-not-exist"
}
result
:=
command
.
Run
(
testEnvironment
(),
args
)
assert
.
Equal
(
result
,
1
,
"a non-existent file should error"
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment