func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) { if artifact.BuilderId() != dockertag.BuilderId { err := fmt.Errorf( "Unknown artifact type: %s\nCan only build with Dockerfile from Docker tag artifacts.", artifact.BuilderId()) return nil, false, err } p.config.From = artifact.Id() template_str := `FROM {{ .From }} {{ if .Maintainer }}MAINTAINER {{ .Maintainer }} {{ end }}{{ if .Cmd }}CMD {{ process .Cmd }} {{ end }}{{ if .Label }}{{ range $k, $v := .Label }}LABEL "{{ $k }}"="{{ $v }}" {{ end }}{{ end }}{{ if .Expose }}EXPOSE {{ join .Expose " " }} {{ end }}{{ if .Env }}{{ range $k, $v := .Env }}ENV {{ $k }} {{ $v }} {{ end }}{{ end }}{{ if .Entrypoint }}ENTRYPOINT {{ process .Entrypoint }} {{ end }}{{ if .Volume }}VOLUME {{ process .Volume }} {{ end }}{{ if .User }}USER {{ .User }} {{ end }}{{ if .WorkDir }}WORKDIR {{ .WorkDir }}{{ end }}` dockerfile := new(bytes.Buffer) template_writer := bufio.NewWriter(dockerfile) tmpl, err := template.New("Dockerfile").Funcs(template.FuncMap{ "process": p.processVar, "join": strings.Join, }).Parse(template_str) if err != nil { return nil, false, err } err = tmpl.Execute(template_writer, p.config) if err != nil { return nil, false, err } template_writer.Flush() log.Printf("Dockerfile:\n%s", dockerfile.String()) driver := p.Driver if driver == nil { // If no driver is set, then we use the real driver driver = &DockerDriver{&docker.DockerDriver{Ctx: &p.config.ctx, Ui: ui}} } ui.Message("Building image from Dockerfile") id, err := driver.BuildImage(dockerfile) if err != nil { return nil, false, err } ui.Message("Destroying previously tagged image: " + p.config.From) err = artifact.Destroy() if err != nil { return nil, false, err } ui.Message("Tagging new image, " + id + ", as " + p.config.From) err = driver.TagImage(id, p.config.From, true) if err != nil { return nil, false, err } // Build the artifact artifact = &docker.ImportArtifact{ BuilderIdValue: dockertag.BuilderId, Driver: driver, IdValue: p.config.From, } return artifact, true, nil }