Compare commits
2 Commits
72d86051f6
...
d2c00402df
Author | SHA1 | Date | |
---|---|---|---|
d2c00402df
|
|||
d701157b06
|
@@ -5,6 +5,8 @@ on:
|
|||||||
- '*'
|
- '*'
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
env:
|
||||||
|
RUNNER_TOOL_CACHE: /toolcache
|
||||||
runs-on: hostinger
|
runs-on: hostinger
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
@@ -19,7 +21,11 @@ jobs:
|
|||||||
- name: Execute Gradle build
|
- name: Execute Gradle build
|
||||||
env:
|
env:
|
||||||
PUBLISHER_TOKEN: ${{ secrets.PUBLISHER_TOKEN }}
|
PUBLISHER_TOKEN: ${{ secrets.PUBLISHER_TOKEN }}
|
||||||
run: ./gradlew build publish
|
run: ./gradlew build
|
||||||
|
- name: Publish artifacts
|
||||||
|
env:
|
||||||
|
PUBLISHER_TOKEN: ${{ secrets.PUBLISHER_TOKEN }}
|
||||||
|
run: ./gradlew publish
|
||||||
build-docker:
|
build-docker:
|
||||||
name: "Build Docker images"
|
name: "Build Docker images"
|
||||||
runs-on: hostinger
|
runs-on: hostinger
|
||||||
|
@@ -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
|
||||||
|
23
build.gradle
23
build.gradle
@@ -10,16 +10,16 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||||
|
|
||||||
|
|
||||||
allprojects {
|
allprojects { subproject ->
|
||||||
group = 'net.woggioni'
|
group = 'net.woggioni'
|
||||||
|
|
||||||
if(project.currentTag.isPresent()) {
|
if(project.currentTag.isPresent()) {
|
||||||
version = project.currentTag
|
version = project.currentTag.map { it[0] }.get()
|
||||||
} else {
|
} else {
|
||||||
version = project.gitRevision.map { gitRevision ->
|
version = project.gitRevision.map { gitRevision ->
|
||||||
"${getProperty('gbcs.version')}.${gitRevision[0..10]}"
|
"${getProperty('gbcs.version')}.${gitRevision[0..10]}"
|
||||||
|
}.get()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
@@ -36,7 +36,7 @@ allprojects {
|
|||||||
pluginManager.withPlugin('java-library') {
|
pluginManager.withPlugin('java-library') {
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
jpmsModuleName = project.group + '.' + project.name.replace('-', '.')
|
jpmsModuleName = subproject.group + '.' + subproject.name.replace('-', '.')
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
@@ -61,14 +61,13 @@ allprojects {
|
|||||||
options.compilerArgumentProviders << new CommandLineArgumentProvider() {
|
options.compilerArgumentProviders << new CommandLineArgumentProvider() {
|
||||||
@Override
|
@Override
|
||||||
Iterable<String> asArguments() {
|
Iterable<String> asArguments() {
|
||||||
return ['--patch-module', project.jpmsModuleName + '=' + project.sourceSets.main.output.asPath]
|
return ['--patch-module', subproject.jpmsModuleName + '=' + subproject.sourceSets.main.output.asPath]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
options.javaModuleVersion = version
|
options.javaModuleVersion = version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pluginManager.withPlugin(catalog.plugins.kotlin.jvm.get().pluginId) {
|
pluginManager.withPlugin(catalog.plugins.kotlin.jvm.get().pluginId) {
|
||||||
tasks.withType(KotlinCompile.class) {
|
tasks.withType(KotlinCompile.class) {
|
||||||
compilerOptions.jvmTarget = JvmTarget.JVM_21
|
compilerOptions.jvmTarget = JvmTarget.JVM_21
|
||||||
@@ -101,10 +100,6 @@ allprojects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(AbstractArchiveTask.class) {
|
|
||||||
archiveVersion = project.version
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@@ -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">
|
||||||
|
@@ -7,10 +7,6 @@ plugins {
|
|||||||
dependencies {
|
dependencies {
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named(JavaPlugin.COMPILE_JAVA_TASK_NAME, JavaCompile) {
|
|
||||||
options.javaModuleVersion = version
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
maven(MavenPublication) {
|
maven(MavenPublication) {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package net.woggioni.gbcs.api;
|
package net.woggioni.gbcs.api;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@@ -23,25 +24,18 @@ public class Configuration {
|
|||||||
|
|
||||||
@Value
|
@Value
|
||||||
public static class Group {
|
public static class Group {
|
||||||
|
@EqualsAndHashCode.Include
|
||||||
String name;
|
String name;
|
||||||
Set<Role> roles;
|
Set<Role> roles;
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return name.hashCode();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value
|
@Value
|
||||||
public static class User {
|
public static class User {
|
||||||
|
@EqualsAndHashCode.Include
|
||||||
String name;
|
String name;
|
||||||
String password;
|
String password;
|
||||||
Set<Group> groups;
|
Set<Group> groups;
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return name.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Role> getRoles() {
|
public Set<Role> getRoles() {
|
||||||
return groups.stream()
|
return groups.stream()
|
||||||
|
@@ -1,5 +1,3 @@
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'java-library'
|
id 'java-library'
|
||||||
@@ -12,15 +10,6 @@ dependencies {
|
|||||||
compileOnly catalog.slf4j.api
|
compileOnly catalog.slf4j.api
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named(JavaPlugin.COMPILE_JAVA_TASK_NAME, JavaCompile) {
|
|
||||||
options.compilerArgs << '--patch-module' << 'net.woggioni.gbcs.base=' + project.sourceSets.main.output.asPath
|
|
||||||
options.javaModuleVersion = version
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.named("compileKotlin", KotlinCompile.class) {
|
|
||||||
compilerOptions.jvmTarget = JvmTarget.JVM_21
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
maven(MavenPublication) {
|
maven(MavenPublication) {
|
||||||
|
@@ -18,8 +18,6 @@ Property<String> mainClassName = objects.property(String.class)
|
|||||||
mainClassName.set('net.woggioni.gbcs.cli.GradleBuildCacheServerCli')
|
mainClassName.set('net.woggioni.gbcs.cli.GradleBuildCacheServerCli')
|
||||||
|
|
||||||
tasks.named(JavaPlugin.COMPILE_JAVA_TASK_NAME, JavaCompile) {
|
tasks.named(JavaPlugin.COMPILE_JAVA_TASK_NAME, JavaCompile) {
|
||||||
options.compilerArgs << '--patch-module' << 'net.woggioni.gbcs.cli=' + project.sourceSets.main.output.asPath
|
|
||||||
options.javaModuleVersion = version
|
|
||||||
options.javaModuleMainClass = mainClassName
|
options.javaModuleMainClass = mainClassName
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,8 +34,6 @@ dependencies {
|
|||||||
implementation catalog.netty.codec.http
|
implementation catalog.netty.codec.http
|
||||||
implementation catalog.picocli
|
implementation catalog.picocli
|
||||||
|
|
||||||
// implementation project(':gbcs-base')
|
|
||||||
// implementation project(':gbcs-api')
|
|
||||||
implementation rootProject
|
implementation rootProject
|
||||||
|
|
||||||
// runtimeOnly catalog.slf4j.jdk14
|
// runtimeOnly catalog.slf4j.jdk14
|
||||||
@@ -50,11 +46,6 @@ Provider<EnvelopeJarTask> envelopeJarTaskProvider = tasks.named('envelopeJar', E
|
|||||||
systemProperties['logback.configurationFile'] = 'classpath:net/woggioni/gbcs/cli/logback.xml'
|
systemProperties['logback.configurationFile'] = 'classpath:net/woggioni/gbcs/cli/logback.xml'
|
||||||
}
|
}
|
||||||
|
|
||||||
def envelopeJarArtifact = artifacts.add('archives', envelopeJarTaskProvider.get().archiveFile.get().asFile) {
|
|
||||||
type = 'jar'
|
|
||||||
builtBy envelopeJarTaskProvider
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.named(NativeImagePlugin.CONFIGURE_NATIVE_IMAGE_TASK_NAME, NativeImageConfigurationTask) {
|
tasks.named(NativeImagePlugin.CONFIGURE_NATIVE_IMAGE_TASK_NAME, NativeImageConfigurationTask) {
|
||||||
mainClass = 'net.woggioni.gbcs.GraalNativeImageConfiguration'
|
mainClass = 'net.woggioni.gbcs.GraalNativeImageConfiguration'
|
||||||
}
|
}
|
||||||
@@ -68,7 +59,7 @@ tasks.named(NativeImagePlugin.NATIVE_IMAGE_TASK_NAME, NativeImageTask) {
|
|||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
maven(MavenPublication) {
|
maven(MavenPublication) {
|
||||||
artifact envelopeJarArtifact
|
artifact envelopeJar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -30,15 +30,6 @@ dependencies {
|
|||||||
implementation catalog.xmemcached
|
implementation catalog.xmemcached
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named(JavaPlugin.COMPILE_JAVA_TASK_NAME, JavaCompile) {
|
|
||||||
options.compilerArgs << '--patch-module' << 'net.woggioni.gbcs.memcached=' + project.sourceSets.main.output.asPath
|
|
||||||
options.javaModuleVersion = version
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.named("compileKotlin", KotlinCompile.class) {
|
|
||||||
compilerOptions.jvmTarget = JvmTarget.JVM_21
|
|
||||||
}
|
|
||||||
|
|
||||||
Provider<Tar> bundleTask = tasks.register("bundle", Tar) {
|
Provider<Tar> bundleTask = tasks.register("bundle", Tar) {
|
||||||
from(tasks.named(JavaPlugin.JAR_TASK_NAME))
|
from(tasks.named(JavaPlugin.JAR_TASK_NAME))
|
||||||
from(configurations.bundle)
|
from(configurations.bundle)
|
||||||
@@ -49,16 +40,10 @@ tasks.named(BasePlugin.ASSEMBLE_TASK_NAME) {
|
|||||||
dependsOn(bundleTask)
|
dependsOn(bundleTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
def bundleArtifact = artifacts.add('archives', bundleTask.get().archiveFile.get().asFile) {
|
|
||||||
type = 'tar'
|
|
||||||
builtBy bundleTask
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
maven(MavenPublication) {
|
maven(MavenPublication) {
|
||||||
artifact bundleArtifact
|
artifact bundleTask
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -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
|
||||||
@@ -34,8 +33,6 @@ import io.netty.handler.codec.http.HttpServerCodec
|
|||||||
import io.netty.handler.codec.http.HttpUtil
|
import io.netty.handler.codec.http.HttpUtil
|
||||||
import io.netty.handler.codec.http.HttpVersion
|
import io.netty.handler.codec.http.HttpVersion
|
||||||
import io.netty.handler.codec.http.LastHttpContent
|
import io.netty.handler.codec.http.LastHttpContent
|
||||||
import io.netty.handler.ssl.ApplicationProtocolNames
|
|
||||||
import io.netty.handler.ssl.ApplicationProtocolNegotiationHandler
|
|
||||||
import io.netty.handler.ssl.ClientAuth
|
import io.netty.handler.ssl.ClientAuth
|
||||||
import io.netty.handler.ssl.SslContext
|
import io.netty.handler.ssl.SslContext
|
||||||
import io.netty.handler.ssl.SslContextBuilder
|
import io.netty.handler.ssl.SslContextBuilder
|
||||||
@@ -71,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
|
||||||
@@ -180,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)
|
||||||
@@ -237,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)
|
||||||
@@ -296,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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -447,46 +444,47 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ServerHandle(
|
class ServerHandle(
|
||||||
private val httpChannel: 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 closeFuture: ChannelFuture = httpChannel.channel().closeFuture()
|
private val closeFuture: ChannelFuture = httpChannel.closeFuture()
|
||||||
|
|
||||||
fun shutdown(): ChannelFuture {
|
fun shutdown(): ChannelFuture {
|
||||||
return httpChannel.channel().close()
|
return httpChannel.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
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()
|
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) {
|
||||||
NioEventLoopGroup(0, Executors.newWorkStealingPool())
|
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)
|
||||||
}
|
}
|
||||||
@@ -495,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 {
|
||||||
@@ -509,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">
|
||||||
|
@@ -1,19 +1,30 @@
|
|||||||
package net.woggioni.gbcs.utils;
|
package net.woggioni.gbcs.utils;
|
||||||
|
|
||||||
|
import net.woggioni.jwo.JWO;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
|
|
||||||
public class NetworkUtils {
|
public class NetworkUtils {
|
||||||
|
|
||||||
|
private static final int MAX_ATTEMPTS = 50;
|
||||||
|
|
||||||
public static int getFreePort() {
|
public static int getFreePort() {
|
||||||
while(true) {
|
int count = 0;
|
||||||
try (ServerSocket serverSocket = new ServerSocket(0)) {
|
while(count < MAX_ATTEMPTS) {
|
||||||
|
try (ServerSocket serverSocket = new ServerSocket(0, 50, InetAddress.getLocalHost())) {
|
||||||
final var candidate = serverSocket.getLocalPort();
|
final var candidate = serverSocket.getLocalPort();
|
||||||
if (serverSocket.getLocalPort() > 0) {
|
if (candidate > 0) {
|
||||||
return candidate;
|
return candidate;
|
||||||
|
} else {
|
||||||
|
JWO.newThrowable(RuntimeException.class, "Got invalid port number: %d", candidate);
|
||||||
|
throw new RuntimeException("Error trying to find an open port");
|
||||||
}
|
}
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
throw new RuntimeException("Error trying to find an open port");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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())
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
@@ -228,7 +228,6 @@ class TlsServerTest : AbstractServerTest() {
|
|||||||
@Test
|
@Test
|
||||||
@Order(3)
|
@Order(3)
|
||||||
fun getAsAWriterUser() {
|
fun getAsAWriterUser() {
|
||||||
|
|
||||||
val (key, _) = keyValuePair
|
val (key, _) = keyValuePair
|
||||||
val user = cfg.users.values.find {
|
val user = cfg.users.values.find {
|
||||||
Role.Writer in it.roles
|
Role.Writer in it.roles
|
||||||
@@ -246,7 +245,6 @@ class TlsServerTest : AbstractServerTest() {
|
|||||||
@Test
|
@Test
|
||||||
@Order(4)
|
@Order(4)
|
||||||
fun putAsAWriterUser() {
|
fun putAsAWriterUser() {
|
||||||
|
|
||||||
val (key, value) = keyValuePair
|
val (key, value) = keyValuePair
|
||||||
val user = cfg.users.values.find {
|
val user = cfg.users.values.find {
|
||||||
Role.Writer in it.roles
|
Role.Writer in it.roles
|
||||||
|
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