From 050f809a1cedb6bf7decb9ba739973be09866466 Mon Sep 17 00:00:00 2001 From: Ladar Levison Date: Mon, 17 Dec 2018 22:04:43 -0600 Subject: [PATCH 1/7] Add changes var to docker driver import func. --- builder/docker/driver_docker.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/builder/docker/driver_docker.go b/builder/docker/driver_docker.go index 50a2b9920..c052131f8 100644 --- a/builder/docker/driver_docker.go +++ b/builder/docker/driver_docker.go @@ -97,16 +97,26 @@ func (d *DockerDriver) Export(id string, dst io.Writer) error { return nil } -func (d *DockerDriver) Import(path string, repo string) (string, error) { +func (d *DockerDriver) Import(path string, changes []string, repo string) (string, error) { var stdout, stderr bytes.Buffer - cmd := exec.Command("docker", "import", "-", repo) cmd.Stdout = &stdout cmd.Stderr = &stderr stdin, err := cmd.StdinPipe() - if err != nil { + + if err != nil { return "", err } + args := []string{"import"} + + for _, change := range changes { + args = append(args, "--change", change) + } + + args = append(args, "-") + args = append(args, repo) + cmd := exec.Command("docker", args...) + // There should be only one artifact of the Docker builder file, err := os.Open(path) if err != nil { @@ -114,6 +124,8 @@ func (d *DockerDriver) Import(path string, repo string) (string, error) { } defer file.Close() + log.Printf("Importing container with args: %v", args) + if err := cmd.Start(); err != nil { return "", err } From 21fdbadf043769d1ffa421db04dd3b2a2d7eb3e6 Mon Sep 17 00:00:00 2001 From: Ladar Levison Date: Mon, 17 Dec 2018 22:13:40 -0600 Subject: [PATCH 2/7] Adding changes to import prototype. --- builder/docker/driver.go | 2 +- builder/docker/driver_mock.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/builder/docker/driver.go b/builder/docker/driver.go index 09da054f3..7359a667d 100644 --- a/builder/docker/driver.go +++ b/builder/docker/driver.go @@ -20,7 +20,7 @@ type Driver interface { Export(id string, dst io.Writer) error // Import imports a container from a tar file - Import(path, repo string) (string, error) + Import(path string, changes []string, repo string) (string, error) // IPAddress returns the address of the container that can be used // for external access. diff --git a/builder/docker/driver_mock.go b/builder/docker/driver_mock.go index 5193f21ee..4cca3325b 100644 --- a/builder/docker/driver_mock.go +++ b/builder/docker/driver_mock.go @@ -101,7 +101,7 @@ func (d *MockDriver) Export(id string, dst io.Writer) error { return d.ExportError } -func (d *MockDriver) Import(path, repo string) (string, error) { +func (d *MockDriver) Import(path string, changes []string, repo string) (string, error) { d.ImportCalled = true d.ImportPath = path d.ImportRepo = repo From 10095678c8b82b6fe172ee1f3e2a6c6b0ebf0d58 Mon Sep 17 00:00:00 2001 From: Ladar Levison Date: Mon, 17 Dec 2018 22:37:32 -0600 Subject: [PATCH 3/7] Adding driver changes. --- builder/docker/driver_docker.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/builder/docker/driver_docker.go b/builder/docker/driver_docker.go index c052131f8..59fb8f9c3 100644 --- a/builder/docker/driver_docker.go +++ b/builder/docker/driver_docker.go @@ -103,19 +103,19 @@ func (d *DockerDriver) Import(path string, changes []string, repo string) (strin cmd.Stderr = &stderr stdin, err := cmd.StdinPipe() - if err != nil { + if err != nil { return "", err } args := []string{"import"} - for _, change := range changes { - args = append(args, "--change", change) - } + for _, change := range changes { + args = append(args, "--change", change) + } - args = append(args, "-") + args = append(args, "-") args = append(args, repo) - cmd := exec.Command("docker", args...) + cmd := exec.Command("docker", args...) // There should be only one artifact of the Docker builder file, err := os.Open(path) @@ -124,8 +124,8 @@ func (d *DockerDriver) Import(path string, changes []string, repo string) (strin } defer file.Close() - log.Printf("Importing container with args: %v", args) - + log.Printf("Importing container with args: %v", args) + if err := cmd.Start(); err != nil { return "", err } From 6ac597128828ecde1e59cd66980378649bbfb799 Mon Sep 17 00:00:00 2001 From: Ladar Levison Date: Mon, 17 Dec 2018 22:59:41 -0600 Subject: [PATCH 4/7] Fixed cmd order for docker driver. Added config to post proc. --- builder/docker/driver_docker.go | 17 +++++++++-------- post-processor/docker-import/post-processor.go | 3 ++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/builder/docker/driver_docker.go b/builder/docker/driver_docker.go index 59fb8f9c3..918dfdb2c 100644 --- a/builder/docker/driver_docker.go +++ b/builder/docker/driver_docker.go @@ -99,13 +99,6 @@ func (d *DockerDriver) Export(id string, dst io.Writer) error { func (d *DockerDriver) Import(path string, changes []string, repo string) (string, error) { var stdout, stderr bytes.Buffer - cmd.Stdout = &stdout - cmd.Stderr = &stderr - stdin, err := cmd.StdinPipe() - - if err != nil { - return "", err - } args := []string{"import"} @@ -115,7 +108,15 @@ func (d *DockerDriver) Import(path string, changes []string, repo string) (strin args = append(args, "-") args = append(args, repo) + cmd := exec.Command("docker", args...) + cmd.Stdout = &stdout + cmd.Stderr = &stderr + stdin, err := cmd.StdinPipe() + + if err != nil { + return "", err + } // There should be only one artifact of the Docker builder file, err := os.Open(path) @@ -124,7 +125,7 @@ func (d *DockerDriver) Import(path string, changes []string, repo string) (strin } defer file.Close() - log.Printf("Importing container with args: %v", args) + log.Printf("Importing tarball with args: %v", args) if err := cmd.Start(); err != nil { return "", err diff --git a/post-processor/docker-import/post-processor.go b/post-processor/docker-import/post-processor.go index 80b99c8b3..c3488b22a 100644 --- a/post-processor/docker-import/post-processor.go +++ b/post-processor/docker-import/post-processor.go @@ -18,6 +18,7 @@ type Config struct { Repository string `mapstructure:"repository"` Tag string `mapstructure:"tag"` + Changes []string ctx interpolate.Context } @@ -62,7 +63,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac ui.Message("Importing image: " + artifact.Id()) ui.Message("Repository: " + importRepo) - id, err := driver.Import(artifact.Files()[0], importRepo) + id, err := driver.Import(artifact.Files()[0], p.config.Changes, importRepo) if err != nil { return nil, false, err } From 3cc83167c8c077b2e3e64ec21ca42af214314139 Mon Sep 17 00:00:00 2001 From: Ladar Levison Date: Tue, 18 Dec 2018 00:48:58 -0600 Subject: [PATCH 5/7] Added map structure type to config changes. --- post-processor/docker-import/post-processor.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/post-processor/docker-import/post-processor.go b/post-processor/docker-import/post-processor.go index c3488b22a..eac920f06 100644 --- a/post-processor/docker-import/post-processor.go +++ b/post-processor/docker-import/post-processor.go @@ -16,9 +16,9 @@ const BuilderId = "packer.post-processor.docker-import" type Config struct { common.PackerConfig `mapstructure:",squash"` - Repository string `mapstructure:"repository"` - Tag string `mapstructure:"tag"` - Changes []string + Repository string `mapstructure:"repository"` + Tag string `mapstructure:"tag"` + Changes []string `mapstructure:"changes"` ctx interpolate.Context } From 6d10badc70579f5defa94559291dc06cc7c82eb8 Mon Sep 17 00:00:00 2001 From: Ladar Levison Date: Tue, 18 Dec 2018 02:00:21 -0600 Subject: [PATCH 6/7] Adding documentation for import changes. --- command/plugin.go | 186 +++++++++--------- common/bootcommand/boot_command.go | 11 -- .../post-processors/docker-import.html.md | 74 +++++++ 3 files changed, 169 insertions(+), 102 deletions(-) diff --git a/command/plugin.go b/command/plugin.go index d0cd68153..1a87c35f3 100644 --- a/command/plugin.go +++ b/command/plugin.go @@ -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 { @@ -85,79 +86,82 @@ type PluginCommand struct { } var Builders = map[string]packer.Builder{ - "alicloud-ecs": new(alicloudecsbuilder.Builder), - "amazon-chroot": new(amazonchrootbuilder.Builder), - "amazon-ebs": new(amazonebsbuilder.Builder), - "amazon-ebssurrogate": new(amazonebssurrogatebuilder.Builder), - "amazon-ebsvolume": new(amazonebsvolumebuilder.Builder), - "amazon-instance": new(amazoninstancebuilder.Builder), - "azure-arm": new(azurearmbuilder.Builder), - "cloudstack": new(cloudstackbuilder.Builder), - "digitalocean": new(digitaloceanbuilder.Builder), - "docker": new(dockerbuilder.Builder), - "file": new(filebuilder.Builder), - "googlecompute": new(googlecomputebuilder.Builder), - "hcloud": new(hcloudbuilder.Builder), - "hyperv-iso": new(hypervisobuilder.Builder), - "hyperv-vmcx": new(hypervvmcxbuilder.Builder), - "lxc": new(lxcbuilder.Builder), - "lxd": new(lxdbuilder.Builder), - "ncloud": new(ncloudbuilder.Builder), - "null": new(nullbuilder.Builder), - "oneandone": new(oneandonebuilder.Builder), - "openstack": new(openstackbuilder.Builder), - "oracle-classic": new(oracleclassicbuilder.Builder), - "oracle-oci": new(oracleocibuilder.Builder), - "parallels-iso": new(parallelsisobuilder.Builder), - "parallels-pvm": new(parallelspvmbuilder.Builder), - "profitbricks": new(profitbricksbuilder.Builder), - "qemu": new(qemubuilder.Builder), - "scaleway": new(scalewaybuilder.Builder), - "triton": new(tritonbuilder.Builder), - "virtualbox-iso": new(virtualboxisobuilder.Builder), - "virtualbox-ovf": new(virtualboxovfbuilder.Builder), - "vmware-iso": new(vmwareisobuilder.Builder), - "vmware-vmx": new(vmwarevmxbuilder.Builder), + "alicloud-ecs": new(alicloudecsbuilder.Builder), + "amazon-chroot": new(amazonchrootbuilder.Builder), + "amazon-ebs": new(amazonebsbuilder.Builder), + "amazon-ebssurrogate": new(amazonebssurrogatebuilder.Builder), + "amazon-ebsvolume": new(amazonebsvolumebuilder.Builder), + "amazon-instance": new(amazoninstancebuilder.Builder), + "azure-arm": new(azurearmbuilder.Builder), + "cloudstack": new(cloudstackbuilder.Builder), + "digitalocean": new(digitaloceanbuilder.Builder), + "docker": new(dockerbuilder.Builder), + "file": new(filebuilder.Builder), + "googlecompute": new(googlecomputebuilder.Builder), + "hcloud": new(hcloudbuilder.Builder), + "hyperv-iso": new(hypervisobuilder.Builder), + "hyperv-vmcx": new(hypervvmcxbuilder.Builder), + "lxc": new(lxcbuilder.Builder), + "lxd": new(lxdbuilder.Builder), + "ncloud": new(ncloudbuilder.Builder), + "null": new(nullbuilder.Builder), + "oneandone": new(oneandonebuilder.Builder), + "openstack": new(openstackbuilder.Builder), + "oracle-classic": new(oracleclassicbuilder.Builder), + "oracle-oci": new(oracleocibuilder.Builder), + "parallels-iso": new(parallelsisobuilder.Builder), + "parallels-pvm": new(parallelspvmbuilder.Builder), + "profitbricks": new(profitbricksbuilder.Builder), + "qemu": new(qemubuilder.Builder), + "scaleway": new(scalewaybuilder.Builder), + "triton": new(tritonbuilder.Builder), + "virtualbox-iso": new(virtualboxisobuilder.Builder), + "virtualbox-ovf": new(virtualboxovfbuilder.Builder), + "vmware-iso": new(vmwareisobuilder.Builder), + "vmware-vmx": new(vmwarevmxbuilder.Builder), } + var Provisioners = map[string]packer.Provisioner{ - "ansible": new(ansibleprovisioner.Provisioner), - "ansible-local": new(ansiblelocalprovisioner.Provisioner), - "breakpoint": new(breakpointprovisioner.Provisioner), - "chef-client": new(chefclientprovisioner.Provisioner), - "chef-solo": new(chefsoloprovisioner.Provisioner), - "converge": new(convergeprovisioner.Provisioner), - "file": new(fileprovisioner.Provisioner), - "powershell": new(powershellprovisioner.Provisioner), - "puppet-masterless": new(puppetmasterlessprovisioner.Provisioner), - "puppet-server": new(puppetserverprovisioner.Provisioner), + "ansible": new(ansibleprovisioner.Provisioner), + "ansible-local": new(ansiblelocalprovisioner.Provisioner), + "breakpoint": new(breakpointprovisioner.Provisioner), + "chef-client": new(chefclientprovisioner.Provisioner), + "chef-solo": new(chefsoloprovisioner.Provisioner), + "converge": new(convergeprovisioner.Provisioner), + "file": new(fileprovisioner.Provisioner), + "powershell": new(powershellprovisioner.Provisioner), + "puppet-masterless": new(puppetmasterlessprovisioner.Provisioner), + "puppet-server": new(puppetserverprovisioner.Provisioner), "salt-masterless": new(saltmasterlessprovisioner.Provisioner), - "shell": new(shellprovisioner.Provisioner), - "shell-local": new(shelllocalprovisioner.Provisioner), + "shell": new(shellprovisioner.Provisioner), + "shell-local": new(shelllocalprovisioner.Provisioner), "windows-restart": new(windowsrestartprovisioner.Provisioner), - "windows-shell": new(windowsshellprovisioner.Provisioner), + "windows-shell": new(windowsshellprovisioner.Provisioner), } + var PostProcessors = map[string]packer.PostProcessor{ - "alicloud-import": new(alicloudimportpostprocessor.PostProcessor), - "amazon-import": new(amazonimportpostprocessor.PostProcessor), - "artifice": new(artificepostprocessor.PostProcessor), - "checksum": new(checksumpostprocessor.PostProcessor), - "compress": new(compresspostprocessor.PostProcessor), - "docker-import": new(dockerimportpostprocessor.PostProcessor), - "docker-push": new(dockerpushpostprocessor.PostProcessor), - "docker-save": new(dockersavepostprocessor.PostProcessor), - "docker-tag": new(dockertagpostprocessor.PostProcessor), - "googlecompute-export": new(googlecomputeexportpostprocessor.PostProcessor), - "googlecompute-import": new(googlecomputeimportpostprocessor.PostProcessor), - "manifest": new(manifestpostprocessor.PostProcessor), - "shell-local": new(shelllocalpostprocessor.PostProcessor), - "vagrant": new(vagrantpostprocessor.PostProcessor), - "vagrant-cloud": new(vagrantcloudpostprocessor.PostProcessor), - "vsphere": new(vspherepostprocessor.PostProcessor), - "vsphere-template": new(vspheretemplatepostprocessor.PostProcessor), + "alicloud-import": new(alicloudimportpostprocessor.PostProcessor), + "amazon-import": new(amazonimportpostprocessor.PostProcessor), + "artifice": new(artificepostprocessor.PostProcessor), + "checksum": new(checksumpostprocessor.PostProcessor), + "compress": new(compresspostprocessor.PostProcessor), + "docker-import": new(dockerimportpostprocessor.PostProcessor), + "docker-push": new(dockerpushpostprocessor.PostProcessor), + "docker-save": new(dockersavepostprocessor.PostProcessor), + "docker-tag": new(dockertagpostprocessor.PostProcessor), + "googlecompute-export": new(googlecomputeexportpostprocessor.PostProcessor), + "googlecompute-import": new(googlecomputeimportpostprocessor.PostProcessor), + "manifest": new(manifestpostprocessor.PostProcessor), + "shell-local": new(shelllocalpostprocessor.PostProcessor), + "vagrant": new(vagrantpostprocessor.PostProcessor), + "vagrant-cloud": new(vagrantcloudpostprocessor.PostProcessor), + "vsphere": new(vspherepostprocessor.PostProcessor), + "vsphere-template": new(vspheretemplatepostprocessor.PostProcessor), } + var pluginRegexp = regexp.MustCompile("packer-(builder|post-processor|provisioner)-(.+)") func (c *PluginCommand) Run(args []string) int { diff --git a/common/bootcommand/boot_command.go b/common/bootcommand/boot_command.go index 95133f334..1447a4337 100644 --- a/common/bootcommand/boot_command.go +++ b/common/bootcommand/boot_command.go @@ -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 { diff --git a/website/source/docs/post-processors/docker-import.html.md b/website/source/docs/post-processors/docker-import.html.md index 00add79e6..1d3e413d7 100644 --- a/website/source/docs/post-processors/docker-import.html.md +++ b/website/source/docs/post-processors/docker-import.html.md @@ -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"` From 0f8f58371e9c26cc2d057a0e2907a0297ad8db2f Mon Sep 17 00:00:00 2001 From: Ladar Levison Date: Tue, 18 Dec 2018 02:13:43 -0600 Subject: [PATCH 7/7] Reverting accidental changes to boot command/plugin go files. --- command/plugin.go | 186 ++++++++++++++--------------- common/bootcommand/boot_command.go | 11 ++ 2 files changed, 102 insertions(+), 95 deletions(-) diff --git a/command/plugin.go b/command/plugin.go index 1a87c35f3..d0cd68153 100644 --- a/command/plugin.go +++ b/command/plugin.go @@ -14,41 +14,22 @@ 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" @@ -57,28 +38,46 @@ 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 { @@ -86,82 +85,79 @@ type PluginCommand struct { } var Builders = map[string]packer.Builder{ - "alicloud-ecs": new(alicloudecsbuilder.Builder), - "amazon-chroot": new(amazonchrootbuilder.Builder), - "amazon-ebs": new(amazonebsbuilder.Builder), - "amazon-ebssurrogate": new(amazonebssurrogatebuilder.Builder), - "amazon-ebsvolume": new(amazonebsvolumebuilder.Builder), - "amazon-instance": new(amazoninstancebuilder.Builder), - "azure-arm": new(azurearmbuilder.Builder), - "cloudstack": new(cloudstackbuilder.Builder), - "digitalocean": new(digitaloceanbuilder.Builder), - "docker": new(dockerbuilder.Builder), - "file": new(filebuilder.Builder), - "googlecompute": new(googlecomputebuilder.Builder), - "hcloud": new(hcloudbuilder.Builder), - "hyperv-iso": new(hypervisobuilder.Builder), - "hyperv-vmcx": new(hypervvmcxbuilder.Builder), - "lxc": new(lxcbuilder.Builder), - "lxd": new(lxdbuilder.Builder), - "ncloud": new(ncloudbuilder.Builder), - "null": new(nullbuilder.Builder), - "oneandone": new(oneandonebuilder.Builder), - "openstack": new(openstackbuilder.Builder), - "oracle-classic": new(oracleclassicbuilder.Builder), - "oracle-oci": new(oracleocibuilder.Builder), - "parallels-iso": new(parallelsisobuilder.Builder), - "parallels-pvm": new(parallelspvmbuilder.Builder), - "profitbricks": new(profitbricksbuilder.Builder), - "qemu": new(qemubuilder.Builder), - "scaleway": new(scalewaybuilder.Builder), - "triton": new(tritonbuilder.Builder), - "virtualbox-iso": new(virtualboxisobuilder.Builder), - "virtualbox-ovf": new(virtualboxovfbuilder.Builder), - "vmware-iso": new(vmwareisobuilder.Builder), - "vmware-vmx": new(vmwarevmxbuilder.Builder), + "alicloud-ecs": new(alicloudecsbuilder.Builder), + "amazon-chroot": new(amazonchrootbuilder.Builder), + "amazon-ebs": new(amazonebsbuilder.Builder), + "amazon-ebssurrogate": new(amazonebssurrogatebuilder.Builder), + "amazon-ebsvolume": new(amazonebsvolumebuilder.Builder), + "amazon-instance": new(amazoninstancebuilder.Builder), + "azure-arm": new(azurearmbuilder.Builder), + "cloudstack": new(cloudstackbuilder.Builder), + "digitalocean": new(digitaloceanbuilder.Builder), + "docker": new(dockerbuilder.Builder), + "file": new(filebuilder.Builder), + "googlecompute": new(googlecomputebuilder.Builder), + "hcloud": new(hcloudbuilder.Builder), + "hyperv-iso": new(hypervisobuilder.Builder), + "hyperv-vmcx": new(hypervvmcxbuilder.Builder), + "lxc": new(lxcbuilder.Builder), + "lxd": new(lxdbuilder.Builder), + "ncloud": new(ncloudbuilder.Builder), + "null": new(nullbuilder.Builder), + "oneandone": new(oneandonebuilder.Builder), + "openstack": new(openstackbuilder.Builder), + "oracle-classic": new(oracleclassicbuilder.Builder), + "oracle-oci": new(oracleocibuilder.Builder), + "parallels-iso": new(parallelsisobuilder.Builder), + "parallels-pvm": new(parallelspvmbuilder.Builder), + "profitbricks": new(profitbricksbuilder.Builder), + "qemu": new(qemubuilder.Builder), + "scaleway": new(scalewaybuilder.Builder), + "triton": new(tritonbuilder.Builder), + "virtualbox-iso": new(virtualboxisobuilder.Builder), + "virtualbox-ovf": new(virtualboxovfbuilder.Builder), + "vmware-iso": new(vmwareisobuilder.Builder), + "vmware-vmx": new(vmwarevmxbuilder.Builder), } - var Provisioners = map[string]packer.Provisioner{ - "ansible": new(ansibleprovisioner.Provisioner), - "ansible-local": new(ansiblelocalprovisioner.Provisioner), - "breakpoint": new(breakpointprovisioner.Provisioner), - "chef-client": new(chefclientprovisioner.Provisioner), - "chef-solo": new(chefsoloprovisioner.Provisioner), - "converge": new(convergeprovisioner.Provisioner), - "file": new(fileprovisioner.Provisioner), - "powershell": new(powershellprovisioner.Provisioner), - "puppet-masterless": new(puppetmasterlessprovisioner.Provisioner), - "puppet-server": new(puppetserverprovisioner.Provisioner), + "ansible": new(ansibleprovisioner.Provisioner), + "ansible-local": new(ansiblelocalprovisioner.Provisioner), + "breakpoint": new(breakpointprovisioner.Provisioner), + "chef-client": new(chefclientprovisioner.Provisioner), + "chef-solo": new(chefsoloprovisioner.Provisioner), + "converge": new(convergeprovisioner.Provisioner), + "file": new(fileprovisioner.Provisioner), + "powershell": new(powershellprovisioner.Provisioner), + "puppet-masterless": new(puppetmasterlessprovisioner.Provisioner), + "puppet-server": new(puppetserverprovisioner.Provisioner), "salt-masterless": new(saltmasterlessprovisioner.Provisioner), - "shell": new(shellprovisioner.Provisioner), - "shell-local": new(shelllocalprovisioner.Provisioner), + "shell": new(shellprovisioner.Provisioner), + "shell-local": new(shelllocalprovisioner.Provisioner), "windows-restart": new(windowsrestartprovisioner.Provisioner), - "windows-shell": new(windowsshellprovisioner.Provisioner), + "windows-shell": new(windowsshellprovisioner.Provisioner), } - var PostProcessors = map[string]packer.PostProcessor{ - "alicloud-import": new(alicloudimportpostprocessor.PostProcessor), - "amazon-import": new(amazonimportpostprocessor.PostProcessor), - "artifice": new(artificepostprocessor.PostProcessor), - "checksum": new(checksumpostprocessor.PostProcessor), - "compress": new(compresspostprocessor.PostProcessor), - "docker-import": new(dockerimportpostprocessor.PostProcessor), - "docker-push": new(dockerpushpostprocessor.PostProcessor), - "docker-save": new(dockersavepostprocessor.PostProcessor), - "docker-tag": new(dockertagpostprocessor.PostProcessor), - "googlecompute-export": new(googlecomputeexportpostprocessor.PostProcessor), - "googlecompute-import": new(googlecomputeimportpostprocessor.PostProcessor), - "manifest": new(manifestpostprocessor.PostProcessor), - "shell-local": new(shelllocalpostprocessor.PostProcessor), - "vagrant": new(vagrantpostprocessor.PostProcessor), - "vagrant-cloud": new(vagrantcloudpostprocessor.PostProcessor), - "vsphere": new(vspherepostprocessor.PostProcessor), - "vsphere-template": new(vspheretemplatepostprocessor.PostProcessor), + "alicloud-import": new(alicloudimportpostprocessor.PostProcessor), + "amazon-import": new(amazonimportpostprocessor.PostProcessor), + "artifice": new(artificepostprocessor.PostProcessor), + "checksum": new(checksumpostprocessor.PostProcessor), + "compress": new(compresspostprocessor.PostProcessor), + "docker-import": new(dockerimportpostprocessor.PostProcessor), + "docker-push": new(dockerpushpostprocessor.PostProcessor), + "docker-save": new(dockersavepostprocessor.PostProcessor), + "docker-tag": new(dockertagpostprocessor.PostProcessor), + "googlecompute-export": new(googlecomputeexportpostprocessor.PostProcessor), + "googlecompute-import": new(googlecomputeimportpostprocessor.PostProcessor), + "manifest": new(manifestpostprocessor.PostProcessor), + "shell-local": new(shelllocalpostprocessor.PostProcessor), + "vagrant": new(vagrantpostprocessor.PostProcessor), + "vagrant-cloud": new(vagrantcloudpostprocessor.PostProcessor), + "vsphere": new(vspherepostprocessor.PostProcessor), + "vsphere-template": new(vspheretemplatepostprocessor.PostProcessor), } - var pluginRegexp = regexp.MustCompile("packer-(builder|post-processor|provisioner)-(.+)") func (c *PluginCommand) Run(args []string) int { diff --git a/common/bootcommand/boot_command.go b/common/bootcommand/boot_command.go index 1447a4337..95133f334 100644 --- a/common/bootcommand/boot_command.go +++ b/common/bootcommand/boot_command.go @@ -1190,6 +1190,7 @@ 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) @@ -1278,6 +1279,9 @@ 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. @@ -1451,6 +1455,13 @@ 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 {