-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RUN command that is inserted before the COPY commands #1093
Comments
Currently I solved this by hacking around tasks.named("dockerCreateDockerfile") {
val task = (this as Dockerfile)
// RUN needs to be inserted before COPY to reduce Docker build invalidations.
// See https://github.com/bmuschko/gradle-docker-plugin/issues/1093
val instructions = task.instructions.get().toMutableList()
instructions.add(
2,
RunCommandInstruction(
"""
apt-get update && \
apt-get install -y somepackage && \
apt-get clean
""".trimIndent()
)
)
task.instructions.value(instructions)
} Not a fan of this solution, I think plugin should provide some sort of I'd argue that many users use What do you think? :) |
The solution you came up with has also been described in the user guide. I'd agree that achieving the goal could be easier. Right now, it requires knowledge about the generated Dockerfile. There are a couple of things, we could do to make it easier:
RE 3: I'd have to think about it a bit to come up with a solution that is a) flexible enough, b) end user-friendly that makes it apparent when the code provided is executed. Let me know if you have some thoughts as well. The last option is that you could simply write your own convention plugin with the functionality you need. |
FWIW, here's my version of the same thing (kts syntax): tasks.withType<Dockerfile> {
// Your custom runCommand instructions
runCommand("...")
// Move the COPY instructions to the end
// See https://github.com/bmuschko/gradle-docker-plugin/issues/1093
instructions.set(
instructions.get().sortedBy { instruction ->
if (instruction.keyword == CopyFileInstruction.KEYWORD) 1 else 0
}
)
}
|
Expected Behavior
Plugin should allow inserting
RUN
instructions into theDockerfile
before it insertsCOPY libs, resources, classes
instructions to allow user executing commands likeapt-get install
that are not invalidated after each Gradle project change.Current Behavior
Currently, if one uses
runCommand
with something costly likeapt-get install
, theseRUN
commands will be executed each time the Docker image is rebuilt due to code change.Context
In our case this results in Docker image build being slow and potentially flaky (network-related) because
RUN apt-get install
instructions are always executed if project source code is changed.Steps to Reproduce (for bugs)
Using configuration like this and then changing some source code in the project and running
./gradlew dockerBuildImage
results inRUN apt-get
instructions being always executed because they're added to the end of generated Dockerfile after theCOPY
commands with code content.Your Environment
Gradle Docker Plugin version
8.0.0
The text was updated successfully, but these errors were encountered: