258 lines
6.8 KiB
Groovy
258 lines
6.8 KiB
Groovy
/*
|
|
* mxisd - Matrix Identity Server Daemon
|
|
* Copyright (C) 2017 Maxime Dor
|
|
*
|
|
* https://max.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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
import java.util.regex.Pattern
|
|
|
|
apply plugin: 'java'
|
|
apply plugin: 'org.springframework.boot'
|
|
|
|
def confFileName = "application.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 = "mxisd-sample.yaml"
|
|
|
|
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}:${gitVersion()}"
|
|
|
|
String gitVersion() {
|
|
def versionPattern = Pattern.compile("v(\\d+\\.)?(\\d+\\.)?(\\d+)(-.*)?")
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream()
|
|
exec {
|
|
commandLine = ['git', 'describe', '--tags', '--always', '--dirty']
|
|
standardOutput = out
|
|
}
|
|
def v = out.toString().replace(System.lineSeparator(), '')
|
|
return versionPattern.matcher(v).matches() ? v.substring(1) : v
|
|
}
|
|
|
|
buildscript {
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
|
|
dependencies {
|
|
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.3.RELEASE'
|
|
}
|
|
}
|
|
|
|
repositories {
|
|
maven { url "https://kamax.io/maven/releases/" }
|
|
mavenCentral()
|
|
}
|
|
|
|
dependencies {
|
|
// Easy file management
|
|
compile 'commons-io:commons-io:2.5'
|
|
|
|
// Spring Boot - standalone app
|
|
compile 'org.springframework.boot:spring-boot-starter-web:1.5.10.RELEASE'
|
|
|
|
// Thymeleaf for HTML templates
|
|
compile "org.springframework.boot:spring-boot-starter-thymeleaf:1.5.10.RELEASE"
|
|
|
|
// Matrix Java SDK
|
|
compile 'io.kamax:matrix-java-sdk:0.0.8'
|
|
|
|
// 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'
|
|
|
|
// JSON
|
|
compile 'com.google.code.gson:gson:2.8.1'
|
|
|
|
// Phone numbers validation
|
|
compile 'com.googlecode.libphonenumber:libphonenumber:8.7.1'
|
|
|
|
// E-mail sending
|
|
compile 'com.sun.mail:javax.mail:1.5.6'
|
|
compile 'javax.mail:javax.mail-api:1.5.6'
|
|
|
|
// Google Firebase Authentication backend
|
|
compile 'com.google.firebase:firebase-admin:5.3.0'
|
|
|
|
// ORMLite
|
|
compile 'com.j256.ormlite:ormlite-jdbc:5.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.1.4'
|
|
|
|
// 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'
|
|
|
|
testCompile 'junit:junit:4.12'
|
|
testCompile 'com.github.tomakehurst:wiremock:2.8.0'
|
|
}
|
|
|
|
springBoot {
|
|
executable = true
|
|
|
|
embeddedLaunchScriptProperties = [
|
|
confFolder: "/etc/default"
|
|
]
|
|
}
|
|
|
|
processResources {
|
|
doLast {
|
|
copy {
|
|
from('build/resources/main/application.yaml') {
|
|
rename 'application.yaml', 'mxisd.yaml'
|
|
}
|
|
into 'build/resources/main'
|
|
}
|
|
}
|
|
}
|
|
|
|
task buildDeb(dependsOn: build) {
|
|
doLast {
|
|
def v = gitVersion()
|
|
println "Version for package: ${v}"
|
|
mkdir distDir
|
|
mkdir debBuildBasePath
|
|
mkdir "${debBuildBasePath}/DEBIAN"
|
|
mkdir debBuildBinPath
|
|
mkdir debBuildConfPath
|
|
mkdir debBuildDataPath
|
|
mkdir debBuildSystemdPath
|
|
|
|
copy {
|
|
from "${project.buildDir}/libs/mxisd.jar"
|
|
into debBuildBinPath
|
|
}
|
|
|
|
ant.chmod(
|
|
file: "${debBuildBinPath}/mxisd.jar",
|
|
perm: 'a+x'
|
|
)
|
|
|
|
copy {
|
|
from(project.file(confFileName)) {
|
|
rename confFileName, debConfFileName
|
|
}
|
|
into debBuildConfPath
|
|
}
|
|
|
|
ant.replaceregexp(
|
|
file: "${debBuildConfPath}/${debConfFileName}",
|
|
match: "key.path:(.*)",
|
|
replace: "key.path: '${debDataPath}/signing.key'"
|
|
)
|
|
|
|
ant.replaceregexp(
|
|
file: "${debBuildConfPath}/${debConfFileName}",
|
|
match: "storage.provider.sqlite.database:(.*)",
|
|
replace: "storage.provider.sqlite.database: '${debDataPath}/mxisd.db'"
|
|
)
|
|
|
|
copy {
|
|
from project.file('src/debian')
|
|
into debBuildDebianPath
|
|
}
|
|
|
|
ant.replace(
|
|
file: "${debBuildDebianPath}/control",
|
|
token: 'Version: 0',
|
|
value: "Version: ${v}"
|
|
)
|
|
|
|
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: build) {
|
|
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"
|
|
}
|
|
}
|
|
}
|