You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.7 KiB
67 lines
1.7 KiB
package de.joshavg
|
|
|
|
import org.slf4j.Logger
|
|
import org.slf4j.LoggerFactory
|
|
import java.io.File
|
|
import javax.inject.Inject
|
|
import javax.ws.rs.*
|
|
import javax.ws.rs.core.MediaType
|
|
import javax.ws.rs.core.Response
|
|
|
|
@Path("/builds")
|
|
class BuildsEndpoint(
|
|
@Inject
|
|
val builds: Builds,
|
|
@Inject
|
|
val security: Security
|
|
) {
|
|
|
|
val logger: Logger = LoggerFactory.getLogger(this::class.java)
|
|
|
|
@GET
|
|
@Path("/{build}/info")
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
fun info(@PathParam("build")
|
|
build: String,
|
|
@QueryParam("key")
|
|
key: String?) =
|
|
security.requireKey(build, key) {
|
|
it.asPublic()
|
|
}
|
|
|
|
@GET
|
|
@Path("/{build}/trigger")
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
fun trigger(@PathParam("build")
|
|
build: String,
|
|
@QueryParam("key")
|
|
key: String?) =
|
|
security.requireKey(build, key) {
|
|
val logFile = builds.createLogFile(build)
|
|
|
|
startBuildThread(build, logFile, it)
|
|
|
|
Response.ok(mapOf(
|
|
"log" to logFile.absolutePath
|
|
))
|
|
.build()
|
|
}
|
|
|
|
fun startBuildThread(build: String, logFile: File, config: BuildConfig) =
|
|
Thread {
|
|
logger.info("preparing process for build $build with config ${config.asPublic()}")
|
|
logger.info("log file: $logFile")
|
|
|
|
val builder = ProcessBuilder(config.exec)
|
|
.directory(File(config.dir))
|
|
.redirectOutput(logFile)
|
|
.redirectError(logFile)
|
|
val process = builder.start()
|
|
val pid = process.toHandle().pid()
|
|
|
|
logger.info("pid for build $build is: $pid")
|
|
}.start()
|
|
|
|
}
|
|
|