/* * mxids - Matrix Identity Server * Copyright (C) 2017 Kamax Sarl * * https://www.kamax.io/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ import java.util.regex.Pattern apply plugin: 'java-library' apply plugin: 'application' apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'idea' apply plugin: 'com.github.ben-manes.versions' def confFileName = "mxids.example.yaml" def distDir = "${project.buildDir}/dist" def debBinPath = "/usr/lib/mxids" def debConfPath = "/etc/mxids" def debDataPath = "/var/lib/mxids" def debSystemdPath = "/etc/systemd/system" def debConfFileName = confFileName def debStartScriptFilename = "mxids" def debBuildBasePath = "${project.buildDir}/tmp/debian" def debBuildDebianPath = "${debBuildBasePath}/DEBIAN" def debBuildBinPath = "${debBuildBasePath}${debBinPath}" def debBuildConfPath = "${debBuildBasePath}${debConfPath}" def debBuildDataPath = "${debBuildBasePath}${debDataPath}" def debBuildSystemdPath = "${debBuildBasePath}${debSystemdPath}" def dockerImageName = "cqrenet/mxids" def dockerImageTag = "${dockerImageName}:${mxidsVersion()}" group = 'io.kamax' mainClassName = 'io.kamax.mxisd.MxisdStandaloneExec' sourceCompatibility = '11' targetCompatibility = '11' String mxidsVersion() { def versionPattern = Pattern.compile("v(\\d+\\.)?(\\d+\\.)?(\\d+)(-.*)?") String version = System.getenv('MXIDS_BUILD_VERSION') if (version == null || version.size() == 0) { version = gitVersion() } return versionPattern.matcher(version).matches() ? version.substring(1) : version } String gitVersion() { ByteArrayOutputStream out = new ByteArrayOutputStream() exec { commandLine = ['git', 'describe', '--tags', '--always', '--dirty'] standardOutput = out } return out.toString().replace(System.lineSeparator(), '') } buildscript { repositories { gradlePluginPortal() mavenCentral() google() } dependencies { classpath 'com.github.johnrengelman:shadow:8.1.1' classpath 'com.github.ben-manes:gradle-versions-plugin:0.52.0' } } repositories { mavenCentral() } dependencies { // Logging api 'org.slf4j:slf4j-simple:2.0.13' // Easy file management api 'commons-io:commons-io:2.20.0' // Config management api 'org.yaml:snakeyaml:1.33' // Dependencies from old Matrix-java-sdk api 'org.apache.commons:commons-lang3:3.18.0' api 'com.squareup.okhttp3:okhttp:4.12.0' api 'commons-codec:commons-codec:1.19.0' // ORMLite api 'com.j256.ormlite:ormlite-jdbc:6.1' // ed25519 handling api 'net.i2p.crypto:eddsa:0.3.0' // LDAP connector api 'org.apache.directory.api:api-all:2.1.7' // DNS lookups api 'dnsjava:dnsjava:3.6.3' // HTTP connections api 'org.apache.httpcomponents:httpclient:4.5.14' // Phone numbers validation api 'com.googlecode.libphonenumber:libphonenumber:8.13.36' // E-mail sending api 'javax.mail:javax.mail-api:1.6.2' api 'com.sun.mail:javax.mail:1.6.2' // Google Firebase Authentication backend api 'com.google.firebase:firebase-admin:9.2.0' // Connection Pool api 'com.mchange:c3p0:0.11.2' // SQLite api 'org.xerial:sqlite-jdbc:3.50.3.0' // PostgreSQL api 'org.postgresql:postgresql:42.7.7' // MariaDB/MySQL api 'org.mariadb.jdbc:mariadb-java-client:3.5.6' // UNIX sockets api 'com.kohlschutter.junixsocket:junixsocket-core:2.9.1' // Twilio SDK for SMS api 'com.twilio.sdk:twilio:10.9.2' // SendGrid SDK to send emails from GCE api 'com.sendgrid:sendgrid-java:4.10.2' // ZT-Exec for exec identity store api 'org.zeroturnaround:zt-exec:1.12' // HTTP server api 'io.undertow:undertow-core:2.3.13.Final' // Command parser for AS interface api 'commons-cli:commons-cli:1.7.0' testImplementation 'junit:junit:4.13.2' testImplementation 'com.github.tomakehurst:wiremock:3.0.1' testImplementation 'com.unboundid:unboundid-ldapsdk:7.0.0' testImplementation 'com.icegreen:greenmail:1.6.15' } jar { manifest { attributes( 'Implementation-Version': mxidsVersion() ) } } shadowJar { archiveBaseName.set(project.name) archiveClassifier.set('') // Set to an empty string if you don't need a classifier. archiveVersion.set('') // Set to an empty string if you don't want the version in the jar name. } task debBuild(dependsOn: shadowJar) { doLast { String debVersion = mxidsVersion() println "Version for package: ${debVersion}" mkdir distDir mkdir debBuildBasePath mkdir debBuildDebianPath mkdir debBuildBinPath mkdir debBuildConfPath mkdir debBuildDataPath mkdir debBuildSystemdPath copy { from "${project.buildDir}/libs/mxids.jar" into debBuildBinPath } copy { from "${project.file("src/script/" + debStartScriptFilename)}" into debBuildBinPath } copy { from(project.file(confFileName)) { rename confFileName, debConfFileName } into debBuildConfPath } ant.replaceregexp( // FIXME adapt to new config format file: "${debBuildConfPath}/${debConfFileName}", match: "key:\\R path:(.*)", replace: "key:\n path: '${debDataPath}/keys'" ) ant.replaceregexp( // FIXME adapt to new config format file: "${debBuildConfPath}/${debConfFileName}", match: "storage:\\R provider:\\R sqlite:\\R database:(.*)", replace: "storage:\n provider:\n sqlite:\n database: '${debDataPath}/store.db'" ) copy { from project.file('src/debian') into debBuildDebianPath } ant.replace( file: "${debBuildDebianPath}/control", token: 'Version: 0', value: "Version: ${debVersion}" ) ant.replace( file: "${debBuildDebianPath}/postinst", token: '%DEB_DATA_DIR%', value: debDataPath ) ant.replace( file: "${debBuildDebianPath}/postinst", token: '%DEB_CONF_FILE%', value: "${debConfPath}/mxids.yaml" ) ant.chmod( file: "${debBuildDebianPath}/postinst", perm: '0755' ) ant.chmod( file: "${debBuildDebianPath}/prerm", perm: 'a+x' ) copy { from "${project.file('src/systemd/mxids.service')}" into debBuildSystemdPath } exec { commandLine( 'fakeroot', 'dpkg-deb', '-b', debBuildBasePath, "${project.buildDir}/dist" ) } } } task dockerBuild(type: Exec) { commandLine 'docker', 'build', '-t', dockerImageTag, project.rootDir doLast { exec { commandLine 'docker', 'tag', dockerImageTag, "${dockerImageName}:latest-dev" } } } task dockerBuildX(type: Exec, dependsOn: shadowJar) { commandLine 'docker', 'buildx', 'build', '--push', '--platform', 'linux/arm64,linux/amd64,linux/arm/v7', '-t', dockerImageTag , project.rootDir doLast { exec { commandLine 'docker', 'buildx', 'build', '--push', '--platform', 'linux/arm64,linux/amd64,linux/arm/v7', '-t', "${dockerImageName}:latest-dev", project.rootDir } } } task dockerPush(type: Exec) { commandLine 'docker', 'push', dockerImageTag doLast { exec { commandLine 'docker', 'push', "${dockerImageName}:latest-dev" } } } task dockerPushX(type: Exec) { commandLine 'docker', 'push', dockerImageTag doLast { exec { commandLine 'docker', 'push', "${dockerImageName}:latest-dev" commandLine 'docker', 'push', "${dockerImageName}:latest-amd64-dev" commandLine 'docker', 'push', "${dockerImageName}:latest-arm64-dev" } } } tasks.named('assemble').configure { dependsOn shadowJar } tasks.withType(AbstractArchiveTask) { if (it.name == 'distZip' || it.name == 'distTar') { dependsOn shadowJar } } tasks.named('startScripts').configure { mustRunAfter shadowJar } tasks.named('startShadowScripts').configure { dependsOn jar }