updated Netty version
This commit is contained in:
@@ -9,7 +9,7 @@ WORKDIR /home/ubuntu
|
|||||||
RUN mkdir gbcs
|
RUN mkdir gbcs
|
||||||
WORKDIR /home/ubuntu/gbcs
|
WORKDIR /home/ubuntu/gbcs
|
||||||
|
|
||||||
COPY --chown=ubuntu:users .git .git
|
COPY --chown=ubuntu:users ./.git ./.git
|
||||||
COPY --chown=ubuntu:users gbcs-base gbcs-base
|
COPY --chown=ubuntu:users gbcs-base gbcs-base
|
||||||
COPY --chown=ubuntu:users gbcs-api gbcs-api
|
COPY --chown=ubuntu:users gbcs-api gbcs-api
|
||||||
COPY --chown=ubuntu:users gbcs-memcached gbcs-memcached
|
COPY --chown=ubuntu:users gbcs-memcached gbcs-memcached
|
||||||
@@ -21,7 +21,7 @@ COPY --chown=ubuntu:users gradle.properties gradle.properties
|
|||||||
COPY --chown=ubuntu:users gradle gradle
|
COPY --chown=ubuntu:users gradle gradle
|
||||||
COPY --chown=ubuntu:users gradlew gradlew
|
COPY --chown=ubuntu:users gradlew gradlew
|
||||||
|
|
||||||
RUN --mount=type=cache,target=/home/ubuntu/.gradle,uid=1000,gid=1000 ./gradlew --no-daemon assemble
|
RUN --mount=type=cache,target=/home/ubuntu/.gradle,uid=1000,gid=1000 ./gradlew --no-daemon clean assemble
|
||||||
|
|
||||||
FROM alpine:latest AS base-release
|
FROM alpine:latest AS base-release
|
||||||
RUN --mount=type=cache,target=/var/cache/apk apk update
|
RUN --mount=type=cache,target=/var/cache/apk apk update
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<gbcs:server useVirtualThreads="false" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
<gbcs:server useVirtualThreads="true" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:gbcs="urn:net.woggioni.gbcs"
|
xmlns:gbcs="urn:net.woggioni.gbcs"
|
||||||
xmlns:gbcs-memcached="urn:net.woggioni.gbcs-memcached"
|
xmlns:gbcs-memcached="urn:net.woggioni.gbcs-memcached"
|
||||||
xs:schemaLocation="urn:net.woggioni.gbcs-memcached jpms://net.woggioni.gbcs.memcached/net/woggioni/gbcs/memcached/schema/gbcs-memcached.xsd urn:net.woggioni.gbcs jpms://net.woggioni.gbcs/net/woggioni/gbcs/schema/gbcs.xsd">
|
xs:schemaLocation="urn:net.woggioni.gbcs-memcached jpms://net.woggioni.gbcs.memcached/net/woggioni/gbcs/memcached/schema/gbcs-memcached.xsd urn:net.woggioni.gbcs jpms://net.woggioni.gbcs/net/woggioni/gbcs/schema/gbcs.xsd">
|
||||||
|
@@ -92,7 +92,14 @@ class GradleBuildCacheServerCli(application : Application, private val log : Log
|
|||||||
"Server configuration:\n${String(it.toByteArray())}"
|
"Server configuration:\n${String(it.toByteArray())}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GradleBuildCacheServer(configuration).run().use {
|
val server = GradleBuildCacheServer(configuration)
|
||||||
|
server.run().use {
|
||||||
|
log.info {
|
||||||
|
"GradleBuildCacheServer is listening on ${configuration.host}:${configuration.port}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info {
|
||||||
|
"GradleBuildCacheServer has been gracefully shut down"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -4,6 +4,6 @@ org.gradle.caching=true
|
|||||||
|
|
||||||
gbcs.version = 0.0.1
|
gbcs.version = 0.0.1
|
||||||
|
|
||||||
lys.version = 2025.01.09
|
lys.version = 2025.01.10
|
||||||
|
|
||||||
gitea.maven.url = https://gitea.woggioni.net/api/packages/woggioni/maven
|
gitea.maven.url = https://gitea.woggioni.net/api/packages/woggioni/maven
|
||||||
|
@@ -12,7 +12,6 @@ import io.netty.channel.ChannelInitializer
|
|||||||
import io.netty.channel.ChannelOption
|
import io.netty.channel.ChannelOption
|
||||||
import io.netty.channel.ChannelPromise
|
import io.netty.channel.ChannelPromise
|
||||||
import io.netty.channel.DefaultFileRegion
|
import io.netty.channel.DefaultFileRegion
|
||||||
import io.netty.channel.EventLoopGroup
|
|
||||||
import io.netty.channel.SimpleChannelInboundHandler
|
import io.netty.channel.SimpleChannelInboundHandler
|
||||||
import io.netty.channel.nio.NioEventLoopGroup
|
import io.netty.channel.nio.NioEventLoopGroup
|
||||||
import io.netty.channel.socket.nio.NioServerSocketChannel
|
import io.netty.channel.socket.nio.NioServerSocketChannel
|
||||||
@@ -69,7 +68,6 @@ import java.security.PrivateKey
|
|||||||
import java.security.cert.X509Certificate
|
import java.security.cert.X509Certificate
|
||||||
import java.util.Arrays
|
import java.util.Arrays
|
||||||
import java.util.Base64
|
import java.util.Base64
|
||||||
import java.util.concurrent.Executors
|
|
||||||
import java.util.regex.Matcher
|
import java.util.regex.Matcher
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
import javax.naming.ldap.LdapName
|
import javax.naming.ldap.LdapName
|
||||||
@@ -178,40 +176,39 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ServerInitializer(private val cfg: Configuration) : ChannelInitializer<Channel>() {
|
private class ServerInitializer(
|
||||||
|
private val cfg: Configuration,
|
||||||
private fun createSslCtx(tls: Configuration.Tls): SslContext {
|
private val eventExecutorGroup: EventExecutorGroup
|
||||||
val keyStore = tls.keyStore
|
) : ChannelInitializer<Channel>() {
|
||||||
return if (keyStore == null) {
|
|
||||||
throw IllegalArgumentException("No keystore configured")
|
|
||||||
} else {
|
|
||||||
val javaKeyStore = loadKeystore(keyStore.file, keyStore.password)
|
|
||||||
val serverKey = javaKeyStore.getKey(
|
|
||||||
keyStore.keyAlias, keyStore.keyPassword?.let(String::toCharArray)
|
|
||||||
) as PrivateKey
|
|
||||||
val serverCert: Array<X509Certificate> =
|
|
||||||
Arrays.stream(javaKeyStore.getCertificateChain(keyStore.keyAlias))
|
|
||||||
.map { it as X509Certificate }
|
|
||||||
.toArray { size -> Array<X509Certificate?>(size) { null } }
|
|
||||||
SslContextBuilder.forServer(serverKey, *serverCert).apply {
|
|
||||||
if (tls.isVerifyClients) {
|
|
||||||
clientAuth(ClientAuth.OPTIONAL)
|
|
||||||
val trustStore = tls.trustStore
|
|
||||||
if (trustStore != null) {
|
|
||||||
val ts = loadKeystore(trustStore.file, trustStore.password)
|
|
||||||
trustManager(
|
|
||||||
ClientCertificateValidator.getTrustManager(ts, trustStore.isCheckCertificateStatus)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val sslContext: SslContext? = cfg.tls?.let(this::createSslCtx)
|
|
||||||
private val group: EventExecutorGroup = DefaultEventExecutorGroup(Runtime.getRuntime().availableProcessors())
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private fun createSslCtx(tls: Configuration.Tls): SslContext {
|
||||||
|
val keyStore = tls.keyStore
|
||||||
|
return if (keyStore == null) {
|
||||||
|
throw IllegalArgumentException("No keystore configured")
|
||||||
|
} else {
|
||||||
|
val javaKeyStore = loadKeystore(keyStore.file, keyStore.password)
|
||||||
|
val serverKey = javaKeyStore.getKey(
|
||||||
|
keyStore.keyAlias, keyStore.keyPassword?.let(String::toCharArray)
|
||||||
|
) as PrivateKey
|
||||||
|
val serverCert: Array<X509Certificate> =
|
||||||
|
Arrays.stream(javaKeyStore.getCertificateChain(keyStore.keyAlias))
|
||||||
|
.map { it as X509Certificate }
|
||||||
|
.toArray { size -> Array<X509Certificate?>(size) { null } }
|
||||||
|
SslContextBuilder.forServer(serverKey, *serverCert).apply {
|
||||||
|
if (tls.isVerifyClients) {
|
||||||
|
clientAuth(ClientAuth.OPTIONAL)
|
||||||
|
val trustStore = tls.trustStore
|
||||||
|
if (trustStore != null) {
|
||||||
|
val ts = loadKeystore(trustStore.file, trustStore.password)
|
||||||
|
trustManager(
|
||||||
|
ClientCertificateValidator.getTrustManager(ts, trustStore.isCheckCertificateStatus)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun loadKeystore(file: Path, password: String?): KeyStore {
|
fun loadKeystore(file: Path, password: String?): KeyStore {
|
||||||
val ext = JWO.splitExtension(file)
|
val ext = JWO.splitExtension(file)
|
||||||
@@ -235,6 +232,8 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val sslContext: SslContext? = cfg.tls?.let(Companion::createSslCtx)
|
||||||
|
|
||||||
private fun userExtractor(authentication: Configuration.ClientCertificateAuthentication) =
|
private fun userExtractor(authentication: Configuration.ClientCertificateAuthentication) =
|
||||||
authentication.userExtractor?.let { extractor ->
|
authentication.userExtractor?.let { extractor ->
|
||||||
val pattern = Pattern.compile(extractor.pattern)
|
val pattern = Pattern.compile(extractor.pattern)
|
||||||
@@ -294,7 +293,7 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
}
|
}
|
||||||
val cacheImplementation = cfg.cache.materialize()
|
val cacheImplementation = cfg.cache.materialize()
|
||||||
val prefix = Path.of("/").resolve(Path.of(cfg.serverPath ?: "/"))
|
val prefix = Path.of("/").resolve(Path.of(cfg.serverPath ?: "/"))
|
||||||
pipeline.addLast(group, ServerHandler(cacheImplementation, prefix))
|
pipeline.addLast(eventExecutorGroup, ServerHandler(cacheImplementation, prefix))
|
||||||
pipeline.addLast(ExceptionHandler())
|
pipeline.addLast(ExceptionHandler())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -446,8 +445,7 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
|
|
||||||
class ServerHandle(
|
class ServerHandle(
|
||||||
httpChannelFuture: ChannelFuture,
|
httpChannelFuture: ChannelFuture,
|
||||||
private val bossGroup: EventLoopGroup,
|
private val executorGroups : Iterable<EventExecutorGroup>
|
||||||
private val workerGroup: EventLoopGroup
|
|
||||||
) : AutoCloseable {
|
) : AutoCloseable {
|
||||||
private val httpChannel: Channel = httpChannelFuture.channel()
|
private val httpChannel: Channel = httpChannelFuture.channel()
|
||||||
|
|
||||||
@@ -461,31 +459,32 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
try {
|
try {
|
||||||
closeFuture.sync()
|
closeFuture.sync()
|
||||||
} finally {
|
} finally {
|
||||||
val fut1 = workerGroup.shutdownGracefully()
|
executorGroups.forEach {
|
||||||
val fut2 = if (bossGroup !== workerGroup) {
|
it.shutdownGracefully().sync()
|
||||||
bossGroup.shutdownGracefully()
|
}
|
||||||
} else null
|
|
||||||
fut1.sync()
|
|
||||||
fut2?.sync()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun run(): ServerHandle {
|
fun run(): ServerHandle {
|
||||||
// Create the multithreaded event loops for the server
|
// Create the multithreaded event loops for the server
|
||||||
val bossGroup = NioEventLoopGroup(0, Executors.defaultThreadFactory())
|
val bossGroup = NioEventLoopGroup(0)
|
||||||
val serverSocketChannel = NioServerSocketChannel::class.java
|
val serverSocketChannel = NioServerSocketChannel::class.java
|
||||||
val workerGroup = if (cfg.isUseVirtualThread) {
|
val workerGroup = bossGroup
|
||||||
NioEventLoopGroup(0, Executors.newVirtualThreadPerTaskExecutor())
|
val eventExecutorGroup = run {
|
||||||
} else {
|
val threadFactory = if(cfg.isUseVirtualThread) {
|
||||||
bossGroup
|
Thread.ofVirtual().factory()
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
DefaultEventExecutorGroup(Runtime.getRuntime().availableProcessors(), threadFactory)
|
||||||
}
|
}
|
||||||
// A helper class that simplifies server configuration
|
// A helper class that simplifies server configuration
|
||||||
val bootstrap = ServerBootstrap().apply {
|
val bootstrap = ServerBootstrap().apply {
|
||||||
// Configure the server
|
// Configure the server
|
||||||
group(bossGroup, workerGroup)
|
group(bossGroup, workerGroup)
|
||||||
channel(serverSocketChannel)
|
channel(serverSocketChannel)
|
||||||
childHandler(ServerInitializer(cfg))
|
childHandler(ServerInitializer(cfg, eventExecutorGroup))
|
||||||
option(ChannelOption.SO_BACKLOG, 128)
|
option(ChannelOption.SO_BACKLOG, 128)
|
||||||
childOption(ChannelOption.SO_KEEPALIVE, true)
|
childOption(ChannelOption.SO_KEEPALIVE, true)
|
||||||
}
|
}
|
||||||
@@ -494,7 +493,7 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
// Bind and start to accept incoming connections.
|
// Bind and start to accept incoming connections.
|
||||||
val bindAddress = InetSocketAddress(cfg.host, cfg.port)
|
val bindAddress = InetSocketAddress(cfg.host, cfg.port)
|
||||||
val httpChannel = bootstrap.bind(bindAddress).sync()
|
val httpChannel = bootstrap.bind(bindAddress).sync()
|
||||||
return ServerHandle(httpChannel, bossGroup, workerGroup)
|
return ServerHandle(httpChannel, setOf(bossGroup, workerGroup, eventExecutorGroup))
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -508,7 +507,7 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
return Parser.parse(doc)
|
return Parser.parse(doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dumpConfiguration(conf : Configuration, outputStream: OutputStream) {
|
fun dumpConfiguration(conf: Configuration, outputStream: OutputStream) {
|
||||||
Xml.write(Serializer.serialize(conf), outputStream)
|
Xml.write(Serializer.serialize(conf), outputStream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,7 @@ object Parser {
|
|||||||
val serverPath = root.getAttribute("path")
|
val serverPath = root.getAttribute("path")
|
||||||
val useVirtualThread = root.getAttribute("useVirtualThreads")
|
val useVirtualThread = root.getAttribute("useVirtualThreads")
|
||||||
.takeIf(String::isNotEmpty)
|
.takeIf(String::isNotEmpty)
|
||||||
?.let(String::toBoolean) ?: false
|
?.let(String::toBoolean) ?: true
|
||||||
var authentication: Authentication? = null
|
var authentication: Authentication? = null
|
||||||
for (child in root.asIterable()) {
|
for (child in root.asIterable()) {
|
||||||
when (child.localName) {
|
when (child.localName) {
|
||||||
|
@@ -10,9 +10,6 @@
|
|||||||
<xs:sequence minOccurs="0">
|
<xs:sequence minOccurs="0">
|
||||||
<xs:element name="bind" type="gbcs:bindType" maxOccurs="1"/>
|
<xs:element name="bind" type="gbcs:bindType" maxOccurs="1"/>
|
||||||
<xs:element name="cache" type="gbcs:cacheType" maxOccurs="1"/>
|
<xs:element name="cache" type="gbcs:cacheType" maxOccurs="1"/>
|
||||||
<!-- <xs:choice>-->
|
|
||||||
<!-- <xs:element name="fileSystemCache" type="fileSystemCacheType"/>-->
|
|
||||||
<!-- </xs:choice>-->
|
|
||||||
<xs:element name="authorization" type="gbcs:authorizationType" minOccurs="0">
|
<xs:element name="authorization" type="gbcs:authorizationType" minOccurs="0">
|
||||||
<xs:key name="userId">
|
<xs:key name="userId">
|
||||||
<xs:selector xpath="users/user"/>
|
<xs:selector xpath="users/user"/>
|
||||||
@@ -28,7 +25,7 @@
|
|||||||
<xs:element name="tls" type="gbcs:tlsType" minOccurs="0" maxOccurs="1"/>
|
<xs:element name="tls" type="gbcs:tlsType" minOccurs="0" maxOccurs="1"/>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
<xs:attribute name="path" type="xs:string" use="optional"/>
|
<xs:attribute name="path" type="xs:string" use="optional"/>
|
||||||
<xs:attribute name="useVirtualThreads" type="xs:boolean" use="optional"/>
|
<xs:attribute name="useVirtualThreads" type="xs:boolean" use="optional" default="true"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
||||||
<xs:complexType name="bindType">
|
<xs:complexType name="bindType">
|
||||||
|
@@ -105,4 +105,28 @@ class NoAuthServerTest : AbstractServerTest() {
|
|||||||
val response: HttpResponse<ByteArray> = client.send(requestBuilder.build(), HttpResponse.BodyHandlers.ofByteArray())
|
val response: HttpResponse<ByteArray> = client.send(requestBuilder.build(), HttpResponse.BodyHandlers.ofByteArray())
|
||||||
Assertions.assertEquals(HttpResponseStatus.NOT_FOUND.code(), response.statusCode())
|
Assertions.assertEquals(HttpResponseStatus.NOT_FOUND.code(), response.statusCode())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
// @Order(4)
|
||||||
|
// fun manyRequestsTest() {
|
||||||
|
// val client: HttpClient = HttpClient.newHttpClient()
|
||||||
|
//
|
||||||
|
// for(i in 0 until 100000) {
|
||||||
|
//
|
||||||
|
// val newEntry = random.nextBoolean()
|
||||||
|
// val (key, _) = if(newEntry) {
|
||||||
|
// newEntry(random)
|
||||||
|
// } else {
|
||||||
|
// keyValuePair
|
||||||
|
// }
|
||||||
|
// val requestBuilder = newRequestBuilder(key).GET()
|
||||||
|
//
|
||||||
|
// val response: HttpResponse<ByteArray> = client.send(requestBuilder.build(), HttpResponse.BodyHandlers.ofByteArray())
|
||||||
|
// if(newEntry) {
|
||||||
|
// Assertions.assertEquals(HttpResponseStatus.NOT_FOUND.code(), response.statusCode())
|
||||||
|
// } else {
|
||||||
|
// Assertions.assertEquals(HttpResponseStatus.OK.code(), response.statusCode())
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
21
src/test/resources/logback.xml
Normal file
21
src/test/resources/logback.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE configuration>
|
||||||
|
|
||||||
|
<configuration>
|
||||||
|
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
|
||||||
|
<import class="ch.qos.logback.core.ConsoleAppender"/>
|
||||||
|
|
||||||
|
<appender name="console" class="ConsoleAppender">
|
||||||
|
<target>System.err</target>
|
||||||
|
<encoder class="PatternLayoutEncoder">
|
||||||
|
<pattern>%d [%highlight(%-5level)] \(%thread\) %logger{36} -%kvp- %msg %n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="console"/>
|
||||||
|
</root>
|
||||||
|
<logger name="io.netty" level="debug"/>
|
||||||
|
<logger name="com.google.code.yanf4j" level="warn"/>
|
||||||
|
<logger name="net.rubyeye.xmemcached" level="warn"/>
|
||||||
|
</configuration>
|
Reference in New Issue
Block a user