Adding documentation for import changes.

This commit is contained in:
Ladar Levison 2018-12-18 02:00:21 -06:00
parent 3cc83167c8
commit 6d10badc70
3 changed files with 169 additions and 102 deletions

View File

@ -14,22 +14,41 @@ import (
"github.com/hashicorp/packer/packer/plugin"
alicloudecsbuilder "github.com/hashicorp/packer/builder/alicloud/ecs"
alicloudimportpostprocessor "github.com/hashicorp/packer/post-processor/alicloud-import"
amazonchrootbuilder "github.com/hashicorp/packer/builder/amazon/chroot"
amazonebsbuilder "github.com/hashicorp/packer/builder/amazon/ebs"
amazonebssurrogatebuilder "github.com/hashicorp/packer/builder/amazon/ebssurrogate"
amazonebsvolumebuilder "github.com/hashicorp/packer/builder/amazon/ebsvolume"
amazonimportpostprocessor "github.com/hashicorp/packer/post-processor/amazon-import"
amazoninstancebuilder "github.com/hashicorp/packer/builder/amazon/instance"
ansiblelocalprovisioner "github.com/hashicorp/packer/provisioner/ansible-local"
ansibleprovisioner "github.com/hashicorp/packer/provisioner/ansible"
artificepostprocessor "github.com/hashicorp/packer/post-processor/artifice"
azurearmbuilder "github.com/hashicorp/packer/builder/azure/arm"
breakpointprovisioner "github.com/hashicorp/packer/provisioner/breakpoint"
checksumpostprocessor "github.com/hashicorp/packer/post-processor/checksum"
chefclientprovisioner "github.com/hashicorp/packer/provisioner/chef-client"
chefsoloprovisioner "github.com/hashicorp/packer/provisioner/chef-solo"
cloudstackbuilder "github.com/hashicorp/packer/builder/cloudstack"
compresspostprocessor "github.com/hashicorp/packer/post-processor/compress"
convergeprovisioner "github.com/hashicorp/packer/provisioner/converge"
digitaloceanbuilder "github.com/hashicorp/packer/builder/digitalocean"
dockerbuilder "github.com/hashicorp/packer/builder/docker"
dockerimportpostprocessor "github.com/hashicorp/packer/post-processor/docker-import"
dockerpushpostprocessor "github.com/hashicorp/packer/post-processor/docker-push"
dockersavepostprocessor "github.com/hashicorp/packer/post-processor/docker-save"
dockertagpostprocessor "github.com/hashicorp/packer/post-processor/docker-tag"
filebuilder "github.com/hashicorp/packer/builder/file"
fileprovisioner "github.com/hashicorp/packer/provisioner/file"
googlecomputebuilder "github.com/hashicorp/packer/builder/googlecompute"
googlecomputeexportpostprocessor "github.com/hashicorp/packer/post-processor/googlecompute-export"
googlecomputeimportpostprocessor "github.com/hashicorp/packer/post-processor/googlecompute-import"
hcloudbuilder "github.com/hashicorp/packer/builder/hcloud"
hypervisobuilder "github.com/hashicorp/packer/builder/hyperv/iso"
hypervvmcxbuilder "github.com/hashicorp/packer/builder/hyperv/vmcx"
lxcbuilder "github.com/hashicorp/packer/builder/lxc"
lxdbuilder "github.com/hashicorp/packer/builder/lxd"
manifestpostprocessor "github.com/hashicorp/packer/post-processor/manifest"
ncloudbuilder "github.com/hashicorp/packer/builder/ncloud"
nullbuilder "github.com/hashicorp/packer/builder/null"
oneandonebuilder "github.com/hashicorp/packer/builder/oneandone"
@ -38,46 +57,28 @@ import (
oracleocibuilder "github.com/hashicorp/packer/builder/oracle/oci"
parallelsisobuilder "github.com/hashicorp/packer/builder/parallels/iso"
parallelspvmbuilder "github.com/hashicorp/packer/builder/parallels/pvm"
powershellprovisioner "github.com/hashicorp/packer/provisioner/powershell"
profitbricksbuilder "github.com/hashicorp/packer/builder/profitbricks"
puppetmasterlessprovisioner "github.com/hashicorp/packer/provisioner/puppet-masterless"
puppetserverprovisioner "github.com/hashicorp/packer/provisioner/puppet-server"
qemubuilder "github.com/hashicorp/packer/builder/qemu"
saltmasterlessprovisioner "github.com/hashicorp/packer/provisioner/salt-masterless"
scalewaybuilder "github.com/hashicorp/packer/builder/scaleway"
shelllocalpostprocessor "github.com/hashicorp/packer/post-processor/shell-local"
shelllocalprovisioner "github.com/hashicorp/packer/provisioner/shell-local"
shellprovisioner "github.com/hashicorp/packer/provisioner/shell"
tritonbuilder "github.com/hashicorp/packer/builder/triton"
vagrantcloudpostprocessor "github.com/hashicorp/packer/post-processor/vagrant-cloud"
vagrantpostprocessor "github.com/hashicorp/packer/post-processor/vagrant"
virtualboxisobuilder "github.com/hashicorp/packer/builder/virtualbox/iso"
virtualboxovfbuilder "github.com/hashicorp/packer/builder/virtualbox/ovf"
vmwareisobuilder "github.com/hashicorp/packer/builder/vmware/iso"
vmwarevmxbuilder "github.com/hashicorp/packer/builder/vmware/vmx"
alicloudimportpostprocessor "github.com/hashicorp/packer/post-processor/alicloud-import"
amazonimportpostprocessor "github.com/hashicorp/packer/post-processor/amazon-import"
artificepostprocessor "github.com/hashicorp/packer/post-processor/artifice"
checksumpostprocessor "github.com/hashicorp/packer/post-processor/checksum"
compresspostprocessor "github.com/hashicorp/packer/post-processor/compress"
dockerimportpostprocessor "github.com/hashicorp/packer/post-processor/docker-import"
dockerpushpostprocessor "github.com/hashicorp/packer/post-processor/docker-push"
dockersavepostprocessor "github.com/hashicorp/packer/post-processor/docker-save"
dockertagpostprocessor "github.com/hashicorp/packer/post-processor/docker-tag"
googlecomputeexportpostprocessor "github.com/hashicorp/packer/post-processor/googlecompute-export"
googlecomputeimportpostprocessor "github.com/hashicorp/packer/post-processor/googlecompute-import"
manifestpostprocessor "github.com/hashicorp/packer/post-processor/manifest"
shelllocalpostprocessor "github.com/hashicorp/packer/post-processor/shell-local"
vagrantpostprocessor "github.com/hashicorp/packer/post-processor/vagrant"
vagrantcloudpostprocessor "github.com/hashicorp/packer/post-processor/vagrant-cloud"
vspherepostprocessor "github.com/hashicorp/packer/post-processor/vsphere"
vspheretemplatepostprocessor "github.com/hashicorp/packer/post-processor/vsphere-template"
ansibleprovisioner "github.com/hashicorp/packer/provisioner/ansible"
ansiblelocalprovisioner "github.com/hashicorp/packer/provisioner/ansible-local"
breakpointprovisioner "github.com/hashicorp/packer/provisioner/breakpoint"
chefclientprovisioner "github.com/hashicorp/packer/provisioner/chef-client"
chefsoloprovisioner "github.com/hashicorp/packer/provisioner/chef-solo"
convergeprovisioner "github.com/hashicorp/packer/provisioner/converge"
fileprovisioner "github.com/hashicorp/packer/provisioner/file"
powershellprovisioner "github.com/hashicorp/packer/provisioner/powershell"
puppetmasterlessprovisioner "github.com/hashicorp/packer/provisioner/puppet-masterless"
puppetserverprovisioner "github.com/hashicorp/packer/provisioner/puppet-server"
saltmasterlessprovisioner "github.com/hashicorp/packer/provisioner/salt-masterless"
shellprovisioner "github.com/hashicorp/packer/provisioner/shell"
shelllocalprovisioner "github.com/hashicorp/packer/provisioner/shell-local"
windowsrestartprovisioner "github.com/hashicorp/packer/provisioner/windows-restart"
windowsshellprovisioner "github.com/hashicorp/packer/provisioner/windows-shell"
)
type PluginCommand struct {
@ -120,6 +121,7 @@ var Builders = map[string]packer.Builder{
"vmware-vmx": new(vmwarevmxbuilder.Builder),
}
var Provisioners = map[string]packer.Provisioner{
"ansible": new(ansibleprovisioner.Provisioner),
"ansible-local": new(ansiblelocalprovisioner.Provisioner),
@ -138,6 +140,7 @@ var Provisioners = map[string]packer.Provisioner{
"windows-shell": new(windowsshellprovisioner.Provisioner),
}
var PostProcessors = map[string]packer.PostProcessor{
"alicloud-import": new(alicloudimportpostprocessor.PostProcessor),
"amazon-import": new(amazonimportpostprocessor.PostProcessor),
@ -158,6 +161,7 @@ var PostProcessors = map[string]packer.PostProcessor{
"vsphere-template": new(vspheretemplatepostprocessor.PostProcessor),
}
var pluginRegexp = regexp.MustCompile("packer-(builder|post-processor|provisioner)-(.+)")
func (c *PluginCommand) Run(args []string) int {

View File

@ -1190,7 +1190,6 @@ func newParser(filename string, b []byte, opts ...Option) *parser {
Stats: &stats,
// start rule is rule [0] unless an alternate entrypoint is specified
entrypoint: g.rules[0].name,
emptyState: make(storeDict),
}
p.setOptions(opts)
@ -1279,9 +1278,6 @@ type parser struct {
choiceNoMatch string
// recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse
recoveryStack []map[string]interface{}
// emptyState contains an empty storeDict, which is used to optimize cloneState if global "state" store is not used.
emptyState storeDict
}
// push a variable set on the vstack.
@ -1455,13 +1451,6 @@ func (p *parser) cloneState() storeDict {
defer p.out(p.in("cloneState"))
}
if len(p.cur.state) == 0 {
if len(p.emptyState) > 0 {
p.emptyState = make(storeDict)
}
return p.emptyState
}
state := make(storeDict, len(p.cur.state))
for k, v := range p.cur.state {
if c, ok := v.(Cloner); ok {

View File

@ -25,11 +25,20 @@ registry.
The configuration for this post-processor only requires a `repository`, a `tag`
is optional.
### Required:
- `repository` (string) - The repository of the imported image.
- `tag` (string) - The tag for the imported image. By default this is not
set.
### Optional:
- `changes` (array of strings) - Dockerfile instructions to add to the
commit. Example of instructions are `CMD`, `ENTRYPOINT`, `ENV`, and
`EXPOSE`. Example: `[ "USER ubuntu", "WORKDIR /app", "EXPOSE 8080" ]`
## Example
An example is shown below, showing only the post-processor configuration:
@ -48,3 +57,68 @@ into the local Docker process with a name of `hashicorp/packer:0.7`.
Following this, you can use the
[docker-push](/docs/post-processors/docker-push.html) post-processor to push it
to a registry, if you want.
## Changing Metadata
Below is an example using the changes argument of the post-processor. This
feature allows the tarball metadata to be changed when imported into the
Docker environment. It is derived from the `docker import --change` command
line [option to
Docker](https://docs.docker.com/engine/reference/commandline/import/).
Example uses of all of the options, assuming one is building an NGINX image
from ubuntu as an simple example:
``` json
{
"type": "docker-import",
"repository": "local/centos6",
"tag": "latest",
"changes": [
"USER www-data",
"WORKDIR /var/www",
"ENV HOSTNAME www.example.com",
"VOLUME /test1 /test2",
"EXPOSE 80 443",
"LABEL version=1.0",
"ONBUILD RUN date",
"CMD [\"nginx\", \"-g\", \"daemon off;\"]",
"ENTRYPOINT /var/www/start.sh"
]
}
```
Allowed metadata fields that can be changed are:
- CMD
- String, supports both array (escaped) and string form
- EX: `"CMD [\"nginx\", \"-g\", \"daemon off;\"]"`
- EX: `"CMD nginx -g daemon off;"`
- ENTRYPOINT
- String
- EX: `"ENTRYPOINT /var/www/start.sh"`
- ENV
- String, note there is no equal sign:
- EX: `"ENV HOSTNAME www.example.com"` not
`"ENV HOSTNAME=www.example.com"`
- EXPOSE
- String, space separated ports
- EX: `"EXPOSE 80 443"`
- LABEL
- String, space separated key=value pairs
- EX: `"LABEL version=1.0"`
- ONBUILD
- String
- EX: `"ONBUILD RUN date"`
- MAINTAINER
- String, deprecated in Docker version 1.13.0
- EX: `"MAINTAINER NAME"`
- USER
- String
- EX: `"USER USERNAME"`
- VOLUME
- String
- EX: `"VOLUME FROM TO"`
- WORKDIR
- String
- EX: `"WORKDIR PATH"`