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
2e080ece
Commit
2e080ece
authored
Nov 08, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/docker: start a container
parent
4db609b2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
builder/docker/builder.go
builder/docker/builder.go
+1
-0
builder/docker/step_run.go
builder/docker/step_run.go
+53
-0
No files found.
builder/docker/builder.go
View file @
2e080ece
...
...
@@ -38,6 +38,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func
(
b
*
Builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
steps
:=
[]
multistep
.
Step
{
&
StepPull
{},
&
StepRun
{},
}
// Setup the state bag and initial state for the steps
...
...
builder/docker/step_run.go
0 → 100644
View file @
2e080ece
package
docker
import
(
"bytes"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"os/exec"
"strings"
)
type
StepRun
struct
{
containerId
string
}
func
(
s
*
StepRun
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Starting docker container with /bin/bash"
)
var
stdout
,
stderr
bytes
.
Buffer
cmd
:=
exec
.
Command
(
"docker"
,
"run"
,
"-d"
,
"-i"
,
"-t"
,
config
.
Image
,
"/bin/bash"
)
cmd
.
Stdout
=
&
stdout
cmd
.
Stderr
=
&
stderr
if
err
:=
cmd
.
Start
();
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error running container: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
if
err
:=
cmd
.
Wait
();
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error running container: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
s
.
containerId
=
strings
.
TrimSpace
(
stdout
.
String
())
ui
.
Message
(
fmt
.
Sprintf
(
"Container ID: %s"
,
s
.
containerId
))
return
multistep
.
ActionContinue
}
func
(
s
*
StepRun
)
Cleanup
(
state
multistep
.
StateBag
)
{
if
s
.
containerId
==
""
{
return
}
// TODO(mitchellh): handle errors
exec
.
Command
(
"docker"
,
"kill"
,
s
.
containerId
)
.
Run
()
}
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