-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
125 lines (105 loc) · 3.59 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
@file:Suppress("SuspiciousCollectionReassignment")
import com.github.lamba92.gradle.utils.TRAVIS_TAG
import com.github.lamba92.gradle.utils.lamba
import org.gradle.internal.os.OperatingSystem
import java.io.ByteArrayOutputStream
buildscript {
repositories {
maven("https://dl.bintray.com/lamba92/com.github.lamba92")
google()
}
dependencies {
classpath("com.github.lamba92", "lamba-gradle-utils", "1.0.6")
}
}
plugins {
kotlin("jvm") version "1.4-M1"
id("org.hidetake.ssh") version "2.10.1"
application
}
group = "com.github.lamba92"
version = TRAVIS_TAG ?: "0.0.1"
repositories {
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://dl.bintray.com/lamba92/com.github.lamba92")
maven("https://dl.bintray.com/kotlin/kotlinx.html")
jcenter()
mavenCentral()
maven("https://oss.sonatype.org/content/repositories/snapshots")
}
kotlin.target.compilations.all {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("org.telegram", "telegrambots", "4.4.0.1")
implementation(lamba("dragalia-library-kodein-di", "+"))
implementation(lamba("telegrambots-ktx", "+"))
implementation("com.vdurmont", "emoji-java", "5.1.1")
}
application {
mainClassName = "com.github.lamba92.dragalialost.bot.MainKt"
}
// Check OS first, if using Win10Home this exec can take a lot of time
// due to Docker Toolbox under VirtualBox cold start
val shouldSetupDocker = if (OperatingSystem.current().isLinux)
exec {
commandLine("docker")
standardOutput = ByteArrayOutputStream()
errorOutput = ByteArrayOutputStream()
}.exitValue == 0
else
false
if (shouldSetupDocker)
tasks {
val distTar by getting(Tar::class)
val dockerBuildFolder = file("$buildDir/dockerBuild").absolutePath
val copyDistTar by creating(Copy::class) {
dependsOn(distTar)
group = "docker"
from(distTar.archiveFile.get())
into(dockerBuildFolder)
}
val copyDockerfile by creating(Copy::class) {
group = "docker"
from("$projectDir/Dockerfile")
into(dockerBuildFolder)
}
fun commands(withVersion: Boolean = false, addArm32: Boolean = true) = arrayOf(
"docker", "buildx", "build", "-t",
buildString {
append("lamba92/${project.name}")
if (withVersion)
append(":${project.version}")
},
"--build-arg=TAR_NAME=${distTar.archiveFile.get().asFile.nameWithoutExtension}",
"--build-arg=APP_NAME=${project.name}",
buildString {
append("--platform=linux/amd64,linux/arm64")
if (addArm32)
append(",linux/arm")
},
dockerBuildFolder
)
val buildMultiArchImages by creating(Exec::class) {
dependsOn(copyDistTar, copyDockerfile)
group = "docker"
commandLine(*commands())
}
"build" {
dependsOn(buildMultiArchImages)
}
val publishMultiArchImagesWithLatestTag by creating(Exec::class) {
dependsOn(copyDistTar, copyDockerfile)
group = "docker"
commandLine(*commands(), "--push")
}
create<Exec>("publishMultiArchImages") {
dependsOn(publishMultiArchImagesWithLatestTag)
group = "docker"
commandLine(*commands(true), "--push")
}
}