Skip to content

Commit

Permalink
Add examples
Browse files Browse the repository at this point in the history
Authored-by: Leonhardt Koepsell <[email protected]>
  • Loading branch information
lnhrdt committed Nov 3, 2024
1 parent a3ce376 commit 240e848
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 40 deletions.
41 changes: 1 addition & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ Create tasks that use containers:
import dev.codebandits.ContainerRunTask

tasks {
register<ContainerRunTask>("sayHello") {
dockerRun {
image = "alpine:latest"
args = arrayOf("echo", "Hello from a container!")
}
}

register<ContainerRunTask>("writeHello") {
dockerRun {
image = "alpine:latest"
Expand All @@ -48,39 +41,7 @@ tasks {
}
```

Declare containers as task inputs and outputs:

```kotlin
import dev.codebandits.ContainerRunTask

tasks {
register<ContainerRunTask>("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<ContainerRunTask>("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

Expand Down
22 changes: 22 additions & 0 deletions examples/basic-groovy/build.gradle
Original file line number Diff line number Diff line change
@@ -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[])
}
}
1 change: 1 addition & 0 deletions examples/basic-groovy/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
includeBuild('../../')
26 changes: 26 additions & 0 deletions examples/basic-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import dev.codebandits.ContainerRunTask

plugins {
id("dev.codebandits.container")
}

tasks {
register<ContainerRunTask>("sayHello") {
dockerRun {
image = "alpine:latest"
args = arrayOf("echo", "Hello from a container!")
}
}

register<ContainerRunTask>("writeHello") {
dockerRun {
image = "alpine:latest"
entrypoint = "sh"
args = arrayOf("-c", "echo Hello from a container! > message.txt")
workdir = "/workdir"
volumes = arrayOf(
"${layout.projectDirectory}:/workdir",
)
}
}
}
1 change: 1 addition & 0 deletions examples/basic-kotlin/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
includeBuild("../../")
26 changes: 26 additions & 0 deletions examples/buildpacks/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import dev.codebandits.ContainerRunTask
import dev.codebandits.outputImages

plugins {
id("dev.codebandits.container")
}

tasks {
register<ContainerRunTask>("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",
)
}
}
}
10 changes: 10 additions & 0 deletions examples/buildpacks/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Container</title>
</head>
<body>

</body>
</html>
10 changes: 10 additions & 0 deletions examples/buildpacks/project.toml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions examples/buildpacks/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
includeBuild("../../")
1 change: 1 addition & 0 deletions examples/dind-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM scratch
23 changes: 23 additions & 0 deletions examples/dind-build/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import dev.codebandits.ContainerRunTask
import dev.codebandits.outputImages

plugins {
id("dev.codebandits.container")
}

tasks {
register<ContainerRunTask>("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",
)
}
}
}
1 change: 1 addition & 0 deletions examples/dind-build/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
includeBuild("../../")
1 change: 1 addition & 0 deletions examples/input-output-chaining/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM scratch
37 changes: 37 additions & 0 deletions examples/input-output-chaining/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import dev.codebandits.ContainerRunTask
import dev.codebandits.inputImages
import dev.codebandits.outputImages

plugins {
id("dev.codebandits.container")
}

tasks {
register<ContainerRunTask>("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<ContainerRunTask>("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",
)
}
}
}
1 change: 1 addition & 0 deletions examples/input-output-chaining/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
includeBuild("../../")

0 comments on commit 240e848

Please sign in to comment.