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
7fa23850
Commit
7fa23850
authored
Sep 26, 2013
by
Matthew Hooker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
dd356d33
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
10 deletions
+38
-10
builder/amazon/chroot/builder.go
builder/amazon/chroot/builder.go
+6
-0
builder/amazon/chroot/communicator.go
builder/amazon/chroot/communicator.go
+5
-7
builder/amazon/chroot/copy_files.go
builder/amazon/chroot/copy_files.go
+21
-0
builder/amazon/chroot/step_chroot_provision.go
builder/amazon/chroot/step_chroot_provision.go
+4
-2
builder/amazon/chroot/step_copy_files.go
builder/amazon/chroot/step_copy_files.go
+2
-1
No files found.
builder/amazon/chroot/builder.go
View file @
7fa23850
...
...
@@ -31,6 +31,7 @@ type Config struct {
DevicePath
string
`mapstructure:"device_path"`
MountCommand
string
`mapstructure:"mount_command"`
ChrootCommand
string
`mapstructure:"chroot_command"`
CopyCommand
string
`mapstructure:"copy_command"`
MountPath
string
`mapstructure:"mount_path"`
SourceAmi
string
`mapstructure:"source_ami"`
UnmountCommand
string
`mapstructure:"unmount_command"`
...
...
@@ -87,6 +88,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b
.
config
.
ChrootCommand
=
"chroot"
}
if
b
.
config
.
CopyCommand
==
""
{
b
.
config
.
CopyCommand
=
"cp"
}
if
b
.
config
.
MountPath
==
""
{
b
.
config
.
MountPath
=
"packer-amazon-chroot-volumes/{{.Device}}"
}
...
...
@@ -135,6 +140,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
"device_path"
:
&
b
.
config
.
DevicePath
,
"mount_command"
:
&
b
.
config
.
MountCommand
,
"chroot_command"
:
&
b
.
config
.
ChrootCommand
,
"copy_command"
:
&
b
.
config
.
CopyCommand
,
"source_ami"
:
&
b
.
config
.
SourceAmi
,
"unmount_command"
:
&
b
.
config
.
UnmountCommand
,
}
...
...
builder/amazon/chroot/communicator.go
View file @
7fa23850
...
...
@@ -15,6 +15,7 @@ import (
type
Communicator
struct
{
Chroot
string
ChrootCommand
string
CopyCommand
string
}
func
(
c
*
Communicator
)
Start
(
cmd
*
packer
.
RemoteCmd
)
error
{
...
...
@@ -71,13 +72,10 @@ func (c *Communicator) UploadDir(dst string, src string, exclude []string) error
}
dstPath
:=
filepath
.
Join
(
dst
,
path
)
f
,
err
:=
os
.
Open
(
fullPath
)
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
return
c
.
Upload
(
dstPath
,
f
)
dst
=
filepath
.
Join
(
c
.
Chroot
,
dst
)
log
.
Printf
(
"Uploading to chroot dir: %s"
,
dst
)
return
copySingle
(
dst
,
""
,
c
.
CopyCommand
)
//return c.Upload(dstPath, f)
}
log
.
Printf
(
"Uploading directory '%s' to '%s'"
,
src
,
dst
)
...
...
builder/amazon/chroot/copy_files.go
0 → 100644
View file @
7fa23850
package
chroot
import
(
"log"
"os"
"os/exec"
"path/filepath"
"syscall"
)
func
copySingle
(
dst
string
,
src
string
,
copyCommand
string
)
error
{
cpCommand
:=
fmt
.
Sprintf
(
"sudo cp -fn %s %s"
,
src
,
dest
)
localcmd
:=
exec
.
Command
(
"/bin/sh"
,
"-c"
,
cpCommand
)
log
.
Println
(
localcmd
.
Args
)
out
,
err
:=
localcmd
.
CombinedOutput
()
if
err
!=
nil
{
log
.
Println
(
err
)
}
log
.
Printf
(
"output: %s"
,
out
)
return
nil
}
builder/amazon/chroot/step_chroot_provision.go
View file @
7fa23850
...
...
@@ -15,12 +15,14 @@ func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction
hook
:=
state
.
Get
(
"hook"
)
.
(
packer
.
Hook
)
mountPath
:=
state
.
Get
(
"mount_path"
)
.
(
string
)
chrootCommand
:=
state
.
Get
(
"chroot_command"
)
.
(
string
)
copyCommand
:=
state
.
Get
(
"copy_command"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
// Create our communicator
comm
:=
&
Communicator
{
Chroot
:
mountPath
,
ChrootCommand
:
chrootCommand
,
Chroot
:
mountPath
,
ChrootCommand
:
chrootCommand
,
CopyCommand
:
copyCommand
,
}
// Provision
...
...
builder/amazon/chroot/step_copy_files.go
View file @
7fa23850
...
...
@@ -22,6 +22,7 @@ type StepCopyFiles struct {
func
(
s
*
StepCopyFiles
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
mountPath
:=
state
.
Get
(
"mount_path"
)
.
(
string
)
copyCmd
:=
state
.
Get
(
"copy_command"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
s
.
files
=
make
([]
string
,
0
,
len
(
config
.
CopyFiles
))
...
...
@@ -32,7 +33,7 @@ func (s *StepCopyFiles) Run(state multistep.StateBag) multistep.StepAction {
chrootPath
:=
filepath
.
Join
(
mountPath
,
path
)
log
.
Printf
(
"Copying '%s' to '%s'"
,
path
,
chrootPath
)
if
err
:=
s
.
copySingle
(
chrootPath
,
path
);
err
!=
nil
{
if
err
:=
copySingle
(
chrootPath
,
path
,
copyCmd
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error copying file: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
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