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
6dd0a21c
Commit
6dd0a21c
authored
Jul 26, 2015
by
Chris Bednarski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an artifice post-processor which allows you to override artifacts in a post-processor chain
parent
100d2b11
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
132 additions
and
0 deletions
+132
-0
plugin/post-processor-artifice/main.go
plugin/post-processor-artifice/main.go
+15
-0
post-processor/artifice/artifact.go
post-processor/artifice/artifact.go
+56
-0
post-processor/artifice/post-processor.go
post-processor/artifice/post-processor.go
+60
-0
post-processor/artifice/post-processor_test.go
post-processor/artifice/post-processor_test.go
+1
-0
No files found.
plugin/post-processor-artifice/main.go
0 → 100644
View file @
6dd0a21c
package
main
import
(
"github.com/mitchellh/packer/packer/plugin"
"github.com/mitchellh/packer/post-processor/artifice"
)
func
main
()
{
server
,
err
:=
plugin
.
Server
()
if
err
!=
nil
{
panic
(
err
)
}
server
.
RegisterPostProcessor
(
new
(
artifice
.
PostProcessor
))
server
.
Serve
()
}
post-processor/artifice/artifact.go
0 → 100644
View file @
6dd0a21c
package
artifice
import
(
"fmt"
"os"
"strings"
)
const
BuilderId
=
"packer.post-processor.artifice"
type
Artifact
struct
{
files
[]
string
}
func
NewArtifact
(
files
[]
string
)
(
*
Artifact
,
error
)
{
for
_
,
f
:=
range
files
{
if
_
,
err
:=
os
.
Stat
(
f
);
err
!=
nil
{
return
nil
,
err
}
}
artifact
:=
&
Artifact
{
files
:
files
,
}
return
artifact
,
nil
}
func
(
a
*
Artifact
)
BuilderId
()
string
{
return
BuilderId
}
func
(
a
*
Artifact
)
Files
()
[]
string
{
return
a
.
files
}
func
(
a
*
Artifact
)
Id
()
string
{
return
""
}
func
(
a
*
Artifact
)
String
()
string
{
files
:=
strings
.
Join
(
a
.
files
,
", "
)
return
fmt
.
Sprintf
(
"Created artifact from files: %s"
,
files
)
}
func
(
a
*
Artifact
)
State
(
name
string
)
interface
{}
{
return
nil
}
func
(
a
*
Artifact
)
Destroy
()
error
{
for
_
,
f
:=
range
a
.
files
{
err
:=
os
.
RemoveAll
(
f
)
if
err
!=
nil
{
return
err
}
}
return
nil
}
post-processor/artifice/post-processor.go
0 → 100644
View file @
6dd0a21c
package
artifice
import
(
"fmt"
"strings"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
)
// The artifact-override post-processor allows you to specify arbitrary files as
// artifacts. These will override any other artifacts created by the builder.
// This allows you to use a builder and provisioner to create some file, such as
// a compiled binary or tarball, extract it from the builder (VM or container)
// and then save that binary or tarball and throw away the builder.
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
Files
[]
string
`mapstructure:"files"`
Keep
bool
`mapstructure:"keep_input_artifact"`
ctx
interpolate
.
Context
}
type
PostProcessor
struct
{
config
Config
}
func
(
p
*
PostProcessor
)
Configure
(
raws
...
interface
{})
error
{
err
:=
config
.
Decode
(
&
p
.
config
,
&
config
.
DecodeOpts
{
Interpolate
:
true
,
InterpolateContext
:
&
p
.
config
.
ctx
,
InterpolateFilter
:
&
interpolate
.
RenderFilter
{
Exclude
:
[]
string
{},
},
},
raws
...
)
if
err
!=
nil
{
return
err
}
if
len
(
p
.
config
.
Files
)
==
0
{
return
fmt
.
Errorf
(
"No files specified in artifice configuration"
)
}
return
nil
}
func
(
p
*
PostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
if
len
(
artifact
.
Files
())
>
0
{
ui
.
Say
(
fmt
.
Sprintf
(
"Discarding artifact files: %s"
,
strings
.
Join
(
artifact
.
Files
(),
", "
)))
}
artifact
,
err
:=
NewArtifact
(
p
.
config
.
Files
)
ui
.
Say
(
fmt
.
Sprintf
(
"Using these artifact files: %s"
,
strings
.
Join
(
artifact
.
Files
(),
", "
)))
return
artifact
,
true
,
err
}
post-processor/artifice/post-processor_test.go
0 → 100644
View file @
6dd0a21c
package
artifice
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