-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.gradle
130 lines (116 loc) · 3.92 KB
/
build.gradle
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
plugins {
id("java")
id("com.github.johnrengelman.shadow") version "8.1.1"
}
group = "be.hokkaydo"
version = "1.0-SNAPSHOT"
var jsoupVersion = "1.18.3"
var jsonVersion = "20231013"
var JDAVersion = "5.2.1"
var dotenvVersion = "3.0.0"
var discordWebhooksVersion = "0.8.4"
var javaJwtVersion = "4.4.0"
var springJdbcVersion = "6.0.11"
var sqliteJdbcVersion = "3.42.0.0"
var githubApiVersion = "1.315"
var logbackClassicVersion = "1.5.6"
var romeVersion = "1.0"
repositories {
mavenCentral()
}
dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
implementation("net.dv8tion:JDA:${JDAVersion}")
// RSS helper
implementation("rome:rome:${romeVersion}")
// https://mvnrepository.com/artifact/org.json/json
implementation("org.json:json:${jsonVersion}")
implementation("io.github.cdimascio:dotenv-java:${dotenvVersion}")
implementation("club.minnced:discord-webhooks:${discordWebhooksVersion}")
implementation("com.auth0:java-jwt:${javaJwtVersion}")
implementation("org.springframework:spring-jdbc:${springJdbcVersion}")
implementation("org.xerial:sqlite-jdbc:${sqliteJdbcVersion}")
// https://mvnrepository.com/artifact/org.kohsuke/github-api
implementation ("org.kohsuke:github-api:${githubApiVersion}")
implementation("org.jsoup:jsoup:${jsoupVersion}")
implementation("ch.qos.logback:logback-classic:${logbackClassicVersion}")
}
jar {
manifest {
attributes["Main-Class"] = "com.github.hokkaydo.eplbot.Main"
}
}
tasks.register("buildLocal") {
group = "Docker"
description = "Builds the shadowJar locally and the Docker container."
dependsOn("shadowJar")
doLast {
providers.exec {
commandLine("docker", "build", "-t", "eplbot:latest", "--target", "local-build", "./")
}.result.get()
}
}
tasks.register("run") {
group = "Docker"
description = "Runs the Docker container."
doLast {
providers.exec {
commandLine("docker", "compose", "-f", "docker-compose.yml", "up", "eplbot", "--remove-orphans", "--force-recreate")
}.result.get()
}
}
tasks.register("buildAndRun") {
group = "Docker"
description = "Builds the shadowJar locally, builds the Docker image, and runs the Docker container."
dependsOn("buildLocal")
finalizedBy("run")
}
tasks.register("pushMain") {
group = "Docker"
description = "Pushes the Docker image to the Docker Hub."
dependsOn("buildLocal")
doLast {
providers.exec {
commandLine("docker", "image", "tag", "eplbot:latest", "hokkaydo/eplbot:latest")
commandLine("docker", "image", "push", "hokkaydo/eplbot:latest")
}.result.get()
}
}
tasks.register("buildRunners") {
group = "Docker"
description = "Builds and tags code runner containers"
doLast {
providers.exec {
commandLine("bash", "-c", """
LIST=\$(ls -d src/main/java/com/github/hokkaydo/eplbot/module/code/*/)
for dir in \$LIST
do
DIRNAME=\$(basename \$dir)
if [ "\$DIRNAME" == "command" ]; then
continue
fi
docker build -t hokkaydo/\$DIRNAME-runner -f \$dir/Dockerfile .
done
""".trim())
}.result.get()
}
}
tasks.register("pushRunners") {
group = "Docker"
description = "Pushes the Docker image to the Docker Hub."
doLast {
providers.exec {
commandLine(
"bash", "-c",
"docker images | grep -E '^[A-Za-z]*-runner' | awk '{print \\\$1}' | xargs -I {} docker image push {}:latest"
)
}.result.get()
}
}
tasks.register("buildPushRunners") {
group = "Docker"
description = "Builds and push code runner containers"
dependsOn("buildRunners")
finalizedBy("pushRunners")
}