server is now a subcommand
This commit is contained in:
@@ -7,7 +7,7 @@ WORKDIR /home/luser
|
|||||||
|
|
||||||
FROM base-release AS release
|
FROM base-release AS release
|
||||||
ADD gbcs-cli-envelope-*.jar gbcs.jar
|
ADD gbcs-cli-envelope-*.jar gbcs.jar
|
||||||
ENTRYPOINT ["java", "-jar", "/home/luser/gbcs.jar"]
|
ENTRYPOINT ["java", "-jar", "/home/luser/gbcs.jar", "server"]
|
||||||
|
|
||||||
FROM base-release AS release-memcached
|
FROM base-release AS release-memcached
|
||||||
ADD --chown=luser:luser gbcs-cli-envelope-*.jar gbcs.jar
|
ADD --chown=luser:luser gbcs-cli-envelope-*.jar gbcs.jar
|
||||||
@@ -15,7 +15,7 @@ RUN mkdir plugins
|
|||||||
WORKDIR /home/luser/plugins
|
WORKDIR /home/luser/plugins
|
||||||
RUN --mount=type=bind,source=.,target=/build/distributions tar -xf /build/distributions/gbcs-memcached*.tar
|
RUN --mount=type=bind,source=.,target=/build/distributions tar -xf /build/distributions/gbcs-memcached*.tar
|
||||||
WORKDIR /home/luser
|
WORKDIR /home/luser
|
||||||
ENTRYPOINT ["java", "-jar", "/home/luser/gbcs.jar"]
|
ENTRYPOINT ["java", "-jar", "/home/luser/gbcs.jar", "server"]
|
||||||
|
|
||||||
FROM release-memcached as compose
|
FROM release-memcached as compose
|
||||||
COPY --chown=luser:luser conf/gbcs-memcached.xml /home/luser/.config/gbcs/gbcs.xml
|
COPY --chown=luser:luser conf/gbcs-memcached.xml /home/luser/.config/gbcs/gbcs.xml
|
@@ -1,30 +1,22 @@
|
|||||||
package net.woggioni.gbcs.cli
|
package net.woggioni.gbcs.cli
|
||||||
|
|
||||||
import net.woggioni.gbcs.GradleBuildCacheServer
|
|
||||||
import net.woggioni.gbcs.GradleBuildCacheServer.Companion.DEFAULT_CONFIGURATION_URL
|
|
||||||
import net.woggioni.gbcs.base.GbcsUrlStreamHandlerFactory
|
import net.woggioni.gbcs.base.GbcsUrlStreamHandlerFactory
|
||||||
import net.woggioni.gbcs.base.contextLogger
|
import net.woggioni.gbcs.base.contextLogger
|
||||||
import net.woggioni.gbcs.base.debug
|
|
||||||
import net.woggioni.gbcs.base.info
|
|
||||||
import net.woggioni.gbcs.cli.impl.AbstractVersionProvider
|
import net.woggioni.gbcs.cli.impl.AbstractVersionProvider
|
||||||
import net.woggioni.gbcs.cli.impl.GbcsCommand
|
import net.woggioni.gbcs.cli.impl.GbcsCommand
|
||||||
import net.woggioni.gbcs.cli.impl.commands.BenchmarkCommand
|
import net.woggioni.gbcs.cli.impl.commands.BenchmarkCommand
|
||||||
import net.woggioni.gbcs.cli.impl.commands.ClientCommand
|
import net.woggioni.gbcs.cli.impl.commands.ClientCommand
|
||||||
import net.woggioni.gbcs.cli.impl.commands.PasswordHashCommand
|
import net.woggioni.gbcs.cli.impl.commands.PasswordHashCommand
|
||||||
|
import net.woggioni.gbcs.cli.impl.commands.ServerCommand
|
||||||
import net.woggioni.jwo.Application
|
import net.woggioni.jwo.Application
|
||||||
import net.woggioni.jwo.JWO
|
|
||||||
import org.slf4j.Logger
|
|
||||||
import picocli.CommandLine
|
import picocli.CommandLine
|
||||||
import picocli.CommandLine.Model.CommandSpec
|
import picocli.CommandLine.Model.CommandSpec
|
||||||
import java.io.ByteArrayOutputStream
|
|
||||||
import java.nio.file.Files
|
|
||||||
import java.nio.file.Path
|
|
||||||
|
|
||||||
|
|
||||||
@CommandLine.Command(
|
@CommandLine.Command(
|
||||||
name = "gbcs", versionProvider = GradleBuildCacheServerCli.VersionProvider::class
|
name = "gbcs", versionProvider = GradleBuildCacheServerCli.VersionProvider::class
|
||||||
)
|
)
|
||||||
class GradleBuildCacheServerCli(application: Application, private val log: Logger) : GbcsCommand() {
|
class GradleBuildCacheServerCli : GbcsCommand() {
|
||||||
|
|
||||||
class VersionProvider : AbstractVersionProvider()
|
class VersionProvider : AbstractVersionProvider()
|
||||||
companion object {
|
companion object {
|
||||||
@@ -37,33 +29,22 @@ class GradleBuildCacheServerCli(application: Application, private val log: Logge
|
|||||||
.configurationDirectoryEnvVar("GBCS_CONFIGURATION_DIR")
|
.configurationDirectoryEnvVar("GBCS_CONFIGURATION_DIR")
|
||||||
.configurationDirectoryPropertyKey("net.woggioni.gbcs.conf.dir")
|
.configurationDirectoryPropertyKey("net.woggioni.gbcs.conf.dir")
|
||||||
.build()
|
.build()
|
||||||
val gbcsCli = GradleBuildCacheServerCli(app, log)
|
val gbcsCli = GradleBuildCacheServerCli()
|
||||||
val commandLine = CommandLine(gbcsCli)
|
val commandLine = CommandLine(gbcsCli)
|
||||||
commandLine.setExecutionExceptionHandler { ex, cl, parseResult ->
|
commandLine.setExecutionExceptionHandler { ex, cl, parseResult ->
|
||||||
log.error(ex.message, ex)
|
log.error(ex.message, ex)
|
||||||
CommandLine.ExitCode.SOFTWARE
|
CommandLine.ExitCode.SOFTWARE
|
||||||
}
|
}
|
||||||
|
commandLine.addSubcommand(ServerCommand(app))
|
||||||
commandLine.addSubcommand(PasswordHashCommand())
|
commandLine.addSubcommand(PasswordHashCommand())
|
||||||
val clientApp = Application.builder("gbcs-client")
|
|
||||||
.configurationDirectoryEnvVar("GBCS_CLIENT_CONFIGURATION_DIR")
|
|
||||||
.configurationDirectoryPropertyKey("net.woggioni.gbcs.client.conf.dir")
|
|
||||||
.build()
|
|
||||||
|
|
||||||
commandLine.addSubcommand(
|
commandLine.addSubcommand(
|
||||||
CommandLine(ClientCommand(clientApp)).apply {
|
CommandLine(ClientCommand(app)).apply {
|
||||||
addSubcommand(BenchmarkCommand())
|
addSubcommand(BenchmarkCommand())
|
||||||
})
|
})
|
||||||
System.exit(commandLine.execute(*args))
|
System.exit(commandLine.execute(*args))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@CommandLine.Option(
|
|
||||||
names = ["-c", "--config-file"],
|
|
||||||
description = ["Read the application configuration from this file"],
|
|
||||||
paramLabel = "CONFIG_FILE"
|
|
||||||
)
|
|
||||||
private var configurationFile: Path = findConfigurationFile(application)
|
|
||||||
|
|
||||||
@CommandLine.Option(names = ["-V", "--version"], versionHelp = true)
|
@CommandLine.Option(names = ["-V", "--version"], versionHelp = true)
|
||||||
var versionHelp = false
|
var versionHelp = false
|
||||||
private set
|
private set
|
||||||
@@ -71,40 +52,8 @@ class GradleBuildCacheServerCli(application: Application, private val log: Logge
|
|||||||
@CommandLine.Spec
|
@CommandLine.Spec
|
||||||
private lateinit var spec: CommandSpec
|
private lateinit var spec: CommandSpec
|
||||||
|
|
||||||
private fun findConfigurationFile(app: Application): Path {
|
|
||||||
val confDir = app.computeConfigurationDirectory()
|
|
||||||
val configurationFile = confDir.resolve("gbcs.xml")
|
|
||||||
return configurationFile
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createDefaultConfigurationFile(configurationFile: Path) {
|
|
||||||
log.info {
|
|
||||||
"Creating default configuration file at '$configurationFile'"
|
|
||||||
}
|
|
||||||
val defaultConfigurationFileResource = DEFAULT_CONFIGURATION_URL
|
|
||||||
Files.newOutputStream(configurationFile).use { outputStream ->
|
|
||||||
defaultConfigurationFileResource.openStream().use { inputStream ->
|
|
||||||
JWO.copy(inputStream, outputStream)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (!Files.exists(configurationFile)) {
|
spec.commandLine().usage(System.out);
|
||||||
Files.createDirectories(configurationFile.parent)
|
|
||||||
createDefaultConfigurationFile(configurationFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
val configuration = GradleBuildCacheServer.loadConfiguration(configurationFile)
|
|
||||||
log.debug {
|
|
||||||
ByteArrayOutputStream().also {
|
|
||||||
GradleBuildCacheServer.dumpConfiguration(configuration, it)
|
|
||||||
}.let {
|
|
||||||
"Server configuration:\n${String(it.toByteArray())}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val server = GradleBuildCacheServer(configuration)
|
|
||||||
server.run().use {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,6 +1,8 @@
|
|||||||
package net.woggioni.gbcs.cli.impl
|
package net.woggioni.gbcs.cli.impl
|
||||||
|
|
||||||
|
import net.woggioni.jwo.Application
|
||||||
import picocli.CommandLine
|
import picocli.CommandLine
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
|
||||||
abstract class GbcsCommand : Runnable {
|
abstract class GbcsCommand : Runnable {
|
||||||
@@ -8,4 +10,10 @@ abstract class GbcsCommand : Runnable {
|
|||||||
@CommandLine.Option(names = ["-h", "--help"], usageHelp = true)
|
@CommandLine.Option(names = ["-h", "--help"], usageHelp = true)
|
||||||
var usageHelp = false
|
var usageHelp = false
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
protected fun findConfigurationFile(app: Application, fileName : String): Path {
|
||||||
|
val confDir = app.computeConfigurationDirectory()
|
||||||
|
val configurationFile = confDir.resolve(fileName)
|
||||||
|
return configurationFile
|
||||||
|
}
|
||||||
}
|
}
|
@@ -14,20 +14,12 @@ import java.nio.file.Path
|
|||||||
)
|
)
|
||||||
class ClientCommand(app : Application) : GbcsCommand() {
|
class ClientCommand(app : Application) : GbcsCommand() {
|
||||||
|
|
||||||
companion object {
|
|
||||||
private fun findConfigurationFile(app: Application): Path {
|
|
||||||
val confDir = app.computeConfigurationDirectory()
|
|
||||||
val configurationFile = confDir.resolve("gbcs-client.xml")
|
|
||||||
return configurationFile
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@CommandLine.Option(
|
@CommandLine.Option(
|
||||||
names = ["-c", "--configuration"],
|
names = ["-c", "--configuration"],
|
||||||
description = ["Path to the client configuration file"],
|
description = ["Path to the client configuration file"],
|
||||||
paramLabel = "CONFIGURATION_FILE"
|
paramLabel = "CONFIGURATION_FILE"
|
||||||
)
|
)
|
||||||
private var configurationFile : Path = findConfigurationFile(app)
|
private var configurationFile : Path = findConfigurationFile(app, "gbcs-client.xml")
|
||||||
|
|
||||||
@CommandLine.Option(
|
@CommandLine.Option(
|
||||||
names = ["-p", "--profile"],
|
names = ["-p", "--profile"],
|
||||||
|
@@ -0,0 +1,67 @@
|
|||||||
|
package net.woggioni.gbcs.cli.impl.commands
|
||||||
|
|
||||||
|
import net.woggioni.gbcs.GradleBuildCacheServer
|
||||||
|
import net.woggioni.gbcs.GradleBuildCacheServer.Companion.DEFAULT_CONFIGURATION_URL
|
||||||
|
import net.woggioni.gbcs.base.contextLogger
|
||||||
|
import net.woggioni.gbcs.base.debug
|
||||||
|
import net.woggioni.gbcs.base.info
|
||||||
|
import net.woggioni.gbcs.cli.impl.GbcsCommand
|
||||||
|
import net.woggioni.gbcs.client.GbcsClient
|
||||||
|
import net.woggioni.jwo.Application
|
||||||
|
import net.woggioni.jwo.JWO
|
||||||
|
import picocli.CommandLine
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
@CommandLine.Command(
|
||||||
|
name = "server",
|
||||||
|
description = ["GBCS server"],
|
||||||
|
showDefaultValues = true
|
||||||
|
)
|
||||||
|
class ServerCommand(app : Application) : GbcsCommand() {
|
||||||
|
|
||||||
|
private val log = contextLogger()
|
||||||
|
|
||||||
|
private fun createDefaultConfigurationFile(configurationFile: Path) {
|
||||||
|
log.info {
|
||||||
|
"Creating default configuration file at '$configurationFile'"
|
||||||
|
}
|
||||||
|
val defaultConfigurationFileResource = DEFAULT_CONFIGURATION_URL
|
||||||
|
Files.newOutputStream(configurationFile).use { outputStream ->
|
||||||
|
defaultConfigurationFileResource.openStream().use { inputStream ->
|
||||||
|
JWO.copy(inputStream, outputStream)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@CommandLine.Option(
|
||||||
|
names = ["-c", "--config-file"],
|
||||||
|
description = ["Read the application configuration from this file"],
|
||||||
|
paramLabel = "CONFIG_FILE"
|
||||||
|
)
|
||||||
|
private var configurationFile: Path = findConfigurationFile(app, "gbcs-server.xml")
|
||||||
|
|
||||||
|
val configuration : GbcsClient.Configuration by lazy {
|
||||||
|
GbcsClient.Configuration.parse(configurationFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun run() {
|
||||||
|
if (!Files.exists(configurationFile)) {
|
||||||
|
Files.createDirectories(configurationFile.parent)
|
||||||
|
createDefaultConfigurationFile(configurationFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
val configuration = GradleBuildCacheServer.loadConfiguration(configurationFile)
|
||||||
|
log.debug {
|
||||||
|
ByteArrayOutputStream().also {
|
||||||
|
GradleBuildCacheServer.dumpConfiguration(configuration, it)
|
||||||
|
}.let {
|
||||||
|
"Server configuration:\n${String(it.toByteArray())}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val server = GradleBuildCacheServer(configuration)
|
||||||
|
server.run().use {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user