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
b25ae21e
Commit
b25ae21e
authored
May 26, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: run provisioners
parent
b5f4ffa5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
108 additions
and
1 deletion
+108
-1
packer/builder_mock.go
packer/builder_mock.go
+6
-0
packer/core.go
packer/core.go
+43
-1
packer/core_test.go
packer/core_test.go
+34
-0
packer/test-fixtures/build-prov.json
packer/test-fixtures/build-prov.json
+9
-0
packer/testing.go
packer/testing.go
+16
-0
No files found.
packer/builder_mock.go
View file @
b25ae21e
...
...
@@ -42,6 +42,12 @@ func (tb *MockBuilder) Run(ui Ui, h Hook, c Cache) (Artifact, error) {
return
nil
,
nil
}
if
h
!=
nil
{
if
err
:=
h
.
Run
(
HookProvision
,
ui
,
nil
,
nil
);
err
!=
nil
{
return
nil
,
err
}
}
return
&
MockArtifact
{
IdValue
:
tb
.
ArtifactId
,
},
nil
...
...
packer/core.go
View file @
b25ae21e
...
...
@@ -118,13 +118,55 @@ func (c *Core) Build(n string) (Build, error) {
"builder type not found: %s"
,
configBuilder
.
Type
)
}
// TODO: template process name
// rawName is the uninterpolated name that we use for various lookups
rawName
:=
configBuilder
.
Name
// Setup the provisioners for this build
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
)
{
continue
}
// Get the provisioner
provisioner
,
err
:=
c
.
components
.
Provisioner
(
rawP
.
Type
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error initializing provisioner '%s': %s"
,
rawP
.
Type
,
err
)
}
if
provisioner
==
nil
{
return
nil
,
fmt
.
Errorf
(
"provisioner type not found: %s"
,
rawP
.
Type
)
}
// Get the configuration
config
:=
make
([]
interface
{},
1
,
2
)
config
[
0
]
=
rawP
.
Config
// TODO override
// If we're pausing, we wrap the provisioner in a special pauser.
if
rawP
.
PauseBefore
>
0
{
provisioner
=
&
PausedProvisioner
{
PauseBefore
:
rawP
.
PauseBefore
,
Provisioner
:
provisioner
,
}
}
provisioners
=
append
(
provisioners
,
coreBuildProvisioner
{
provisioner
:
provisioner
,
config
:
config
,
})
}
return
&
coreBuild
{
name
:
n
,
builder
:
builder
,
builderConfig
:
configBuilder
.
Config
,
builderType
:
configBuilder
.
Type
,
provisioners
:
provisioners
,
variables
:
c
.
variables
,
},
nil
}
...
...
packer/core_test.go
View file @
b25ae21e
...
...
@@ -120,6 +120,40 @@ func TestCoreBuild_nonExist(t *testing.T) {
}
}
func
TestCoreBuild_prov
(
t
*
testing
.
T
)
{
config
:=
TestCoreConfig
(
t
)
testCoreTemplate
(
t
,
config
,
fixtureDir
(
"build-prov.json"
))
b
:=
TestBuilder
(
t
,
config
,
"test"
)
p
:=
TestProvisioner
(
t
,
config
,
"test"
)
core
:=
TestCore
(
t
,
config
)
b
.
ArtifactId
=
"hello"
build
,
err
:=
core
.
Build
(
"test"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
_
,
err
:=
build
.
Prepare
();
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
artifact
,
err
:=
build
.
Run
(
nil
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
len
(
artifact
)
!=
1
{
t
.
Fatalf
(
"bad: %#v"
,
artifact
)
}
if
artifact
[
0
]
.
Id
()
!=
b
.
ArtifactId
{
t
.
Fatalf
(
"bad: %s"
,
artifact
[
0
]
.
Id
())
}
if
!
p
.
ProvCalled
{
t
.
Fatal
(
"provisioner not called"
)
}
}
func
TestCoreValidate
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
File
string
...
...
packer/test-fixtures/build-prov.json
0 → 100644
View file @
b25ae21e
{
"builders"
:
[{
"type"
:
"test"
}],
"provisioners"
:
[{
"type"
:
"test"
}]
}
packer/testing.go
View file @
b25ae21e
...
...
@@ -58,3 +58,19 @@ func TestBuilder(t *testing.T, c *CoreConfig, n string) *MockBuilder {
return
&
b
}
// TestProvisioner sets the prov. with the name n to the component finder
// and returns the mock.
func
TestProvisioner
(
t
*
testing
.
T
,
c
*
CoreConfig
,
n
string
)
*
MockProvisioner
{
var
b
MockProvisioner
c
.
Components
.
Provisioner
=
func
(
actual
string
)
(
Provisioner
,
error
)
{
if
actual
!=
n
{
return
nil
,
nil
}
return
&
b
,
nil
}
return
&
b
}
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