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
2b89da50
Commit
2b89da50
authored
Nov 09, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/docker: UploadDir
parent
ab5f7197
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
1 deletion
+77
-1
builder/docker/communicator.go
builder/docker/communicator.go
+77
-1
No files found.
builder/docker/communicator.go
View file @
2b89da50
...
@@ -91,11 +91,87 @@ func (c *Communicator) Upload(dst string, src io.Reader) error {
...
@@ -91,11 +91,87 @@ func (c *Communicator) Upload(dst string, src io.Reader) error {
}
}
func
(
c
*
Communicator
)
UploadDir
(
dst
string
,
src
string
,
exclude
[]
string
)
error
{
func
(
c
*
Communicator
)
UploadDir
(
dst
string
,
src
string
,
exclude
[]
string
)
error
{
// Create the temporary directory that will store the contents of "src"
// for copying into the container.
td
,
err
:=
ioutil
.
TempDir
(
c
.
HostDir
,
"dirupload"
)
if
err
!=
nil
{
return
err
}
defer
os
.
RemoveAll
(
td
)
walkFn
:=
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
if
err
!=
nil
{
return
err
}
relpath
,
err
:=
filepath
.
Rel
(
src
,
path
)
if
err
!=
nil
{
return
err
}
hostpath
:=
filepath
.
Join
(
td
,
relpath
)
// If it is a directory, just create it
if
info
.
IsDir
()
{
return
os
.
MkdirAll
(
hostpath
,
info
.
Mode
())
}
// It is a file, copy it over, including mode.
src
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
err
}
defer
src
.
Close
()
dst
,
err
:=
os
.
Create
(
hostpath
)
if
err
!=
nil
{
return
err
}
defer
dst
.
Close
()
if
_
,
err
:=
io
.
Copy
(
dst
,
src
);
err
!=
nil
{
return
err
}
si
,
err
:=
src
.
Stat
()
if
err
!=
nil
{
return
err
}
return
dst
.
Chmod
(
si
.
Mode
())
}
// Copy the entire directory tree to the temporary directory
if
err
:=
filepath
.
Walk
(
src
,
walkFn
);
err
!=
nil
{
return
err
}
// Determine the destination directory
containerSrc
:=
filepath
.
Join
(
c
.
ContainerDir
,
filepath
.
Base
(
td
))
containerDst
:=
dst
if
src
[
len
(
src
)
-
1
]
!=
'/'
{
containerDst
=
filepath
.
Join
(
dst
,
filepath
.
Base
(
src
))
}
// Make the directory, then copy into it
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
fmt
.
Sprintf
(
"set -e; mkdir -p %s; cp -R %s/* %s"
,
containerDst
,
containerSrc
,
containerDst
),
}
if
err
:=
c
.
Start
(
cmd
);
err
!=
nil
{
return
err
}
// Wait for the copy to complete
cmd
.
Wait
()
if
cmd
.
ExitStatus
!=
0
{
return
fmt
.
Errorf
(
"Upload failed with non-zero exit status: %d"
,
cmd
.
ExitStatus
)
}
return
nil
return
nil
}
}
func
(
c
*
Communicator
)
Download
(
src
string
,
dst
io
.
Writer
)
error
{
func
(
c
*
Communicator
)
Download
(
src
string
,
dst
io
.
Writer
)
error
{
return
nil
panic
(
"not implemented"
)
}
}
// Runs the given command and blocks until completion
// Runs the given command and blocks until completion
...
...
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