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
aaaad835
Commit
aaaad835
authored
Jul 30, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/chroot: copyfiles support
parent
7ae0f3ba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
builder/amazon/chroot/builder.go
builder/amazon/chroot/builder.go
+10
-0
builder/amazon/chroot/step_copy_files.go
builder/amazon/chroot/step_copy_files.go
+70
-0
No files found.
builder/amazon/chroot/builder.go
View file @
aaaad835
...
...
@@ -26,6 +26,7 @@ type Config struct {
AttachedDevicePath
string
`mapstructure:"attached_device_path"`
ChrootMounts
[][]
string
`mapstructure:"chroot_mounts"`
CopyFiles
[]
string
`mapstructure:"copy_files"`
DevicePath
string
`mapstructure:"device_path"`
MountCommand
string
`mapstructure:"mount_command"`
MountPath
string
`mapstructure:"mount_path"`
...
...
@@ -49,6 +50,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b
.
config
.
ChrootMounts
=
make
([][]
string
,
0
)
}
if
b
.
config
.
CopyFiles
==
nil
{
b
.
config
.
CopyFiles
=
make
([]
string
,
0
)
}
if
len
(
b
.
config
.
ChrootMounts
)
==
0
{
b
.
config
.
ChrootMounts
=
[][]
string
{
[]
string
{
"proc"
,
"proc"
,
"/proc"
},
...
...
@@ -59,6 +64,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
}
}
if
len
(
b
.
config
.
CopyFiles
)
==
0
{
b
.
config
.
CopyFiles
=
[]
string
{
"/etc/resolv.conf"
}
}
if
b
.
config
.
DevicePath
==
""
{
b
.
config
.
DevicePath
=
"/dev/sdh"
}
...
...
@@ -127,6 +136,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
StepAttachVolume
{},
&
StepMountDevice
{},
&
StepMountExtra
{},
&
StepCopyFiles
{},
&
StepChrootProvision
{},
}
...
...
builder/amazon/chroot/step_copy_files.go
0 → 100644
View file @
aaaad835
package
chroot
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"io"
"log"
"os"
"path/filepath"
)
// StepCopyFiles copies some files from the host into the chroot environment.
type
StepCopyFiles
struct
{
mounts
[]
string
}
func
(
s
*
StepCopyFiles
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
Config
)
mountPath
:=
state
[
"mount_path"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
if
len
(
config
.
CopyFiles
)
>
0
{
ui
.
Say
(
"Copying files from host to chroot..."
)
for
_
,
path
:=
range
config
.
CopyFiles
{
ui
.
Message
(
path
)
chrootPath
:=
filepath
.
Join
(
mountPath
,
path
)
log
.
Printf
(
"Copying '%s' to '%s'"
,
path
,
chrootPath
)
if
err
:=
s
.
copySingle
(
chrootPath
,
path
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error copying file: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
}
}
return
multistep
.
ActionContinue
}
func
(
s
*
StepCopyFiles
)
Cleanup
(
state
map
[
string
]
interface
{})
{}
func
(
s
*
StepCopyFiles
)
copySingle
(
dst
,
src
string
)
error
{
srcInfo
,
err
:=
os
.
Stat
(
src
)
if
err
!=
nil
{
return
err
}
srcF
,
err
:=
os
.
Open
(
src
)
if
err
!=
nil
{
return
err
}
defer
srcF
.
Close
()
dstF
,
err
:=
os
.
Create
(
dst
)
if
err
!=
nil
{
return
err
}
if
_
,
err
:=
io
.
Copy
(
dstF
,
srcF
);
err
!=
nil
{
return
err
}
if
err
:=
os
.
Chmod
(
dst
,
srcInfo
.
Mode
());
err
!=
nil
{
return
err
}
return
nil
}
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