GithubHelp home page GithubHelp logo

nukemberg / packer-post-processor-docker-dockerfile Goto Github PK

View Code? Open in Web Editor NEW
29.0 3.0 12.0 27 KB

A packer.io post processor plugin that sets dockerfile metadata on docker images

License: Apache License 2.0

Go 100.00%

packer-post-processor-docker-dockerfile's Introduction

Packer Docker build post processor

Build Status

This is a packer post processor plugin which allows setting Docker metadata on Docker artifact.

Normally, Docker iamges built using packer cannot include user, environment variables and other metadata that is available using Dockerfiles.

This plugin will automatically create a temporary Dockerfile and run docker build in an annonymous context. Most Dockerfile instructions are supported as json parameters, note that ADD, RUN, COPY etc. are not supported because packer provisioners should be used for this functionality.

Usage

In your packer template, configure the post processor:

{
  "post-processors": [
    {
      "type": "docker-dockerfile",
      "env": { "envname": "envvalue" },
      "user": "userid",
      "volume": ["/data"],
      "entrypoint": ["/bin/bash", "-v"],
      "expose": [8080, 8081]
    }
  ]
}

Values can include user variables and other packer functions as documented on the packer manual.

cmd and entrypoint can have either array or string values, this mirrors Dockerfile format and functionality; See the docker build reference for details.

Please note that if you are using the docker-tag post processor to tag the resulting artifact of this post processor then you must put both post processor on the same chain:

{
...
  "post-processors": [
    [
      {
        "type": "docker-dockerfile",
        "env": {
          "SOMEENVVAR": "value"
        },
        "user": "userid",
        "volume": ["/data", "/logs"]
      },
      {
        "type": "docker-tag",
        "repository": "packer/whatever",
        "tag": "latest"
      }
    ]
  ]
...
}

Building

It's recommended to build this plugin using goop. Install goop:

go get github.com/nitrous-io/goop && go build github.com/nitrous-io/goop

Then build the packer plugin. From within the plugin source code directory use the commands:

goop install && goop go build

Copy the binary packer-post-processor-docker-dockerfile to your packer directory.

License

This plugin is released under the Apache V2 license

Support

Please file an issue on the github repository if you think anything isn't working properly or an improvement is required.

This plugin has been tested with packer 0.7.2 and 0.8 development branch.

packer-post-processor-docker-dockerfile's People

Contributors

nukemberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

packer-post-processor-docker-dockerfile's Issues

build fails due to broken deeper level dependency

Hi,
it seems to me that the post processor does not build currently due to some broken dependencies in dependencies:

it's the goop install command that fails, seemingly(I'm not a go expert) at this place:

$ goop install
...
package google.golang.org/grpc
imports golang.org/x/net/http2
imports golang.org/x/net/http2/hpack
imports google.golang.org/grpc/credentials
imports google.golang.org/api/bigquery/v2
imports google.golang.org/api/container/v1beta1
imports google.golang.org/api/container/v1beta1
imports google.golang.org/api/container/v1beta1: cannot find package "google.golang.org/api/container/v1beta1" in any of:
/usr/lib/go/src/pkg/google.golang.org/api/container/v1beta1 (from $GOROOT)
/home/henning/packer-post-processor-docker-dockerfile/.vendor/tmp/src/google.golang.org/api/container/v1beta1 (from $GOPATH)
....
goop: Command failed with exit status 1

install.txt

Thoughts on merging this into the packer code base?

I was wondering if you are planning on merging this into the packer code base, there is currently an enhancement tagged for this exact functionality. It would be really great to have this integrated. Any thoughts on this?

It doesn't compiled

Hi guys,

please update your code. Thanks.

searching for changes
no changes found
=> Fetching dependencies for github.com/onsi/ginkgo/ginkgo...
=> Fetching dependencies for github.com/onsi/gomega...
=> Fetching dependencies for code.google.com/p/go.tools/go/vcs...
code.google.com/p/go.net (download)
warning: code.google.com is shutting down; import path code.google.com/p/go.net/html will stop working
Fetching https://golang.org/x/net/html/atom?go-get=1
Parsing meta tags from https://golang.org/x/net/html/atom?go-get=1 (status code 200)
get "golang.org/x/net/html/atom": found meta tag main.metaImport{Prefix:"golang.org/x/net", VCS:"git", RepoRoot:"https://go.googlesource.com/net"} at https://golang.org/x/net/html/atom?go-get=1
get "golang.org/x/net/html/atom": verifying non-authoritative meta tag
Fetching https://golang.org/x/net?go-get=1
Parsing meta tags from https://golang.org/x/net?go-get=1 (status code 200)
golang.org/x/net (download)
warning: code.google.com is shutting down; import path code.google.com/p/go.net/html/atom will stop working
can't load package: the code.google.com/p/go.tools/cmd/cover command has moved; use golang.org/x/tools/cmd/cover instead.
can't load package: the code.google.com/p/go.tools/cmd/godoc command has moved; use golang.org/x/tools/cmd/godoc instead.
can't load package: the code.google.com/p/go.tools/cmd/vet command has moved; use golang.org/x/tools/cmd/vet instead.
goop: Command failed with exit status 1

Compilation error when building

ubuntu@test-instance:~/packer-post-processor-docker-dockerfile$ sudo goop go build
# _/home/ubuntu/packer-post-processor-docker-dockerfile
./main.go:37: undefined: packer.ConfigTemplate

I am getting the following error when trying to build

Does this plugin still work?

I have attempted to use this module but am getting this error:

==> docker: Running post-processor: docker-dockerfile
Build 'docker' errored: 1 error(s) occurred:

* Post-processor failed: Unknown artifact type: packer.docker
Can only tag from Docker builder artifacts.


▽
==> Some builds didn't complete successfully and had errors:
--> docker: 1 error(s) occurred:

* Post-processor failed: Unknown artifact type: packer.docker
Can only tag from Docker builder artifacts.

==> Builds finished but no artifacts were created.

My build looks like this:

{
    "builders":[{
        "type": "docker",
        "image": "frodopwns/macrobase",
        "export_path": "image.tar",
        "volumes": {
            "/etc/ansible": "/etc/ansible",
            "/etc/ansible": "/etc/ansible",
            "/root/.ssh": "/root/.ssh"
        },
        "run_command": ["-d", "-i", "-t", "{{.Image}}", "/bin/bash"]
    }],
    "provisioners":[
        {
            "type": "ansible-local",
            "playbook_file": "provisioning/local.yml",
            "role_paths": [
                "provisioning/roles/manage_site"
            ],
            "host_vars": "provisioning/host_vars",
            "extra_arguments": ["--extra-vars 'test_var=muahahahah'", "-vvvv"]
        }
    ],
    "post-processors": [
      {
        "type": "docker-dockerfile",
        "entrypoint": ["/bin/bash", "/start.sh"],
        "expose": [80]
      }
  ]
}

Packer version: 0.8.6

I followed your instructions which were pretty clear until the part about putting the binary file in the "packer" directory. My packer files are all in /usr/local/bin at the moment so I put it in there...Is this wrong?

Thanks!

Cannot build the plugin

Hi,
When running the following I get:

go install github.com/nitrous-io/goop: build output "goop" already exists and is a directory

I followed the instructions in the documentation.

Goop install is exiting with status 1

I am attempting to build this project on my local machine and am getting the following error:

=> Fetching dependencies for code.google.com/p/gosshold...
=> Fetching dependencies for github.com/ActiveState/tail...
=> Fetching dependencies for github.com/going/toolkit...
package code.google.com/p/goprotobuf/proto: unable to detect version control system for code.google.com/ path
github.com/xiocode/toolkit (download)
goop: Command failed with exit status 1

Is there any way around this? Is this even a problem? I ran goop go build afterwards and a binary did build without any errors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.