-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle
76 lines (67 loc) · 2.44 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.DockerPushImage
import com.bmuschko.gradle.docker.tasks.image.DockerRemoveImage
import com.bmuschko.gradle.docker.tasks.image.Dockerfile
plugins {
id 'base'
id 'com.bmuschko.docker-remote-api' version '6.7.0'
}
String base = project.property('redpanda.base')
String image = project.property('redpanda.image')
def labels = [ 'maintainer': project.property('maintainer') ] + project.properties.findAll { it -> it.key.startsWith('org.opencontainers.image.') }
def dockerfileDest = project.layout.buildDirectory.file('docker/Dockerfile')
def dockerfileDir = project.layout.buildDirectory.dir('prepareDocker')
def imageIdFile = project.layout.buildDirectory.file('.docker/imageId.txt').get().asFile
def imageId = imageIdFile.exists() ? imageIdFile.text : null
def createDockerfile = project.tasks.register('createDockerfile', Dockerfile) {
it.from base
// Redpanda schema registry, not exposed by base image
it.exposePort(8081)
it.defaultCommand(
"redpanda",
"start",
"--smp",
"1",
"--reserve-memory",
"0M",
"--overprovisioned",
"--node-id",
"0",
"--check=false",
"--kafka-addr",
"PLAINTEXT://0.0.0.0:29092,OUTSIDE://0.0.0.0:9092",
"--advertise-kafka-addr",
"PLAINTEXT://redpanda:29092,OUTSIDE://redpanda:9092")
it.label(labels)
it.destFile.set dockerfileDest
}
def prepareDocker = project.tasks.register('prepareDocker', Sync) {
it.dependsOn createDockerfile
it.from dockerfileDest
it.into dockerfileDir
}
def buildImage = project.tasks.register('buildImage', DockerBuildImage) {
it.dependsOn prepareDocker
it.inputDir.set dockerfileDir
it.imageIdFile.set imageIdFile
it.images.add(image)
}
project.tasks.register('deleteImage', DockerRemoveImage) {
it.onlyIf { imageId != null }
it.imageId.set imageId
it.force.set true
it.onError { exception ->
if (!exception.message.contains('No such image'))
throw exception
}
it.doLast {
imageIdFile.delete()
}
}
project.tasks.register('pushImage', DockerPushImage) {
DockerBuildImage buildImageTask = buildImage.get()
it.dependsOn buildImageTask
it.inputs.files buildImageTask.outputs.files
it.images.add(image)
}
assemble.dependsOn buildImage