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
bbca2c32
Commit
bbca2c32
authored
Jan 19, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'docker-metadata' of
https://github.com/mmckeen/packer
into mmckeen-docker-metadata
parents
7ec05423
6d23d940
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
463 additions
and
1 deletion
+463
-1
config.go
config.go
+3
-1
plugin/post-processor-docker-import/main.go
plugin/post-processor-docker-import/main.go
+15
-0
plugin/post-processor-docker-import/main_test.go
plugin/post-processor-docker-import/main_test.go
+1
-0
plugin/post-processor-docker-push/main.go
plugin/post-processor-docker-push/main.go
+15
-0
plugin/post-processor-docker-push/main_test.go
plugin/post-processor-docker-push/main_test.go
+1
-0
post-processor/docker-import/post-processor.go
post-processor/docker-import/post-processor.go
+218
-0
post-processor/docker-import/post-processor_test.go
post-processor/docker-import/post-processor_test.go
+31
-0
post-processor/docker-push/post-processor.go
post-processor/docker-push/post-processor.go
+148
-0
post-processor/docker-push/post-processor_test.go
post-processor/docker-push/post-processor_test.go
+31
-0
No files found.
config.go
View file @
bbca2c32
...
...
@@ -42,7 +42,9 @@ const defaultConfig = `
"post-processors": {
"vagrant": "packer-post-processor-vagrant",
"vsphere": "packer-post-processor-vsphere"
"vsphere": "packer-post-processor-vsphere",
"docker-push": "packer-post-processor-docker-push",
"docker-import": "packer-post-processor-docker-import"
},
"provisioners": {
...
...
plugin/post-processor-docker-import/main.go
0 → 100644
View file @
bbca2c32
package
main
import
(
"github.com/mitchellh/packer/packer/plugin"
"github.com/mitchellh/packer/post-processor/docker-import"
)
func
main
()
{
server
,
err
:=
plugin
.
Server
()
if
err
!=
nil
{
panic
(
err
)
}
server
.
RegisterPostProcessor
(
new
(
dockerimport
.
PostProcessor
))
server
.
Serve
()
}
plugin/post-processor-docker-import/main_test.go
0 → 100644
View file @
bbca2c32
package
main
plugin/post-processor-docker-push/main.go
0 → 100644
View file @
bbca2c32
package
main
import
(
"github.com/mitchellh/packer/packer/plugin"
"github.com/mitchellh/packer/post-processor/docker-push"
)
func
main
()
{
server
,
err
:=
plugin
.
Server
()
if
err
!=
nil
{
panic
(
err
)
}
server
.
RegisterPostProcessor
(
new
(
dockerpush
.
PostProcessor
))
server
.
Serve
()
}
plugin/post-processor-docker-push/main_test.go
0 → 100644
View file @
bbca2c32
package
main
post-processor/docker-import/post-processor.go
0 → 100644
View file @
bbca2c32
package
dockerimport
import
(
"fmt"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"io"
"os"
"os/exec"
)
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
Repository
string
`mapstructure:"repository"`
Tag
string
`mapstructure:"tag"`
Dockerfile
string
`mapstructure:"dockerfile"`
tpl
*
packer
.
ConfigTemplate
}
type
PostProcessor
struct
{
config
Config
}
func
(
p
*
PostProcessor
)
Configure
(
raws
...
interface
{})
error
{
_
,
err
:=
common
.
DecodeConfig
(
&
p
.
config
,
raws
...
)
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
,
err
=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
.
UserVars
=
p
.
config
.
PackerUserVars
// Accumulate any errors
errs
:=
new
(
packer
.
MultiError
)
templates
:=
map
[
string
]
*
string
{
"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
}
return
nil
}
func
(
p
*
PostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
id
:=
artifact
.
Id
()
ui
.
Say
(
"Importing image: "
+
id
)
if
p
.
config
.
Tag
==
""
{
cmd
:=
exec
.
Command
(
"docker"
,
"import"
,
"-"
,
p
.
config
.
Repository
)
stdin
,
err
:=
cmd
.
StdinPipe
()
if
err
!=
nil
{
return
nil
,
false
,
err
}
// There should be only one artifact of the Docker builder
file
,
err
:=
os
.
Open
(
artifact
.
Files
()[
0
])
if
err
!=
nil
{
return
nil
,
false
,
err
}
defer
file
.
Close
()
if
err
:=
cmd
.
Start
();
err
!=
nil
{
ui
.
Say
(
"Image import failed"
)
return
nil
,
false
,
err
}
go
func
()
{
io
.
Copy
(
stdin
,
file
)
// close stdin so that program will exit
stdin
.
Close
()
}()
cmd
.
Wait
()
}
else
{
cmd
:=
exec
.
Command
(
"docker"
,
"import"
,
"-"
,
p
.
config
.
Repository
+
":"
+
p
.
config
.
Tag
)
stdin
,
err
:=
cmd
.
StdinPipe
()
if
err
!=
nil
{
return
nil
,
false
,
err
}
// There should be only one artifact of the Docker builder
file
,
err
:=
os
.
Open
(
artifact
.
Files
()[
0
])
if
err
!=
nil
{
return
nil
,
false
,
err
}
defer
file
.
Close
()
if
err
:=
cmd
.
Start
();
err
!=
nil
{
ui
.
Say
(
"Image import failed"
)
return
nil
,
false
,
err
}
go
func
()
{
io
.
Copy
(
stdin
,
file
)
// close stdin so that program will exit
stdin
.
Close
()
}()
cmd
.
Wait
()
}
// Process Dockerfile if provided
if
p
.
config
.
Dockerfile
!=
""
{
if
p
.
config
.
Tag
!=
""
{
cmd
:=
exec
.
Command
(
"docker"
,
"build"
,
"-t="
+
p
.
config
.
Repository
+
":"
+
p
.
config
.
Tag
,
"-"
)
stdin
,
err
:=
cmd
.
StdinPipe
()
if
err
!=
nil
{
return
nil
,
false
,
err
}
// open Dockerfile
file
,
err
:=
os
.
Open
(
p
.
config
.
Dockerfile
)
if
err
!=
nil
{
ui
.
Say
(
"Could not open Dockerfile: "
+
p
.
config
.
Dockerfile
)
return
nil
,
false
,
err
}
ui
.
Say
(
id
)
defer
file
.
Close
()
if
err
:=
cmd
.
Start
();
err
!=
nil
{
ui
.
Say
(
"Failed to build image: "
+
id
)
return
nil
,
false
,
err
}
go
func
()
{
io
.
Copy
(
stdin
,
file
)
// close stdin so that program will exit
stdin
.
Close
()
}()
cmd
.
Wait
()
}
else
{
cmd
:=
exec
.
Command
(
"docker"
,
"build"
,
"-t="
+
p
.
config
.
Repository
,
"-"
)
stdin
,
err
:=
cmd
.
StdinPipe
()
if
err
!=
nil
{
return
nil
,
false
,
err
}
// open Dockerfile
file
,
err
:=
os
.
Open
(
p
.
config
.
Dockerfile
)
if
err
!=
nil
{
ui
.
Say
(
"Could not open Dockerfile: "
+
p
.
config
.
Dockerfile
)
return
nil
,
false
,
err
}
ui
.
Say
(
id
)
defer
file
.
Close
()
if
err
:=
cmd
.
Start
();
err
!=
nil
{
ui
.
Say
(
"Failed to build image: "
+
id
)
return
nil
,
false
,
err
}
go
func
()
{
io
.
Copy
(
stdin
,
file
)
// close stdin so that program will exit
stdin
.
Close
()
}()
cmd
.
Wait
()
}
}
return
nil
,
false
,
nil
}
post-processor/docker-import/post-processor_test.go
0 → 100644
View file @
bbca2c32
package
dockerimport
import
(
"bytes"
"github.com/mitchellh/packer/packer"
"testing"
)
func
testConfig
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{}
}
func
testPP
(
t
*
testing
.
T
)
*
PostProcessor
{
var
p
PostProcessor
if
err
:=
p
.
Configure
(
testConfig
());
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
return
&
p
}
func
testUi
()
*
packer
.
BasicUi
{
return
&
packer
.
BasicUi
{
Reader
:
new
(
bytes
.
Buffer
),
Writer
:
new
(
bytes
.
Buffer
),
}
}
func
TestPostProcessor_ImplementsPostProcessor
(
t
*
testing
.
T
)
{
var
_
packer
.
PostProcessor
=
new
(
PostProcessor
)
}
post-processor/docker-push/post-processor.go
0 → 100644
View file @
bbca2c32
package
dockerpush
import
(
"fmt"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"os/exec"
)
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
}
type
PostProcessor
struct
{
config
Config
}
func
(
p
*
PostProcessor
)
Configure
(
raws
...
interface
{})
error
{
_
,
err
:=
common
.
DecodeConfig
(
&
p
.
config
,
raws
...
)
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
,
err
=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
.
UserVars
=
p
.
config
.
PackerUserVars
// 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
}
return
nil
}
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
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
}
}
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
}
}
return
nil
,
false
,
nil
}
post-processor/docker-push/post-processor_test.go
0 → 100644
View file @
bbca2c32
package
dockerpush
import
(
"bytes"
"github.com/mitchellh/packer/packer"
"testing"
)
func
testConfig
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{}
}
func
testPP
(
t
*
testing
.
T
)
*
PostProcessor
{
var
p
PostProcessor
if
err
:=
p
.
Configure
(
testConfig
());
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
return
&
p
}
func
testUi
()
*
packer
.
BasicUi
{
return
&
packer
.
BasicUi
{
Reader
:
new
(
bytes
.
Buffer
),
Writer
:
new
(
bytes
.
Buffer
),
}
}
func
TestPostProcessor_ImplementsPostProcessor
(
t
*
testing
.
T
)
{
var
_
packer
.
PostProcessor
=
new
(
PostProcessor
)
}
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