diff --git a/README.md b/README.md index 87cc4cc..7babe4c 100644 --- a/README.md +++ b/README.md @@ -27,18 +27,11 @@ Create tasks that use containers: import dev.codebandits.ContainerRunTask tasks { - register("sayHello") { - dockerRun { - image = "alpine:latest" - args = arrayOf("echo", "Hello from a container!") - } - } - register("writeHello") { dockerRun { image = "alpine:latest" entrypoint = "sh" - args = arrayOf("-c", "echo 'Hello from a container!' > message.txt") + args = arrayOf("-c", "echo Hello from a container! > message.txt") workdir = "/workdir" volumes = arrayOf( "${layout.projectDirectory}:/workdir", @@ -48,39 +41,7 @@ tasks { } ``` -Declare containers as task inputs and outputs: - -```kotlin -import dev.codebandits.ContainerRunTask - -tasks { - register("buildContainer") { - outputImages.dockerLocal("my-image:latest") - dockerRun { - image = "buildpacksio/pack:latest" - args = arrayOf( - "build", "my-image:latest", - "--builder", "paketobuildpacks/builder-jammy-base:latest" - ) - workdir = "/workdir" - volumes = arrayOf( - "${layout.projectDirectory}:/workdir", - "/var/run/docker.sock:/var/run/docker.sock:ro", - ) - } - } - - register("useContainer") { - dependsOn("buildContainer") - inputImages.dockerLocal("my-image:latest") - dockerRun { - image = "my-image:latest" - entrypoint = "echo" - args = arrayOf("echo", "Hello from my custom container!") - } - } -} -``` +To see more ways to use this plugin see the [examples folder](examples/). ## Contributing diff --git a/examples/basic-groovy/build.gradle b/examples/basic-groovy/build.gradle new file mode 100644 index 0000000..99d1860 --- /dev/null +++ b/examples/basic-groovy/build.gradle @@ -0,0 +1,22 @@ +import dev.codebandits.ContainerRunTask + +plugins { + id 'dev.codebandits.container' +} + +tasks.register('sayHello', ContainerRunTask) { + dockerRun { + it.image.set('alpine:latest') + it.args.set(['echo', 'Hello from a container!'] as String[]) + } +} + +tasks.register('writeHello', ContainerRunTask) { + dockerRun { + it.image.set('alpine:latest') + it.entrypoint.set('sh') + it.args.set(['-c', "echo Hello from a container! > message.txt"] as String[]) + it.workdir.set('/workdir') + it.volumes.set(["${layout.projectDirectory}:/workdir"] as String[]) + } +} diff --git a/examples/basic-groovy/settings.gradle b/examples/basic-groovy/settings.gradle new file mode 100644 index 0000000..a2e5059 --- /dev/null +++ b/examples/basic-groovy/settings.gradle @@ -0,0 +1 @@ +includeBuild('../../') diff --git a/examples/basic-kotlin/build.gradle.kts b/examples/basic-kotlin/build.gradle.kts new file mode 100644 index 0000000..cfffcfb --- /dev/null +++ b/examples/basic-kotlin/build.gradle.kts @@ -0,0 +1,26 @@ +import dev.codebandits.ContainerRunTask + +plugins { + id("dev.codebandits.container") +} + +tasks { + register("sayHello") { + dockerRun { + image = "alpine:latest" + args = arrayOf("echo", "Hello from a container!") + } + } + + register("writeHello") { + dockerRun { + image = "alpine:latest" + entrypoint = "sh" + args = arrayOf("-c", "echo Hello from a container! > message.txt") + workdir = "/workdir" + volumes = arrayOf( + "${layout.projectDirectory}:/workdir", + ) + } + } +} diff --git a/examples/basic-kotlin/settings.gradle.kts b/examples/basic-kotlin/settings.gradle.kts new file mode 100644 index 0000000..a10ac80 --- /dev/null +++ b/examples/basic-kotlin/settings.gradle.kts @@ -0,0 +1 @@ +includeBuild("../../") diff --git a/examples/buildpacks/build.gradle.kts b/examples/buildpacks/build.gradle.kts new file mode 100644 index 0000000..a081062 --- /dev/null +++ b/examples/buildpacks/build.gradle.kts @@ -0,0 +1,26 @@ +import dev.codebandits.ContainerRunTask +import dev.codebandits.outputImages + +plugins { + id("dev.codebandits.container") +} + +tasks { + register("buildImage") { + inputs.file("index.html") + inputs.file("project.toml") + outputImages.dockerLocal("my-image:latest") + dockerRun { + image = "buildpacksio/pack:latest" + args = arrayOf( + "build", "my-image:latest", + "--builder", "paketobuildpacks/builder-jammy-base:latest", + ) + workdir = "/workdir" + volumes = arrayOf( + "${layout.projectDirectory}:/workdir", + "/var/run/docker.sock:/var/run/docker.sock:ro", + ) + } + } +} diff --git a/examples/buildpacks/index.html b/examples/buildpacks/index.html new file mode 100644 index 0000000..df078c2 --- /dev/null +++ b/examples/buildpacks/index.html @@ -0,0 +1,10 @@ + + + + + Container + + + + + diff --git a/examples/buildpacks/project.toml b/examples/buildpacks/project.toml new file mode 100644 index 0000000..af485bb --- /dev/null +++ b/examples/buildpacks/project.toml @@ -0,0 +1,10 @@ +[_] +schema-version = "0.2" + +[io.buildpacks] +builder = "paketo-buildpacks/nginx" +include = ["index.html"] + +[[io.buildpacks.build.env]] +name = "BP_WEB_SERVER" +value = "nginx" diff --git a/examples/buildpacks/settings.gradle.kts b/examples/buildpacks/settings.gradle.kts new file mode 100644 index 0000000..a10ac80 --- /dev/null +++ b/examples/buildpacks/settings.gradle.kts @@ -0,0 +1 @@ +includeBuild("../../") diff --git a/examples/dind-build/Dockerfile b/examples/dind-build/Dockerfile new file mode 100644 index 0000000..c35f1b5 --- /dev/null +++ b/examples/dind-build/Dockerfile @@ -0,0 +1 @@ +FROM scratch diff --git a/examples/dind-build/build.gradle.kts b/examples/dind-build/build.gradle.kts new file mode 100644 index 0000000..9a5b1a5 --- /dev/null +++ b/examples/dind-build/build.gradle.kts @@ -0,0 +1,23 @@ +import dev.codebandits.ContainerRunTask +import dev.codebandits.outputImages + +plugins { + id("dev.codebandits.container") +} + +tasks { + register("buildImage") { + inputs.file("Dockerfile") + outputImages.dockerLocal("my-image:latest") + dockerRun { + image = "docker:dind" + entrypoint = "docker" + args = arrayOf("build", "-t", "my-image:latest", ".") + workdir = "/workdir" + volumes = arrayOf( + "${layout.projectDirectory}:/workdir", + "/var/run/docker.sock:/var/run/docker.sock:ro", + ) + } + } +} diff --git a/examples/dind-build/settings.gradle.kts b/examples/dind-build/settings.gradle.kts new file mode 100644 index 0000000..a10ac80 --- /dev/null +++ b/examples/dind-build/settings.gradle.kts @@ -0,0 +1 @@ +includeBuild("../../") diff --git a/examples/input-output-chaining/Dockerfile b/examples/input-output-chaining/Dockerfile new file mode 100644 index 0000000..c35f1b5 --- /dev/null +++ b/examples/input-output-chaining/Dockerfile @@ -0,0 +1 @@ +FROM scratch diff --git a/examples/input-output-chaining/build.gradle.kts b/examples/input-output-chaining/build.gradle.kts new file mode 100644 index 0000000..c292cd1 --- /dev/null +++ b/examples/input-output-chaining/build.gradle.kts @@ -0,0 +1,37 @@ +import dev.codebandits.ContainerRunTask +import dev.codebandits.inputImages +import dev.codebandits.outputImages + +plugins { + id("dev.codebandits.container") +} + +tasks { + register("printImageID") { + dependsOn("buildImage") + inputImages.dockerLocal("my-image:latest") + dockerRun { + image = "docker:dind" + entrypoint = "docker" + args = arrayOf("images", "--filter", "reference=my-image:latest", "--format", "{{.ID}}") + volumes = arrayOf( + "/var/run/docker.sock:/var/run/docker.sock:ro", + ) + } + } + + register("buildImage") { + inputs.file("Dockerfile") + outputImages.dockerLocal("my-image:latest") + dockerRun { + image = "docker:dind" + entrypoint = "docker" + args = arrayOf("build", "-t", "my-image:latest", ".") + workdir = "/workdir" + volumes = arrayOf( + "${layout.projectDirectory}:/workdir", + "/var/run/docker.sock:/var/run/docker.sock:ro", + ) + } + } +} diff --git a/examples/input-output-chaining/settings.gradle.kts b/examples/input-output-chaining/settings.gradle.kts new file mode 100644 index 0000000..a10ac80 --- /dev/null +++ b/examples/input-output-chaining/settings.gradle.kts @@ -0,0 +1 @@ +includeBuild("../../")