bmuschko / gradle-docker-plugin

Gradle plugin for managing Docker images and containers.
https://bmuschko.github.io/gradle-docker-plugin/current/user-guide/
Apache License 2.0
1.23k stars 361 forks source link

Support COPY --from (multi-stage builds) #465

Closed andybug closed 6 years ago

andybug commented 7 years ago

As of gradle-docker-plugin 3.0.11, it does not appear to support the COPY --from= syntax. The FROM as works as expected. A simple example is below.

task dockerAssemble(type: Dockerfile, dependsOn: dockerAssembleBuild) {
  description 'creates project Dockerfile'
  destFile = dockerBuildDir.resolve('Dockerfile').toFile()

  from "debian:latest as base_image"
  // do stuff
  from "alpine:latest"
  //copyFile "--from=base_image", "/etc/debian_version",  "/etc/debian_version"

This results in a Dockerfile that looks as expected:

FROM debian:latest as base_image
FROM alpine:latest

Uncommenting the copy line yields:

> Could not find method copyFile() for arguments [--from=base_image, /etc/debian_version, /etc/debian_version] on task ':nifi:dockerAssemble' of type com.bmuschko.gradle.docker.tasks.image.Dockerfile.

There doesn't appear to by a copyFile method that supports the from field in Dockerfile.

andybug commented 7 years ago

Note, I was able to get around this by using the generic instruction:

instruction "COPY --from=base_image /etc/debian_version /etc/debian_version"
orzeh commented 7 years ago

@andybug this seems to be an easy fix would you like to submit PR?

andybug commented 7 years ago

I'll take a look at it this weekend

cdancy commented 6 years ago

Closing issue. Feel free to re-open should you care to send in a PR.