add backend publication ext
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import ru.shadowsparky.setupBackendPublication
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.convention.backend.app)
|
alias(libs.plugins.convention.backend.app)
|
||||||
alias(libs.plugins.ktor)
|
alias(libs.plugins.ktor)
|
||||||
@@ -60,43 +62,9 @@ application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ktor {
|
ktor {
|
||||||
fatJar {
|
docker {
|
||||||
archiveFileName.set("server-fat.jar")
|
localImageName = "giga-wear-backend"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
setupBackendPublication()
|
||||||
named("build") {
|
|
||||||
dependsOn("buildFatJar")
|
|
||||||
}
|
|
||||||
register<Exec>("deployRemote") {
|
|
||||||
dependsOn("buildFatJar")
|
|
||||||
commandLine(
|
|
||||||
getCommandLine(
|
|
||||||
"docker context use remote",
|
|
||||||
"docker build . -t gigawear-server",
|
|
||||||
"docker context use default"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
notCompatibleWithConfigurationCache("This task uses Exec which is not compatible with configuration cache")
|
|
||||||
}
|
|
||||||
register<Exec>("deployLocal") {
|
|
||||||
dependsOn("buildFatJar")
|
|
||||||
commandLine(
|
|
||||||
getCommandLine(
|
|
||||||
"docker compose down",
|
|
||||||
"docker compose up -d --build --force-recreate"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
notCompatibleWithConfigurationCache("This task uses Exec which is not compatible with configuration cache")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getCommandLine(vararg commands: String): List<String> {
|
|
||||||
val osName = System.getProperty("os.name").lowercase()
|
|
||||||
return if (osName.contains("win")) {
|
|
||||||
listOf("cmd", "/c") + commands.joinToString(" && ")
|
|
||||||
} else {
|
|
||||||
listOf("sh", "-c") + commands.joinToString(" && ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package ru.shadowsparky
|
||||||
|
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.tasks.Exec
|
||||||
|
import org.gradle.kotlin.dsl.invoke
|
||||||
|
|
||||||
|
fun Project.setupBackendPublication() {
|
||||||
|
val switchToRemoteContext = tasks.register("switchToRemoteContext", Exec::class.java) {
|
||||||
|
group = "publishing"
|
||||||
|
description = "Переключает Docker-контекст на remote"
|
||||||
|
commandLine("docker", "context", "use", "remote")
|
||||||
|
}
|
||||||
|
val switchToDefaultContext = tasks.register("switchToDefaultContext",Exec::class.java) {
|
||||||
|
group = "publishing"
|
||||||
|
description = "Возвращает Docker-контекст на default"
|
||||||
|
commandLine("docker", "context", "use", "default")
|
||||||
|
}
|
||||||
|
tasks.register("publishImageRemote") {
|
||||||
|
group = "publishing"
|
||||||
|
description = "Публикует Docker image через remote context"
|
||||||
|
dependsOn(
|
||||||
|
switchToRemoteContext,
|
||||||
|
"publishImageToLocalRegistry"
|
||||||
|
)
|
||||||
|
finalizedBy(switchToDefaultContext)
|
||||||
|
}
|
||||||
|
tasks.register("publishImageLocal") {
|
||||||
|
group = "publishing"
|
||||||
|
description = "Публикует Docker image"
|
||||||
|
dependsOn("publishImageToLocalRegistry")
|
||||||
|
}
|
||||||
|
tasks.named("publishImageToLocalRegistry") {
|
||||||
|
mustRunAfter(switchToRemoteContext)
|
||||||
|
}
|
||||||
|
switchToDefaultContext {
|
||||||
|
mustRunAfter("publishImageToLocalRegistry")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user