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
8d3cf7aa
Commit
8d3cf7aa
authored
Jul 30, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/chroot: provision within the chroot
parent
e0adf3b6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
130 additions
and
0 deletions
+130
-0
builder/amazon/chroot/communicator.go
builder/amazon/chroot/communicator.go
+82
-0
builder/amazon/chroot/communicator_test.go
builder/amazon/chroot/communicator_test.go
+14
-0
builder/amazon/chroot/step_chroot_provision.go
builder/amazon/chroot/step_chroot_provision.go
+34
-0
No files found.
builder/amazon/chroot/communicator.go
0 → 100644
View file @
8d3cf7aa
package
chroot
import
(
"github.com/mitchellh/packer/packer"
"io"
"log"
"os"
"os/exec"
"path/filepath"
"syscall"
)
// Communicator is a special communicator that works by executing
// commands locally but within a chroot.
type
Communicator
struct
{
Chroot
string
}
func
(
c
*
Communicator
)
Start
(
cmd
*
packer
.
RemoteCmd
)
error
{
chrootCmdPath
,
err
:=
exec
.
LookPath
(
"chroot"
)
if
err
!=
nil
{
return
err
}
localCmd
:=
exec
.
Command
(
chrootCmdPath
,
c
.
Chroot
,
"/bin/sh"
,
"-c"
,
cmd
.
Command
)
localCmd
.
Stdin
=
cmd
.
Stdin
localCmd
.
Stdout
=
cmd
.
Stdout
localCmd
.
Stderr
=
cmd
.
Stderr
log
.
Printf
(
"Executing: %s %#v"
,
localCmd
.
Path
,
localCmd
.
Args
)
if
err
:=
localCmd
.
Start
();
err
!=
nil
{
return
err
}
go
func
()
{
exitStatus
:=
0
if
err
:=
localCmd
.
Wait
();
err
!=
nil
{
if
exitErr
,
ok
:=
err
.
(
*
exec
.
ExitError
);
ok
{
exitStatus
=
1
// There is no process-independent way to get the REAL
// exit status so we just try to go deeper.
if
status
,
ok
:=
exitErr
.
Sys
()
.
(
syscall
.
WaitStatus
);
ok
{
exitStatus
=
status
.
ExitStatus
()
}
}
}
cmd
.
SetExited
(
exitStatus
)
}()
return
nil
}
func
(
c
*
Communicator
)
Upload
(
dst
string
,
r
io
.
Reader
)
error
{
dst
=
filepath
.
Join
(
c
.
Chroot
,
dst
)
f
,
err
:=
os
.
Open
(
dst
)
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
if
_
,
err
:=
io
.
Copy
(
f
,
r
);
err
!=
nil
{
return
err
}
return
nil
}
func
(
c
*
Communicator
)
Download
(
src
string
,
w
io
.
Writer
)
error
{
src
=
filepath
.
Join
(
c
.
Chroot
,
src
)
f
,
err
:=
os
.
Open
(
src
)
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
if
_
,
err
:=
io
.
Copy
(
w
,
f
);
err
!=
nil
{
return
err
}
return
nil
}
builder/amazon/chroot/communicator_test.go
0 → 100644
View file @
8d3cf7aa
package
chroot
import
(
"github.com/mitchellh/packer/packer"
"testing"
)
func
TestCommunicator_ImplementsCommunicator
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
&
Communicator
{}
if
_
,
ok
:=
raw
.
(
packer
.
Communicator
);
!
ok
{
t
.
Fatalf
(
"Communicator should be a communicator"
)
}
}
builder/amazon/chroot/step_chroot_provision.go
0 → 100644
View file @
8d3cf7aa
package
chroot
import
(
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
// StepChrootProvision provisions the instance within a chroot.
type
StepChrootProvision
struct
{
mounts
[]
string
}
func
(
s
*
StepChrootProvision
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
hook
:=
state
[
"hook"
]
.
(
packer
.
Hook
)
mountPath
:=
state
[
"mount_path"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
// Create our communicator
comm
:=
&
Communicator
{
Chroot
:
mountPath
,
}
// Provision
log
.
Println
(
"Running the provision hook"
)
if
err
:=
hook
.
Run
(
packer
.
HookProvision
,
ui
,
comm
,
nil
);
err
!=
nil
{
state
[
"error"
]
=
err
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
func
(
s
*
StepChrootProvision
)
Cleanup
(
state
map
[
string
]
interface
{})
{}
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