/* * mxisd - Matrix Identity Server Daemon * 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' apply plugin: 'application' apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'idea' def confFileName = "mxisd.example.yaml" def distDir = "${project.buildDir}/dist" def debBinPath = "/usr/lib/mxisd" def debConfPath = "/etc/mxisd" def debDataPath = "/var/lib/mxisd" def debSystemdPath = "/etc/systemd/system" def debConfFileName = confFileName def debStartScriptFilename = "mxisd" 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 = "kamax/mxisd" def dockerImageTag = "${dockerImageName}:${mxisdVersion()}" group = 'io.kamax' mainClassName = 'io.kamax.mxisd.MxisdStandaloneExec' String mxisdVersion() { def versionPattern = Pattern.compile("v(\\d+\\.)?(\\d+\\.)?(\\d+)(-.*)?") String version = System.getenv('MXISD_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 { jcenter() } dependencies { classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.3' } } repositories { jcenter() maven { url "https://kamax.io/maven/releases/" } maven { url "https://kamax.io/maven/snapshots/" } } dependencies { // Logging compile 'org.slf4j:slf4j-simple:1.7.25' // Easy file management compile 'commons-io:commons-io:2.5' // Config management compile 'org.yaml:snakeyaml:1.23' // Matrix Java SDK compile 'io.kamax:matrix-java-sdk:0.0.14-8-g0e57ec6' // ORMLite compile 'com.j256.ormlite:ormlite-jdbc:5.0' // ed25519 handling compile 'net.i2p.crypto:eddsa:0.1.0' // LDAP connector compile 'org.apache.directory.api:api-all:1.0.0' // DNS lookups compile 'dnsjava:dnsjava:2.1.8' // HTTP connections compile 'org.apache.httpcomponents:httpclient:4.5.3' // Phone numbers validation compile 'com.googlecode.libphonenumber:libphonenumber:8.7.1' // E-mail sending compile 'javax.mail:javax.mail-api:1.6.2' compile 'com.sun.mail:javax.mail:1.6.2' // Google Firebase Authentication backend compile 'com.google.firebase:firebase-admin:5.3.0' // Connection Pool compile 'com.mchange:c3p0:0.9.5.2' // SQLite compile 'org.xerial:sqlite-jdbc:3.20.0' // PostgreSQL compile 'org.postgresql:postgresql:42.2.5' // MariaDB/MySQL compile 'org.mariadb.jdbc:mariadb-java-client:2.1.2' // Twilio SDK for SMS compile 'com.twilio.sdk:twilio:7.14.5' // SendGrid SDK to send emails from GCE compile 'com.sendgrid:sendgrid-java:2.2.2' // ZT-Exec for exec identity store compile 'org.zeroturnaround:zt-exec:1.10' // HTTP server compile 'io.undertow:undertow-core:2.0.16.Final' testCompile 'junit:junit:4.12' testCompile 'com.github.tomakehurst:wiremock:2.8.0' testCompile 'com.unboundid:unboundid-ldapsdk:4.0.9' testCompile 'com.icegreen:greenmail:1.5.9' } shadowJar { baseName = project.name classifier = null version = null } task debBuild(dependsOn: shadowJar) { doLast { String debVersion = mxisdVersion() println "Version for package: ${debVersion}" mkdir distDir mkdir debBuildBasePath mkdir debBuildDebianPath mkdir debBuildBinPath mkdir debBuildConfPath mkdir debBuildDataPath mkdir debBuildSystemdPath copy { from "${project.buildDir}/libs/mxisd.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}/signing.key'" ) 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}/mxisd.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.chmod( file: "${debBuildDebianPath}/postinst", perm: 'a+x' ) ant.chmod( file: "${debBuildDebianPath}/prerm", perm: 'a+x' ) copy { from "${project.file('src/systemd/mxisd.service')}" into debBuildSystemdPath } exec { commandLine( 'fakeroot', 'dpkg-deb', '-b', debBuildBasePath, "${project.buildDir}/dist" ) } } } task dockerBuild(type: Exec, dependsOn: shadowJar) { commandLine 'docker', 'build', '-t', dockerImageTag, project.rootDir doLast { exec { commandLine 'docker', 'tag', dockerImageTag, "${dockerImageName}:latest-dev" } } } task dockerPush(type: Exec) { commandLine 'docker', 'push', dockerImageTag doLast { exec { commandLine 'docker', 'push', "${dockerImageName}:latest-dev" } } }