40 lines
1.0 KiB
Plaintext
40 lines
1.0 KiB
Plaintext
package be.simplenotes
|
|
|
|
import java.util.concurrent.TimeUnit.MINUTES
|
|
import kotlin.concurrent.thread
|
|
|
|
fun runCommand(vararg args: String, onError: () -> Unit) {
|
|
logging.captureStandardOutput(LogLevel.INFO)
|
|
ProcessBuilder(*args)
|
|
.redirectOutput(ProcessBuilder.Redirect.PIPE)
|
|
.redirectError(ProcessBuilder.Redirect.PIPE)
|
|
.directory(rootProject.projectDir)
|
|
.start()
|
|
.apply {
|
|
thread { inputStream.use { it.copyTo(System.out) } }
|
|
thread { errorStream.use { it.copyTo(System.out) } }
|
|
waitFor(2, MINUTES)
|
|
if (exitValue() != 0) onError()
|
|
}
|
|
}
|
|
|
|
tasks.create("dockerBuild") {
|
|
dependsOn("package")
|
|
|
|
doLast {
|
|
runCommand("docker", "build", "-t", "hubv/simplenotes:latest", ".") {
|
|
throw GradleException("Docker build failed")
|
|
}
|
|
}
|
|
}
|
|
|
|
tasks.create("dockerPush") {
|
|
dependsOn("dockerBuild")
|
|
|
|
doLast {
|
|
runCommand("docker", "push", "hubv/simplenotes:latest") {
|
|
throw GradleException("Docker Push failed")
|
|
}
|
|
}
|
|
}
|