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
a15f629f
Commit
a15f629f
authored
Sep 28, 2013
by
Matthew Hooker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP copying files.
parent
831d5caa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
30 deletions
+40
-30
builder/amazon/chroot/communicator.go
builder/amazon/chroot/communicator.go
+26
-22
builder/amazon/chroot/copy_files.go
builder/amazon/chroot/copy_files.go
+6
-5
builder/amazon/chroot/step_copy_files.go
builder/amazon/chroot/step_copy_files.go
+8
-3
No files found.
builder/amazon/chroot/communicator.go
View file @
a15f629f
...
...
@@ -49,7 +49,7 @@ func (c *Communicator) Start(cmd *packer.RemoteCmd) error {
}
log
.
Printf
(
"Chroot executation e
nd
ed with '%d': '%s'"
,
"Chroot executation e
xit
ed with '%d': '%s'"
,
exitStatus
,
cmd
.
Command
)
cmd
.
SetExited
(
exitStatus
)
}()
...
...
@@ -67,35 +67,39 @@ func (c *Communicator) Upload(dst string, r io.Reader) error {
defer
os
.
Remove
(
tf
.
Name
())
io
.
Copy
(
tf
,
r
)
cpCmd
:=
fmt
.
Sprintf
(
"cp %s %s"
,
tf
.
Name
(),
dst
)
return
(
*
c
.
ChrootCm
d
(
cpCmd
))
.
Run
()
return
(
c
.
WrappedComman
d
(
cpCmd
))
.
Run
()
}
func
(
c
*
Communicator
)
UploadDir
(
dst
string
,
src
string
,
exclude
[]
string
)
error
{
walkFn
:=
func
(
fullPath
string
,
info
os
.
FileInfo
,
err
error
)
error
{
if
err
!=
nil
{
return
err
}
/*
walkFn := func(fullPath string, info os.FileInfo, err error) error {
if err != nil {
return err
}
path
,
err
:=
filepath
.
Rel
(
src
,
fullPath
)
if
err
!=
nil
{
return
err
}
path, err := filepath.Rel(src, fullPath)
if err != nil {
return err
}
for
_
,
e
:=
range
exclude
{
if
e
==
path
{
log
.
Printf
(
"Skipping excluded file: %s"
,
path
)
return
nil
for _, e := range exclude {
if e == path {
log.Printf("Skipping excluded file: %s", path)
return nil
}
}
}
chrootDest
:=
filepath
.
Join
(
c
.
Chroot
,
dst
,
path
)
log
.
Printf
(
"Uploading to chroot dir: %s"
,
dst
)
cpCmd
:=
fmt
.
Sprintf
(
"cp %s %s"
,
fullPath
,
chrootDest
)
return
c
.
ChrootCmd
(
cpCmd
)
.
Run
()
}
chrootDest := filepath.Join(c.Chroot, dst, path)
log.Printf("Uploading dir %s to chroot dir: %s", src, dst)
cpCmd := fmt.Sprintf("cp %s %s", fullPath, chrootDest)
return c.WrappedCommand(cpCmd).Run()
}
*/
log
.
Printf
(
"Uploading directory '%s' to '%s'"
,
src
,
dst
)
return
filepath
.
Walk
(
src
,
walkFn
)
chrootDest
:=
filepath
.
Join
(
c
.
Chroot
,
dst
)
log
.
Printf
(
"Uploading directory '%s' to '%s'"
,
src
,
chrootDest
)
cpCmd
:=
fmt
.
Sprintf
(
"cp -R %s* %s"
,
src
,
chrootDest
)
return
c
.
WrappedCommand
(
cpCmd
)
.
Run
()
}
func
(
c
*
Communicator
)
Download
(
src
string
,
w
io
.
Writer
)
error
{
...
...
builder/amazon/chroot/copy_files.go
View file @
a15f629f
...
...
@@ -7,12 +7,13 @@ import (
)
func
ChrootCommand
(
chroot
string
,
command
string
)
*
exec
.
Cmd
{
c
hrootCommand
:=
fmt
.
Sprintf
(
"chroot %s %s"
,
chroot
,
command
)
return
ShellCommand
(
c
hrootC
ommand
)
c
md
:=
fmt
.
Sprintf
(
"sudo chroot %s"
,
chroot
)
return
ShellCommand
(
c
md
,
c
ommand
)
}
func
ShellCommand
(
command
string
)
*
exec
.
Cmd
{
cmd
:=
exec
.
Command
(
"/bin/sh"
,
"-c"
,
command
)
log
.
Printf
(
"ShellCommand(%s) -> #%v"
,
command
,
cmd
.
Args
)
func
ShellCommand
(
commands
...
string
)
*
exec
.
Cmd
{
cmds
:=
append
([]
string
{
"-c"
},
commands
...
)
cmd
:=
exec
.
Command
(
"/bin/sh"
,
cmds
...
)
log
.
Printf
(
"ShellCommand: %s %v"
,
cmd
.
Path
,
cmd
.
Args
[
1
:
])
return
cmd
}
builder/amazon/chroot/step_copy_files.go
View file @
a15f629f
package
chroot
import
(
"bytes"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
...
...
@@ -22,6 +23,7 @@ func (s *StepCopyFiles) Run(state multistep.StateBag) multistep.StepAction {
mountPath
:=
state
.
Get
(
"mount_path"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
wrappedCommand
:=
state
.
Get
(
"wrappedCommand"
)
.
(
Command
)
stderr
:=
new
(
bytes
.
Buffer
)
s
.
files
=
make
([]
string
,
0
,
len
(
config
.
CopyFiles
))
if
len
(
config
.
CopyFiles
)
>
0
{
...
...
@@ -31,9 +33,12 @@ func (s *StepCopyFiles) Run(state multistep.StateBag) multistep.StepAction {
chrootPath
:=
filepath
.
Join
(
mountPath
,
path
)
log
.
Printf
(
"Copying '%s' to '%s'"
,
path
,
chrootPath
)
cmd
:=
fmt
.
Sprintf
(
"cp %s %s"
,
path
,
chrootPath
)
if
err
:=
wrappedCommand
(
cmd
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error copying file: %s"
,
err
)
cmd
:=
wrappedCommand
(
fmt
.
Sprintf
(
"cp %s %s"
,
path
,
chrootPath
))
stderr
.
Reset
()
cmd
.
Stderr
=
stderr
if
err
:=
cmd
.
Run
();
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error copying file: %s
\n
nStderr: %s"
,
err
,
stderr
.
String
())
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
...
...
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