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
d7f93224
Commit
d7f93224
authored
Jul 30, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/chroot: mount extra paths
parent
618e1b16
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
15 deletions
+96
-15
builder/amazon/chroot/builder.go
builder/amazon/chroot/builder.go
+15
-14
builder/amazon/chroot/step_mount_device.go
builder/amazon/chroot/step_mount_device.go
+2
-1
builder/amazon/chroot/step_mount_extra.go
builder/amazon/chroot/step_mount_extra.go
+79
-0
No files found.
builder/amazon/chroot/builder.go
View file @
d7f93224
...
...
@@ -24,13 +24,13 @@ type Config struct {
common
.
PackerConfig
`mapstructure:",squash"`
awscommon
.
AccessConfig
`mapstructure:",squash"`
AttachedDevicePath
string
`mapstructure:"attached_device_path"`
ChrootMounts
[]
string
`mapstructure:"chroot_mounts"`
DevicePath
string
`mapstructure:"device_path"`
MountCommand
string
`mapstructure:"mount_command"`
MountPath
string
`mapstructure:"mount_path"`
SourceAmi
string
`mapstructure:"source_ami"`
UnmountCommand
string
`mapstructure:"unmount_command"`
AttachedDevicePath
string
`mapstructure:"attached_device_path"`
ChrootMounts
[]
[]
string
`mapstructure:"chroot_mounts"`
DevicePath
string
`mapstructure:"device_path"`
MountCommand
string
`mapstructure:"mount_command"`
MountPath
string
`mapstructure:"mount_path"`
SourceAmi
string
`mapstructure:"source_ami"`
UnmountCommand
string
`mapstructure:"unmount_command"`
}
type
Builder
struct
{
...
...
@@ -46,16 +46,16 @@ func (b *Builder) Prepare(raws ...interface{}) error {
// Defaults
if
b
.
config
.
ChrootMounts
==
nil
{
b
.
config
.
ChrootMounts
=
make
([]
string
,
0
)
b
.
config
.
ChrootMounts
=
make
([]
[]
string
,
0
)
}
if
len
(
b
.
config
.
ChrootMounts
)
==
0
{
b
.
config
.
ChrootMounts
=
[]
string
{
"{{.MountCommand}} -t proc proc {{.MountPath}}/proc"
,
"{{.MountCommand}} -t sysfs sysfs {{.MountPath}}/sys"
,
"{{.MountCommand}} -t bind /dev {{.MountPath}}/dev"
,
"{{.MountCommand}} -t devpts devpts {{.MountPath}}/dev/pts"
,
"{{.MountCommand}} -t binfmt_misc binfmt_misc {{.MountPath}}/proc/sys/fs/binfmt_misc"
,
b
.
config
.
ChrootMounts
=
[]
[]
string
{
[]
string
{
"proc"
,
"proc"
,
"/proc"
}
,
[]
string
{
"sysfs"
,
"sysfs"
,
"/sys"
}
,
[]
string
{
"bind"
,
"/dev"
,
"/dev"
}
,
[]
string
{
"devpts"
,
"devpts"
,
"/dev/pts"
}
,
[]
string
{
"binfmt_misc"
,
"binfmt_misc"
,
"/proc/sys/fs/binfmt_misc"
}
,
}
}
...
...
@@ -126,6 +126,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
StepCreateVolume
{},
&
StepAttachVolume
{},
&
StepMountDevice
{},
&
StepMountExtra
{},
}
// Run!
...
...
builder/amazon/chroot/step_mount_device.go
View file @
d7f93224
...
...
@@ -32,7 +32,7 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction
mountPathRaw
:=
new
(
bytes
.
Buffer
)
t
:=
template
.
Must
(
template
.
New
(
"mountPath"
)
.
Parse
(
config
.
MountPath
))
t
.
Execute
(
mountPathRaw
,
&
mountPathData
{
Device
:
filepath
.
Base
name
(
device
),
Device
:
filepath
.
Base
(
device
),
})
mountPath
:=
mountPathRaw
.
String
()
...
...
@@ -60,6 +60,7 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction
// Set the mount path so we remember to unmount it later
s
.
mountPath
=
mountPath
state
[
"mount_path"
]
=
s
.
mountPath
return
multistep
.
ActionContinue
}
...
...
builder/amazon/chroot/step_mount_extra.go
0 → 100644
View file @
d7f93224
package
chroot
import
(
"bytes"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"os"
"os/exec"
)
// StepMountExtra mounts the attached device.
//
// Produces:
// mount_path string - The location where the volume was mounted.
type
StepMountExtra
struct
{
mounts
[]
string
}
func
(
s
*
StepMountExtra
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
Config
)
mountPath
:=
state
[
"mount_path"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
s
.
mounts
=
make
([]
string
,
0
,
len
(
config
.
ChrootMounts
))
ui
.
Say
(
"Mounting additional paths within the chroot..."
)
for
_
,
mountInfo
:=
range
config
.
ChrootMounts
{
innerPath
:=
mountPath
+
mountInfo
[
2
]
if
err
:=
os
.
MkdirAll
(
innerPath
,
0755
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating mount directory: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
ui
.
Message
(
fmt
.
Sprintf
(
"Mounting: %s"
,
mountInfo
[
2
]))
stderr
:=
new
(
bytes
.
Buffer
)
mountCommand
:=
fmt
.
Sprintf
(
"%s -t %s %s %s"
,
config
.
MountCommand
,
mountInfo
[
0
],
mountInfo
[
1
],
innerPath
)
cmd
:=
exec
.
Command
(
"/bin/sh"
,
"-c"
,
mountCommand
)
cmd
.
Stderr
=
stderr
if
err
:=
cmd
.
Run
();
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error mounting: %s
\n
Stderr: %s"
,
err
,
stderr
.
String
())
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
s
.
mounts
=
append
(
s
.
mounts
,
innerPath
)
}
return
multistep
.
ActionContinue
}
func
(
s
*
StepMountExtra
)
Cleanup
(
state
map
[
string
]
interface
{})
{
if
s
.
mounts
==
nil
{
return
}
config
:=
state
[
"config"
]
.
(
*
Config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
for
_
,
path
:=
range
s
.
mounts
{
unmountCommand
:=
fmt
.
Sprintf
(
"%s %s"
,
config
.
UnmountCommand
,
path
)
cmd
:=
exec
.
Command
(
"bin/sh"
,
"-c"
,
unmountCommand
)
if
err
:=
cmd
.
Run
();
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error unmounting root device: %s"
,
err
))
return
}
}
}
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