-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
138 lines (117 loc) · 4.35 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
// Defined in the root `gradle.properties` file
val ktor_version: String by project
val kotlin_version: String by project
val logback_version: String by project
val kmongo_version: String by project
val koin_version: String by project
plugins {
application
kotlin("jvm") version "1.7.0"
id("org.jetbrains.kotlin.plugin.serialization") version "1.7.0"
id("com.github.johnrengelman.shadow") version "5.2.0" // generates a fat jar
}
group = "com.realityexpander"
version = "0.0.1"
application {
mainClass.set("io.ktor.server.netty.EngineMain")
project.setProperty("mainClassName", mainClass.get()) // used by the shadow plugin
}
repositories {
mavenCentral()
gradlePluginPortal() // for the shadow plugin
}
val sshAntTask = configurations.create("sshAntTask")
dependencies {
println("Kotlin version: $kotlin_version")
println("Ktor version: $ktor_version")
println("Logback version: $logback_version")
println("KMongo version: $kmongo_version")
println("Koin version: $koin_version")
implementation("io.ktor:ktor-server-core:$ktor_version")
implementation("io.ktor:ktor-websockets:$ktor_version")
implementation("io.ktor:ktor-serialization:$ktor_version")
implementation("io.ktor:ktor-server-sessions:$ktor_version")
implementation("io.ktor:ktor-server-netty:$ktor_version")
implementation("ch.qos.logback:logback-classic:$logback_version")
testImplementation("io.ktor:ktor-server-tests:$ktor_version")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
// KMongo
implementation("org.litote.kmongo:kmongo:$kmongo_version")
implementation("org.litote.kmongo:kmongo-coroutine:$kmongo_version")
// Koin core features
implementation("io.insert-koin:koin-core:$koin_version")
implementation("io.insert-koin:koin-ktor:$koin_version")
implementation("io.insert-koin:koin-logger-slf4j:$koin_version")
sshAntTask("org.apache.ant:ant-jsch:1.9.2")
}
tasks.withType<ShadowJar> {
manifest {
attributes(
"Main-Class" to application.mainClass.get()
)
}
}
ant.withGroovyBuilder {
"taskdef"(
"name" to "scp",
"classname" to "org.apache.tools.ant.taskdefs.optional.ssh.Scp",
"classpath" to configurations.get("sshAntTask").asPath
)
"taskdef"(
"name" to "ssh",
"classname" to "org.apache.tools.ant.taskdefs.optional.ssh.SSHExec",
"classpath" to configurations.get("sshAntTask").asPath
)
}
task("deploy") {
dependsOn("clean", "shadowJar")
ant.withGroovyBuilder {
doLast {
val knownHosts = File.createTempFile("knownhosts", "txt")
val user = "root"
val host = "82.180.173.232"
val pk = file("keys/hostinger_rsa")
val jarFileName = "com.realityexpander.ktor-chat-$version-all.jar"
try {
// Copy the jar file to the server
"scp"(
"file" to file("build/libs/$jarFileName"),
"todir" to "$user@$host:/root/chat",
"keyfile" to pk,
"trust" to true,
"knownhosts" to knownHosts
)
// Rename the jar file
"ssh"(
"host" to host,
"username" to user,
"keyfile" to pk,
"trust" to true,
"knownhosts" to knownHosts,
"command" to "mv /root/chat/$jarFileName /root/chat/chat-server.jar"
)
// Stop the current chat server
"ssh"(
"host" to host,
"username" to user,
"keyfile" to pk,
"trust" to true,
"knownhosts" to knownHosts,
"command" to "systemctl stop chat"
)
// Start the new chat server
"ssh"(
"host" to host,
"username" to user,
"keyfile" to pk,
"trust" to true,
"knownhosts" to knownHosts,
"command" to "systemctl start chat"
)
} finally {
knownHosts.delete()
}
}
}
}