use ubuntu_plus_user as default test container image
This commit is contained in:
parent
4587938e0b
commit
2623eb857f
10 changed files with 85 additions and 51 deletions
|
@ -1,5 +1,7 @@
|
|||
buildscript {
|
||||
ext.kotlin_version = '1.4.31'
|
||||
ext.CI_PROJECT_ID = System.env.CI_PROJECT_ID
|
||||
|
||||
repositories { jcenter() }
|
||||
|
||||
dependencies {
|
||||
|
@ -60,9 +62,8 @@ dependencies {
|
|||
api "ch.qos.logback:logback-classic:1.2.3"
|
||||
api "ch.qos.logback:logback-core:1.2.3"
|
||||
|
||||
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.2'
|
||||
testFixturesApi group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.2'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
|
||||
testImplementation "io.mockk:mockk:1.9.3"
|
||||
}
|
||||
|
||||
|
||||
|
@ -151,7 +152,7 @@ publishing {
|
|||
if (System.getenv("CI_JOB_TOKEN") != null) {
|
||||
// see https://docs.gitlab.com/ee/user/packages/maven_repository/index.html
|
||||
maven {
|
||||
url "https://gitlab.com/api/v4/projects/23966425/packages/maven"
|
||||
url "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/packages/maven"
|
||||
name "GitLab"
|
||||
credentials(HttpHeaderCredentials) {
|
||||
name = 'Job-Token'
|
||||
|
|
|
@ -8,6 +8,30 @@ import io.provs.platforms.UbuntuProv
|
|||
import io.provs.processors.ContainerStartMode
|
||||
|
||||
|
||||
/**
|
||||
* Builds a docker image if not yet existing.
|
||||
*/
|
||||
fun Prov.dockerProvideImage(image: DockerImage, skipIfExisting: Boolean = true, sudo: Boolean = true) : ProvResult {
|
||||
if (this is UbuntuProv) {
|
||||
return this.dockerProvideImagePlatform(image, skipIfExisting, sudo)
|
||||
} else {
|
||||
throw RuntimeException("docker not yet supported for " + (this as UbuntuProv).javaClass)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the specified docker image exists.
|
||||
*/
|
||||
fun Prov.dockerImageExists(imageName: String, sudo: Boolean = true) : Boolean {
|
||||
if (this is UbuntuProv) {
|
||||
return this.dockerImageExistsPlatform(imageName, sudo)
|
||||
} else {
|
||||
throw RuntimeException("docker not yet supported for " + (this as UbuntuProv).javaClass)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates and runs a new container with name _containerName_ for image _imageName_ if not yet existing.
|
||||
* In case the container already exists, the parameter _startMode_ determines
|
||||
|
@ -51,22 +75,6 @@ fun Prov.runContainer(
|
|||
}
|
||||
|
||||
|
||||
fun Prov.dockerBuildImage(image: DockerImage, skipIfExisting: Boolean = true, sudo: Boolean = true) : ProvResult {
|
||||
if (this is UbuntuProv) {
|
||||
return this.dockerBuildImagePlatform(image, skipIfExisting, sudo)
|
||||
} else {
|
||||
throw RuntimeException("docker not yet supported for " + (this as UbuntuProv).javaClass)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun Prov.dockerImageExists(imageName: String, sudo: Boolean = true) : Boolean {
|
||||
if (this is UbuntuProv) {
|
||||
return this.dockerImageExistsPlatform(imageName, sudo)
|
||||
} else {
|
||||
throw RuntimeException("docker not yet supported for " + (this as UbuntuProv).javaClass)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun Prov.exitAndRmContainer(
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package io.provs.docker.platforms
|
||||
|
||||
import io.provs.*
|
||||
import io.provs.ProvResult
|
||||
import io.provs.docker.containerRuns
|
||||
import io.provs.docker.dockerImageExists
|
||||
import io.provs.docker.exitAndRmContainer
|
||||
import io.provs.docker.images.DockerImage
|
||||
import io.provs.escapeSingleQuote
|
||||
import io.provs.fileSeparator
|
||||
import io.provs.hostUserHome
|
||||
import io.provs.platforms.UbuntuProv
|
||||
import io.provs.processors.ContainerStartMode
|
||||
|
||||
|
@ -58,7 +61,7 @@ fun UbuntuProv.containerExecPlatform(containerName: String, cmd: String, sudo: B
|
|||
}
|
||||
|
||||
|
||||
fun UbuntuProv.dockerBuildImagePlatform(image: DockerImage, skipIfExisting: Boolean, sudo: Boolean): ProvResult {
|
||||
fun UbuntuProv.dockerProvideImagePlatform(image: DockerImage, skipIfExisting: Boolean, sudo: Boolean): ProvResult {
|
||||
val dockerCmd = if (sudo) "sudo docker " else "docker "
|
||||
|
||||
if (skipIfExisting && dockerImageExists(image.imageName())) {
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package io.provs
|
||||
|
||||
import io.provs.test.defaultTestContainer
|
||||
import io.provs.test.tags.CONTAINERTEST
|
||||
import io.provs.test.tags.ContainerTest
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Tag
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.condition.EnabledOnOs
|
||||
import org.junit.jupiter.api.condition.OS
|
||||
|
@ -12,7 +11,7 @@ import org.junit.jupiter.api.condition.OS
|
|||
internal class ContainerProcessorTest {
|
||||
|
||||
@Test
|
||||
@Tag(CONTAINERTEST)
|
||||
@ContainerTest
|
||||
fun cmd_works_with_echo() {
|
||||
|
||||
// given
|
||||
|
@ -29,7 +28,7 @@ internal class ContainerProcessorTest {
|
|||
|
||||
|
||||
@Test
|
||||
@Tag(CONTAINERTEST)
|
||||
@ContainerTest
|
||||
fun cmdNoLog_works_with_echo() {
|
||||
// given
|
||||
val prov = defaultTestContainer()
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package io.provs
|
||||
|
||||
import io.provs.docker.provideContainer
|
||||
import io.provs.test.tags.CONTAINERTEST
|
||||
import io.provs.test.tags.CONTAINER_NON_CI
|
||||
import io.provs.test.tags.ContainerTest
|
||||
import io.provs.test.tags.ContainerTestNonCi
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.Tag
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.condition.EnabledOnOs
|
||||
import org.junit.jupiter.api.condition.OS
|
||||
|
@ -36,7 +35,7 @@ internal class ProvTest {
|
|||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
@Tag(CONTAINERTEST)
|
||||
@ContainerTest
|
||||
fun sh_onLinux() {
|
||||
// given
|
||||
val script = """
|
||||
|
@ -409,7 +408,7 @@ internal class ProvTest {
|
|||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
@Tag(CONTAINER_NON_CI)
|
||||
@ContainerTestNonCi
|
||||
fun inContainer_locally() {
|
||||
// given
|
||||
val containerName = "provs_test"
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package io.provs
|
||||
|
||||
import io.provs.test.defaultTestContainer
|
||||
import io.provs.test.tags.CONTAINERTEST
|
||||
import io.provs.test.tags.ContainerTest
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Tag
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
internal class UtilsTest {
|
||||
|
@ -18,7 +17,7 @@ internal class UtilsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Tag(CONTAINERTEST)
|
||||
@ContainerTest
|
||||
fun test_docker() {
|
||||
// when
|
||||
val res = defaultTestContainer().cmd("echo something")
|
||||
|
|
|
@ -5,9 +5,8 @@ import io.provs.docker.containerRuns
|
|||
import io.provs.docker.exitAndRmContainer
|
||||
import io.provs.docker.runContainer
|
||||
import io.provs.local
|
||||
import io.provs.test.tags.CONTAINER_NON_CI
|
||||
import io.provs.test.tags.ContainerTestNonCi
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Tag
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.condition.EnabledOnOs
|
||||
import org.junit.jupiter.api.condition.OS
|
||||
|
@ -16,7 +15,7 @@ internal class UbuntuHostDockerKtTest {
|
|||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
@Tag(CONTAINER_NON_CI)
|
||||
@ContainerTestNonCi
|
||||
fun runAndCheckAndExitContainer() {
|
||||
// when
|
||||
val containerName = "testContainer"
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package io.provs.processors
|
||||
|
||||
import io.provs.test.DEFAULT_START_MODE_TEST_CONTAINER
|
||||
import io.provs.platforms.SHELL
|
||||
import io.provs.test.DEFAULT_START_MODE_TEST_CONTAINER
|
||||
import io.provs.test.tags.ContainerTest
|
||||
import io.provs.test.testDockerWithSudo
|
||||
import io.provs.test.tags.CONTAINERTEST
|
||||
import org.junit.jupiter.api.Tag
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.condition.EnabledOnOs
|
||||
import org.junit.jupiter.api.condition.OS.LINUX
|
||||
|
@ -14,7 +13,7 @@ class ContainerUbuntuHostProcessorTest {
|
|||
|
||||
@Test
|
||||
@EnabledOnOs(LINUX)
|
||||
@Tag(CONTAINERTEST)
|
||||
@ContainerTest
|
||||
fun test() {
|
||||
val processor =
|
||||
ContainerUbuntuHostProcessor("provs_ubuntuhost_test", "ubuntu", DEFAULT_START_MODE_TEST_CONTAINER, sudo = testDockerWithSudo)
|
||||
|
|
|
@ -1,22 +1,32 @@
|
|||
package io.provs.test
|
||||
|
||||
import io.provs.Prov
|
||||
import io.provs.docker.dockerImageExists
|
||||
import io.provs.docker.dockerProvideImage
|
||||
import io.provs.docker.images.UbuntuPlusUser
|
||||
import io.provs.local
|
||||
import io.provs.processors.ContainerStartMode
|
||||
import io.provs.processors.ContainerUbuntuHostProcessor
|
||||
|
||||
val DEFAULT_START_MODE_TEST_CONTAINER = ContainerStartMode.USE_RUNNING_ELSE_CREATE
|
||||
|
||||
val testDockerWithSudo = "true" != System.getProperty("testdockerwithoutsudo")?.toLowerCase()
|
||||
val testDockerWithSudo = !"true".equals(System.getProperty("testdockerwithoutsudo")?.toLowerCase())
|
||||
|
||||
const val defaultTestContainerName = "provs_test"
|
||||
|
||||
fun defaultTestContainer(imageName: String = "ubuntu"): Prov {
|
||||
fun defaultTestContainer(): Prov {
|
||||
val image = UbuntuPlusUser()
|
||||
val prov = local()
|
||||
if (!prov.dockerImageExists(image.imageName(), testDockerWithSudo)) {
|
||||
prov.dockerProvideImage(image, sudo = testDockerWithSudo)
|
||||
}
|
||||
|
||||
return Prov.newInstance(
|
||||
ContainerUbuntuHostProcessor(
|
||||
defaultTestContainerName,
|
||||
startMode = DEFAULT_START_MODE_TEST_CONTAINER,
|
||||
sudo = testDockerWithSudo,
|
||||
dockerImage = imageName
|
||||
dockerImage = image.imageName()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,21 @@
|
|||
package io.provs.test.tags
|
||||
|
||||
const val CONTAINERTEST = "containertest"
|
||||
const val CONTAINER_NON_CI = "containernonci"
|
||||
import org.junit.jupiter.api.Tag
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
private const val CONTAINER_TEST = "containertest"
|
||||
private const val CONTAINER_TEST_NON_CI = "containernonci"
|
||||
|
||||
|
||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
|
||||
@kotlin.annotation.Retention
|
||||
@Tag(CONTAINER_TEST)
|
||||
@Test
|
||||
annotation class ContainerTest
|
||||
|
||||
|
||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
|
||||
@kotlin.annotation.Retention
|
||||
@Tag(CONTAINER_TEST_NON_CI)
|
||||
@Test
|
||||
annotation class ContainerTestNonCi
|
Loading…
Reference in a new issue