-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle
65 lines (56 loc) · 2.13 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
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('web.base')
String image = project.property('web.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
// COPY --chown=www-data layouts/ /data/layouts
it.copyFile 'layouts', '/data/layouts'
it.runCommand 'chown www-data:www-data /data/layouts'
it.label(labels)
it.destFile.set dockerfileDest
}
def prepareDocker = project.tasks.register('prepareDocker', Sync) {
it.dependsOn createDockerfile
it.from dockerfileDest
it.from('src/main/layouts.application') {
into 'layouts'
}
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