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
350aa4e5
Commit
350aa4e5
authored
May 29, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2055 from FGtatsuro/docker_tag_force
Support force option for docker-tag.
parents
b0c63ce8
09f379a9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
5 deletions
+57
-5
builder/docker/driver.go
builder/docker/driver.go
+1
-1
builder/docker/driver_docker.go
builder/docker/driver_docker.go
+8
-2
builder/docker/driver_mock.go
builder/docker/driver_mock.go
+3
-1
post-processor/docker-tag/post-processor.go
post-processor/docker-tag/post-processor.go
+2
-1
post-processor/docker-tag/post-processor_test.go
post-processor/docker-tag/post-processor_test.go
+43
-0
No files found.
builder/docker/driver.go
View file @
350aa4e5
...
@@ -46,7 +46,7 @@ type Driver interface {
...
@@ -46,7 +46,7 @@ type Driver interface {
StopContainer
(
id
string
)
error
StopContainer
(
id
string
)
error
// TagImage tags the image with the given ID
// TagImage tags the image with the given ID
TagImage
(
id
string
,
repo
string
)
error
TagImage
(
id
string
,
repo
string
,
force
bool
)
error
// Verify verifies that the driver can run
// Verify verifies that the driver can run
Verify
()
error
Verify
()
error
...
...
builder/docker/driver_docker.go
View file @
350aa4e5
...
@@ -240,9 +240,15 @@ func (d *DockerDriver) StopContainer(id string) error {
...
@@ -240,9 +240,15 @@ func (d *DockerDriver) StopContainer(id string) error {
return
exec
.
Command
(
"docker"
,
"rm"
,
id
)
.
Run
()
return
exec
.
Command
(
"docker"
,
"rm"
,
id
)
.
Run
()
}
}
func
(
d
*
DockerDriver
)
TagImage
(
id
string
,
repo
string
)
error
{
func
(
d
*
DockerDriver
)
TagImage
(
id
string
,
repo
string
,
force
bool
)
error
{
args
:=
[]
string
{
"tag"
}
if
force
{
args
=
append
(
args
,
"-f"
)
}
args
=
append
(
args
,
id
,
repo
)
var
stderr
bytes
.
Buffer
var
stderr
bytes
.
Buffer
cmd
:=
exec
.
Command
(
"docker"
,
"tag"
,
id
,
repo
)
cmd
:=
exec
.
Command
(
"docker"
,
args
...
)
cmd
.
Stderr
=
&
stderr
cmd
.
Stderr
=
&
stderr
if
err
:=
cmd
.
Start
();
err
!=
nil
{
if
err
:=
cmd
.
Start
();
err
!=
nil
{
...
...
builder/docker/driver_mock.go
View file @
350aa4e5
...
@@ -46,6 +46,7 @@ type MockDriver struct {
...
@@ -46,6 +46,7 @@ type MockDriver struct {
TagImageCalled
bool
TagImageCalled
bool
TagImageImageId
string
TagImageImageId
string
TagImageRepo
string
TagImageRepo
string
TagImageForce
bool
TagImageErr
error
TagImageErr
error
ExportReader
io
.
Reader
ExportReader
io
.
Reader
...
@@ -156,10 +157,11 @@ func (d *MockDriver) StopContainer(id string) error {
...
@@ -156,10 +157,11 @@ func (d *MockDriver) StopContainer(id string) error {
return
d
.
StopError
return
d
.
StopError
}
}
func
(
d
*
MockDriver
)
TagImage
(
id
string
,
repo
string
)
error
{
func
(
d
*
MockDriver
)
TagImage
(
id
string
,
repo
string
,
force
bool
)
error
{
d
.
TagImageCalled
=
true
d
.
TagImageCalled
=
true
d
.
TagImageImageId
=
id
d
.
TagImageImageId
=
id
d
.
TagImageRepo
=
repo
d
.
TagImageRepo
=
repo
d
.
TagImageForce
=
force
return
d
.
TagImageErr
return
d
.
TagImageErr
}
}
...
...
post-processor/docker-tag/post-processor.go
View file @
350aa4e5
...
@@ -18,6 +18,7 @@ type Config struct {
...
@@ -18,6 +18,7 @@ type Config struct {
Repository
string
`mapstructure:"repository"`
Repository
string
`mapstructure:"repository"`
Tag
string
`mapstructure:"tag"`
Tag
string
`mapstructure:"tag"`
Force
bool
ctx
interpolate
.
Context
ctx
interpolate
.
Context
}
}
...
@@ -64,7 +65,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
...
@@ -64,7 +65,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
ui
.
Message
(
"Tagging image: "
+
artifact
.
Id
())
ui
.
Message
(
"Tagging image: "
+
artifact
.
Id
())
ui
.
Message
(
"Repository: "
+
importRepo
)
ui
.
Message
(
"Repository: "
+
importRepo
)
err
:=
driver
.
TagImage
(
artifact
.
Id
(),
importRepo
)
err
:=
driver
.
TagImage
(
artifact
.
Id
(),
importRepo
,
p
.
config
.
Force
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
false
,
err
}
}
...
...
post-processor/docker-tag/post-processor_test.go
View file @
350aa4e5
...
@@ -68,4 +68,47 @@ func TestPostProcessor_PostProcess(t *testing.T) {
...
@@ -68,4 +68,47 @@ func TestPostProcessor_PostProcess(t *testing.T) {
if
driver
.
TagImageRepo
!=
"foo:bar"
{
if
driver
.
TagImageRepo
!=
"foo:bar"
{
t
.
Fatal
(
"bad repo"
)
t
.
Fatal
(
"bad repo"
)
}
}
if
driver
.
TagImageForce
{
t
.
Fatal
(
"bad force. force=false in default"
)
}
}
func
TestPostProcessor_PostProcess_Force
(
t
*
testing
.
T
)
{
driver
:=
&
docker
.
MockDriver
{}
p
:=
&
PostProcessor
{
Driver
:
driver
}
config
:=
testConfig
()
config
[
"force"
]
=
true
_
,
err
:=
common
.
DecodeConfig
(
&
p
.
config
,
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"err %s"
,
err
)
}
artifact
:=
&
packer
.
MockArtifact
{
BuilderIdValue
:
dockerimport
.
BuilderId
,
IdValue
:
"1234567890abcdef"
,
}
result
,
keep
,
err
:=
p
.
PostProcess
(
testUi
(),
artifact
)
if
_
,
ok
:=
result
.
(
packer
.
Artifact
);
!
ok
{
t
.
Fatal
(
"should be instance of Artifact"
)
}
if
!
keep
{
t
.
Fatal
(
"should keep"
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
!
driver
.
TagImageCalled
{
t
.
Fatal
(
"should call TagImage"
)
}
if
driver
.
TagImageImageId
!=
"1234567890abcdef"
{
t
.
Fatal
(
"bad image id"
)
}
if
driver
.
TagImageRepo
!=
"foo:bar"
{
t
.
Fatal
(
"bad repo"
)
}
if
!
driver
.
TagImageForce
{
t
.
Fatal
(
"bad force"
)
}
}
}
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