Skip to content
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

Publishing docker images within a build like other artifacts #171

Open
vierbergenlars opened this issue Oct 21, 2020 · 0 comments
Open

Publishing docker images within a build like other artifacts #171

vierbergenlars opened this issue Oct 21, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@vierbergenlars
Copy link
Member

For normal gradle artifacts, consuming them from another subproject of the build works with cross-project publications: https://docs.gradle.org/current/userguide/cross_project_publications.html#sec:simple-sharing-artifacts-between-projects

How it is now

Currently, docker images can not be consumed this way, which prevents some nice things from working:

  • having some isolation between different projects
  • not needing to explicitly describe the dependency on a task from an other project
// projectA/build.gradle

plugins {
   id "eu.xenit.docker"
}
// projectB/build.gradle

plugins {
  id "eu.xenit.docker"
}

evaluationDependsOn(":projectA")

createDockerFile {
  dependsOn(":projectA:buildDockerImage")
  from(project(":projectA").tasks.named("buildDockerImage").flatMap({ it.imageId }))
}

How Gradle does it for other artifacts

In its simplest form, an output (file/directory) that is created by a task in project A is attached to a configuration in project A.
To use it from project B, a configuration is created and a dependency is added on project(path: ":projectA", configuration: "XX"), which is then consumed by the task from project B that needs the artifact.

// projectA/build.gradle
plugins {
  id "java"
}
// projectB/build.gradle
configurations {
  YY
}

dependencies {
  YY project(path: ":projectA", configuration: "archives")
}

How it could be

// projectA/build.gradle

plugins {
   id "eu.xenit.docker"
}
// projectB/build.gradle

plugins {
   id "eu.xenit.docker"
}

configurations {
   YY
}

dependencies {
   YY project(path: ":projectA", configuration: "dockerImage")
}

createDockerFile {
   from(YY)
}

Necessary changes

Automatically create an outgoing configuration named dockerImage. This configuration should have a single artifact that represents the image ID of the image built by buildDockerImage. Since configurations can only contain files, it shall be a textfile containing the image ID. The artifact should also be builtBy(buildDockerImage), so it is automatically built when the configuration is consumed an used.

On the consuming side, a Dockerfile convention should add a method: from(Configuration), which will add a dependency on the configuration, and internally wire to from(Provider<String>). In the provider, we will assert that there is only a single file present in the configuration (with Configuration#getSingleFile()), and then read the image ID from that file.

@vierbergenlars vierbergenlars added the enhancement New feature or request label Oct 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant