All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ai.digital.integration.server.common.util.DockerComposeUtil.kt Maven / Gradle / Ivy

There is a newer version: 23.3.0-1025.941
Show newest version
package ai.digital.integration.server.common.util

import ai.digital.integration.server.common.constant.ProductName
import ai.digital.integration.server.common.domain.Server
import org.gradle.api.Project
import java.io.File
import java.nio.file.Path

class DockerComposeUtil {
    companion object {
        fun getResolvedDockerPath(project: Project, relativePath: String): Path {
            val dockerComposeStream = {}::class.java.classLoader.getResourceAsStream(relativePath)
            val resultComposeFilePath =
                IntegrationServerUtil.getRelativePathInIntegrationServerDist(project, relativePath)
            dockerComposeStream?.let {
                FileUtil.copyFile(it, resultComposeFilePath)
            }
            return resultComposeFilePath
        }

        fun execute(project: Project, args: List, logOutput: Boolean = true): String {
            return ProcessUtil.execute(project, "docker-compose", args, logOutput)
        }

        fun allowToCleanMountedFiles(
                project: Project,
                productName: ProductName,
                server: Server,
                dockerComposeFile: File
        ) {
            val name = productName.toString().lowercase()
            try {
                val args = arrayListOf("-f",
                        dockerComposeFile.path,
                        "exec",
                        "-T",
                        "${name}-${server.version}",
                        "chmod",
                        "777",
                        "-R",
                        "/opt/xebialabs/xl-${name}-server")
                execute(project, args, false)
            } catch (e: Exception) {
                // ignore, if throws exception, it means that docker container is not running
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy