diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index dac3e4e1a9..4d1ddfeba4 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -5,7 +5,7 @@ on: push: branches: - 'master' - + concurrency: # https://docs.github.com/en/actions/using-jobs/using-concurrency # The latest queued workflow is preferred; the ones already in progress get cancelled diff --git a/.github/workflows/deploy_images.yml b/.github/workflows/deploy_images.yml index aadf8eb1e6..1eadce315f 100644 --- a/.github/workflows/deploy_images.yml +++ b/.github/workflows/deploy_images.yml @@ -96,10 +96,10 @@ jobs: path: save fetch-depth: 0 submodules: true - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: 11 + java-version: 17 distribution: temurin - name: Install system packages # libcurl is needed for ktor-client-curl diff --git a/.github/workflows/detekt.yml b/.github/workflows/detekt.yml index d43c342a6e..122def56a9 100644 --- a/.github/workflows/detekt.yml +++ b/.github/workflows/detekt.yml @@ -14,10 +14,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: 11 + java-version: 17 distribution: temurin - uses: gradle/gradle-build-action@v2 with: diff --git a/.github/workflows/diktat.yml b/.github/workflows/diktat.yml index 249b3da757..acd4c3bb3a 100644 --- a/.github/workflows/diktat.yml +++ b/.github/workflows/diktat.yml @@ -14,10 +14,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: 11 + java-version: 17 distribution: temurin - uses: gradle/gradle-build-action@v2 with: diff --git a/.github/workflows/save-api-build.yml b/.github/workflows/save-api-build.yml index 6c106cf5e7..d554cc8715 100644 --- a/.github/workflows/save-api-build.yml +++ b/.github/workflows/save-api-build.yml @@ -13,10 +13,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: 11 + java-version: 17 distribution: temurin - name: Install system packages # libcurl is needed for ktor-client-curl, libc-bin for orchestrator diff --git a/gradle.properties b/gradle.properties index aa0e4312f1..4497732cdc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ liquibaseTaskPrefix=liquibase #build.docker.cert-path=C:\\Users\\\\.minikube\\certs # gradle performance -org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=512m +org.gradle.jvmargs=-Xmx4g -Xms3g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 org.gradle.parallel=true org.gradle.vfs.watch=true ## https://docs.gradle.org/current/userguide/multi_project_configuration_and_execution.html#sec:configuration_on_demand diff --git a/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/AgentConfiguration.kt b/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/AgentConfiguration.kt index 1d8f6bd506..a9c44550c5 100644 --- a/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/AgentConfiguration.kt +++ b/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/AgentConfiguration.kt @@ -9,6 +9,7 @@ import com.saveourtool.save.agent.utils.TEST_SUITES_DIR_NAME import com.saveourtool.save.core.config.LogType import com.saveourtool.save.core.config.OutputStreamType import com.saveourtool.save.core.config.ReportType +import com.saveourtool.save.utils.optionalEnv import com.saveourtool.save.utils.requiredEnv import generated.SAVE_CLOUD_VERSION @@ -26,6 +27,7 @@ import kotlinx.serialization.Serializable * @property testSuitesDir directory where tests and additional files need to be stored into * @property logFilePath path to logs of save-cli execution * @property save additional configuration for save-cli + * @property kubernetes a flag which shows that agent runs in k8s */ @Serializable data class AgentConfiguration( @@ -37,6 +39,7 @@ data class AgentConfiguration( val debug: Boolean = false, val testSuitesDir: String = TEST_SUITES_DIR_NAME, val logFilePath: String = "logs.txt", + val kubernetes: Boolean = false, val save: SaveCliConfig = SaveCliConfig(), ) { companion object { @@ -52,6 +55,7 @@ data class AgentConfiguration( heartbeat = HeartbeatConfig( url = requiredEnv(AgentEnvName.HEARTBEAT_URL.name), ), + kubernetes = optionalEnv(AgentEnvName.KUBERNETES.name).toBoolean(), ) } } diff --git a/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/Main.kt b/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/Main.kt index 8e68a588bb..0874f4f326 100644 --- a/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/Main.kt +++ b/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/Main.kt @@ -92,5 +92,7 @@ private fun configureHttpClient(agentConfiguration: AgentConfiguration) = HttpCl logger = ktorLogger level = if (agentConfiguration.debug) LogLevel.ALL else LogLevel.INFO } - install(KubernetesServiceAccountAuthHeaderPlugin) + if (agentConfiguration.kubernetes) { + install(KubernetesServiceAccountAuthHeaderPlugin) + } } diff --git a/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/agent/AgentEnvName.kt b/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/agent/AgentEnvName.kt index 611f16632f..b056491683 100644 --- a/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/agent/AgentEnvName.kt +++ b/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/agent/AgentEnvName.kt @@ -10,6 +10,7 @@ enum class AgentEnvName { DEBUG, EXECUTION_ID, HEARTBEAT_URL, + KUBERNETES, TEST_SUITES_DIR, ; } diff --git a/save-deploy/README.md b/save-deploy/README.md index 99504fe466..a32c051a56 100644 --- a/save-deploy/README.md +++ b/save-deploy/README.md @@ -221,7 +221,7 @@ two reasons: Under WSL, from a separate local _Git_ repository run: ```bash -./gradlew :save-agent:copyAgentDistribution -Preckon.stage=snapshot +./gradlew :save-agent:clean :save-agent:build :save-agent:copyAgentDistribution -x spotlessKotlin -Preckon.stage=snapshot -Psave.profile=dev ``` and provide the path to the JAR archive which contains `save-agent.kexe` via the diff --git a/save-orchestrator-common/src/main/kotlin/com/saveourtool/save/orchestrator/docker/DockerContainerRunner.kt b/save-orchestrator-common/src/main/kotlin/com/saveourtool/save/orchestrator/docker/DockerContainerRunner.kt index fb94d7a732..48028af105 100644 --- a/save-orchestrator-common/src/main/kotlin/com/saveourtool/save/orchestrator/docker/DockerContainerRunner.kt +++ b/save-orchestrator-common/src/main/kotlin/com/saveourtool/save/orchestrator/docker/DockerContainerRunner.kt @@ -80,7 +80,7 @@ class DockerContainerRunner( override fun isStopped(containerId: String): Boolean = dockerClient.inspectContainerCmd(containerId) .exec() .state - .also { log.debug("Container $containerId has state $it") } + .also { state -> log.debug { "Container $containerId has state $state" } } .status != RUNNING_STATUS override fun cleanupAllByExecution(executionId: Long) { @@ -113,7 +113,7 @@ class DockerContainerRunner( for (type in PruneType.values().filterNot { it == PruneType.VOLUMES }) { val pruneCmd = dockerClient.pruneCmd(type).withUntilFilter(configProperties.dockerResourcesLifetime).exec() val currentReclaimedBytes = pruneCmd.spaceReclaimed ?: 0 - log.debug("Reclaimed $currentReclaimedBytes bytes after prune of docker $type") + log.debug { "Reclaimed $currentReclaimedBytes bytes after prune of docker $type" } reclaimedBytes += currentReclaimedBytes } log.info("Reclaimed $reclaimedBytes bytes after prune command") @@ -136,9 +136,9 @@ class DockerContainerRunner( val baseImageTag = configuration.imageTag val runCmd = configuration.runCmd val envFileTargetPath = "$SAVE_AGENT_USER_HOME/.env" - val envVariables = configuration.env.map { (key, value) -> - "$key=$value" - } + "${AgentEnvName.CONTAINER_NAME.name}=$containerName" + val envVariables = configuration.env.mapToEnvs() + + AgentEnvName.CONTAINER_NAME.toEnv(containerName) + + kubernetesEnv // createContainerCmd accepts image name, not id, so we retrieve it from tags val createContainerCmdResponse: CreateContainerResponse = dockerClient.createContainerCmd(baseImageTag) @@ -218,5 +218,10 @@ class DockerContainerRunner( companion object { private val log: Logger = getLogger() private const val RUNNING_STATUS = "running" + private val kubernetesEnv: String = AgentEnvName.KUBERNETES.toEnv(false) + + private fun Map.mapToEnvs(): List = entries.map { (key, value) -> key.toEnv(value) } + + private fun AgentEnvName.toEnv(value: Any): String = "${this.name}=$value" } } diff --git a/save-orchestrator-common/src/main/kotlin/com/saveourtool/save/orchestrator/kubernetes/KubernetesManager.kt b/save-orchestrator-common/src/main/kotlin/com/saveourtool/save/orchestrator/kubernetes/KubernetesManager.kt index da0954a7fe..5562951856 100644 --- a/save-orchestrator-common/src/main/kotlin/com/saveourtool/save/orchestrator/kubernetes/KubernetesManager.kt +++ b/save-orchestrator-common/src/main/kotlin/com/saveourtool/save/orchestrator/kubernetes/KubernetesManager.kt @@ -155,7 +155,7 @@ class KubernetesManager( imagePullPolicy = "IfNotPresent" // so that local images could be used val staticEnvs = env.mapToEnvs() - this.env = staticEnvs + containerIdEnv + this.env = staticEnvs + containerIdEnv + kubernetesEnv this.command = agentRunCmd.dropLast(1) this.args = listOf(agentRunCmd.last()) @@ -176,13 +176,6 @@ class KubernetesManager( } } - private fun Map.mapToEnvs(): List = map { (envName, envValue) -> - EnvVar().apply { - name = envName.name - value = envValue.toString() - } - } - companion object { private val logger = LoggerFactory.getLogger(KubernetesManager::class.java) private const val EXECUTION_ID_LABEL = "executionId" @@ -198,5 +191,13 @@ class KubernetesManager( } } } + private val kubernetesEnv: EnvVar = AgentEnvName.KUBERNETES.toEnv(true) + + private fun Map.mapToEnvs(): List = entries.map { (key, value) -> key.toEnv(value) } + + private fun AgentEnvName.toEnv(value: Any): EnvVar = EnvVar().apply { + this.name = this@toEnv.name + this.value = value.toString() + } } }