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
c18b74e9
Commit
c18b74e9
authored
Jan 19, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-processor/docker-push
parent
4e4a6ffd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
99 deletions
+18
-99
post-processor/docker-push/post-processor.go
post-processor/docker-push/post-processor.go
+18
-99
No files found.
post-processor/docker-push/post-processor.go
View file @
c18b74e9
...
...
@@ -2,21 +2,16 @@ package dockerpush
import
(
"fmt"
"github.com/mitchellh/packer/builder/docker"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"os/exec"
"github.com/mitchellh/packer/post-processor/docker-import"
"strings"
)
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
Repository
string
`mapstructure:"repository"`
Tag
string
`mapstructure:"tag"`
Registry
string
`mapstructure:"registry"`
Username
string
`mapstructure:"username"`
Password
string
`mapstructure:"password"`
Email
string
`mapstructure:"email"`
tpl
*
packer
.
ConfigTemplate
}
...
...
@@ -38,26 +33,6 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
// Accumulate any errors
errs
:=
new
(
packer
.
MultiError
)
templates
:=
map
[
string
]
*
string
{
"username"
:
&
p
.
config
.
Username
,
"password"
:
&
p
.
config
.
Password
,
"repository"
:
&
p
.
config
.
Repository
,
}
for
key
,
ptr
:=
range
templates
{
if
*
ptr
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"%s must be set"
,
key
))
}
*
ptr
,
err
=
p
.
config
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
key
,
err
))
}
}
if
len
(
errs
.
Errors
)
>
0
{
return
errs
}
...
...
@@ -67,81 +42,25 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
}
func
(
p
*
PostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
id
:=
artifact
.
Id
()
ui
.
Say
(
"Pushing image: "
+
id
)
if
p
.
config
.
Registry
==
""
{
if
p
.
config
.
Email
==
""
{
cmd
:=
exec
.
Command
(
"docker"
,
"login"
,
"-u="
+
p
.
config
.
Username
,
"-p="
+
p
.
config
.
Password
)
if
err
:=
cmd
.
Run
();
err
!=
nil
{
ui
.
Say
(
"Login to the registry "
+
p
.
config
.
Registry
+
" failed"
)
return
nil
,
false
,
err
}
}
else
{
cmd
:=
exec
.
Command
(
"docker"
,
"login"
,
"-u="
+
p
.
config
.
Username
,
"-p="
+
p
.
config
.
Password
,
"-e="
+
p
.
config
.
Email
)
if
err
:=
cmd
.
Run
();
err
!=
nil
{
ui
.
Say
(
"Login to the registry "
+
p
.
config
.
Registry
+
" failed"
)
return
nil
,
false
,
err
}
}
}
else
{
if
p
.
config
.
Email
==
""
{
cmd
:=
exec
.
Command
(
"docker"
,
"login"
,
"-u="
+
p
.
config
.
Username
,
"-p="
+
p
.
config
.
Password
,
p
.
config
.
Registry
)
if
err
:=
cmd
.
Run
();
err
!=
nil
{
ui
.
Say
(
"Login to the registry "
+
p
.
config
.
Registry
+
" failed"
)
return
nil
,
false
,
err
}
}
else
{
cmd
:=
exec
.
Command
(
"docker"
,
"login"
,
"-u="
+
p
.
config
.
Username
,
"-p="
+
p
.
config
.
Password
,
"-e="
+
p
.
config
.
Email
,
p
.
config
.
Registry
)
if
err
:=
cmd
.
Run
();
err
!=
nil
{
ui
.
Say
(
"Login to the registry "
+
p
.
config
.
Registry
+
" failed"
)
return
nil
,
false
,
err
}
}
if
artifact
.
BuilderId
()
!=
dockerimport
.
BuilderId
{
err
:=
fmt
.
Errorf
(
"Unknown artifact type: %s
\n
Can only import from docker-import artifacts."
,
artifact
.
BuilderId
())
return
nil
,
false
,
err
}
if
p
.
config
.
Tag
!=
""
{
cmd
:=
exec
.
Command
(
"docker"
,
"push"
,
p
.
config
.
Repository
+
":"
+
p
.
config
.
Tag
)
if
err
:=
cmd
.
Run
();
err
!=
nil
{
ui
.
Say
(
"Failed to push image: "
+
id
)
return
nil
,
false
,
err
}
driver
:=
&
docker
.
DockerDriver
{
Tpl
:
p
.
config
.
tpl
,
Ui
:
ui
}
}
else
{
cmd
:=
exec
.
Command
(
"docker"
,
"push"
,
p
.
config
.
Repository
)
if
err
:=
cmd
.
Run
();
err
!=
nil
{
ui
.
Say
(
"Failed to push image: "
+
id
)
return
nil
,
false
,
err
}
// Get the name. We strip off any tags from the name because the
// push doesn't use those.
name
:=
artifact
.
Id
()
if
i
:=
strings
.
Index
(
name
,
":"
);
i
>=
0
{
name
=
name
[
:
i
]
}
ui
.
Message
(
"Pushing: "
+
name
)
if
err
:=
driver
.
Push
(
name
);
err
!=
nil
{
return
nil
,
false
,
err
}
return
nil
,
false
,
nil
...
...
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