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
d5ce8ddb
Commit
d5ce8ddb
authored
Nov 09, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/docker: export the final image
parent
d27ceaf5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
1 deletion
+64
-1
builder/docker/builder.go
builder/docker/builder.go
+1
-0
builder/docker/config.go
builder/docker/config.go
+2
-1
builder/docker/step_export.go
builder/docker/step_export.go
+61
-0
No files found.
builder/docker/builder.go
View file @
d5ce8ddb
...
...
@@ -41,6 +41,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
StepPull
{},
&
StepRun
{},
&
StepProvision
{},
&
StepExport
{},
}
// Setup the state bag and initial state for the steps
...
...
builder/docker/config.go
View file @
d5ce8ddb
...
...
@@ -8,6 +8,7 @@ import (
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
ExportPath
string
`mapstructure:"export_path"`
Image
string
tpl
*
packer
.
ConfigTemplate
...
...
builder/docker/step_export.go
0 → 100644
View file @
d5ce8ddb
package
docker
import
(
"bytes"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
"os"
"os/exec"
)
// StepExport exports the container to a flat tar file.
type
StepExport
struct
{}
func
(
s
*
StepExport
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
containerId
:=
state
.
Get
(
"container_id"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Exporting the container"
)
// Args that we're going to pass to Docker
args
:=
[]
string
{
"export"
,
containerId
}
// Open the file that we're going to write to
f
,
err
:=
os
.
Create
(
config
.
ExportPath
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating output file: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
defer
f
.
Close
()
// Export the thing, take stderr and point it to the file
var
stderr
bytes
.
Buffer
cmd
:=
exec
.
Command
(
"docker"
,
args
...
)
cmd
.
Stdout
=
f
cmd
.
Stderr
=
&
stderr
log
.
Printf
(
"Starting container with args: %v"
,
args
)
if
err
:=
cmd
.
Start
();
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error exporting: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
if
err
:=
cmd
.
Wait
();
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error exporting: %s
\n
Stderr: %s"
,
err
,
stderr
.
String
())
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
func
(
s
*
StepExport
)
Cleanup
(
state
multistep
.
StateBag
)
{}
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