|
1 | 1 | # Container Gradle Plugin
|
2 | 2 |
|
3 |
| -Container is a Gradle plugin that enhances build portability, reproducibility, and flexibility by integrating containers into Gradle tasks. It provides a declarative and familiar way to run task operations inside containers and declare containers as task inputs and outputs. |
| 3 | +Container is a Gradle plugin that enhances build portability, reproducibility, and flexibility by integrating containers |
| 4 | +into Gradle tasks. It provides a declarative and familiar way to run task operations inside containers and declare |
| 5 | +containers as task inputs and outputs. |
4 | 6 |
|
5 | 7 | ## Status
|
6 | 8 |
|
7 |
| -⚠️ **Experimental**: This project is currently in its early stages (version `0.x.x`). The API and features may change as we refine and improve the plugin. We're actively seeking feedback from early adopters to help shape its development. |
| 9 | +⚠️ **Experimental**: This project is currently in its early stages (version `0.x.x`). The API and features may change as |
| 10 | +we refine and improve the plugin. We're actively seeking feedback from early adopters to help shape its development. |
8 | 11 |
|
9 | 12 | ## Features
|
10 | 13 |
|
@@ -44,6 +47,60 @@ tasks {
|
44 | 47 | }
|
45 | 48 | ```
|
46 | 49 |
|
| 50 | +Create tasks that produce images: |
| 51 | + |
| 52 | +```kotlin |
| 53 | +import dev.codebandits.container.gradle.container |
| 54 | +import dev.codebandits.container.gradle.tasks.ContainerTask |
| 55 | + |
| 56 | +tasks { |
| 57 | + register<ContainerTask>("buildWithDocker") { |
| 58 | + inputs.file("Dockerfile") |
| 59 | + container.outputs.localImage("docker-build-image:latest") |
| 60 | + dockerPull { |
| 61 | + image = "docker:dind" |
| 62 | + } |
| 63 | + dockerRun { |
| 64 | + image = "docker:dind" |
| 65 | + entrypoint = "docker" |
| 66 | + args = arrayOf("build", "-t", "docker-build-image:latest", ".") |
| 67 | + workdir = "/workdir" |
| 68 | + volumes = arrayOf( |
| 69 | + "${layout.projectDirectory}:/workdir", |
| 70 | + "/var/run/docker.sock:/var/run/docker.sock:ro", |
| 71 | + ) |
| 72 | + } |
| 73 | + doLast { |
| 74 | + container.outputs.captureLocalImage("docker-build-image:latest") |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + register<ContainerTask>("buildImageWithPack") { |
| 79 | + inputs.file("index.html") |
| 80 | + inputs.file("project.toml") |
| 81 | + container.outputs.localImage("pack-build-image:latest") |
| 82 | + dockerPull { |
| 83 | + image = "buildpacksio/pack:latest" |
| 84 | + } |
| 85 | + dockerRun { |
| 86 | + image = "buildpacksio/pack:latest" |
| 87 | + args = arrayOf( |
| 88 | + "build", "pack-build-image:latest", |
| 89 | + "--builder", "paketobuildpacks/builder-jammy-base:latest", |
| 90 | + ) |
| 91 | + workdir = "/workdir" |
| 92 | + volumes = arrayOf( |
| 93 | + "${layout.projectDirectory}:/workdir", |
| 94 | + "/var/run/docker.sock:/var/run/docker.sock:ro", |
| 95 | + ) |
| 96 | + } |
| 97 | + doLast { |
| 98 | + container.outputs.captureLocalImage("pack-build-image:latest") |
| 99 | + } |
| 100 | + } |
| 101 | +} |
| 102 | +``` |
| 103 | + |
47 | 104 | To see more ways to use this plugin see the [examples folder](examples/).
|
48 | 105 |
|
49 | 106 | ## Contributing
|
|
0 commit comments