Skip to content

Commit

Permalink
docker image config (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
arndey authored Mar 29, 2024
1 parent 4fd6413 commit 724d482
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ open class IrohaContainer : GenericContainer<IrohaContainer> {

constructor(config: IrohaConfig.() -> Unit = {}) : this(IrohaConfig().apply(config))

constructor(config: IrohaConfig) : super(
DockerImageName.parse("${config.imageName}:${config.imageTag}"),
) {
constructor(config: IrohaConfig) : super(config.getFullImageName()) {
val publicKey = config.keyPair.public.bytes().toHex()
val privateKey = config.keyPair.private.bytes().toHex()

Expand Down Expand Up @@ -151,8 +149,13 @@ open class IrohaContainer : GenericContainer<IrohaContainer> {
private fun String.readStatusBlocks() = JSON_SERDE.readTree(this).get("blocks")?.doubleValue()

companion object {
private fun IrohaConfig.getFullImageName() = when (this.imageTag.contains("sha256")) {
true -> "${this.imageName}@${this.imageTag}"
false -> "${this.imageName}:${this.imageTag}"
}.let { DockerImageName.parse(it) }

const val NETWORK_ALIAS = "iroha"
const val DEFAULT_IMAGE_TAG = "stable-2.0.0-pre-rc.20"
const val DEFAULT_IMAGE_TAG = "sha256:b71e3ac42aeace89483eeadcded35cc6f982d4d9b48c002dd425f8dbaf669374"
const val DEFAULT_IMAGE_NAME = "hyperledger/iroha2"
const val DEFAULT_EXECUTOR_FILE_NAME = "executor.wasm"
const val DEFAULT_GENESIS_FILE_NAME = "genesis.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import org.junit.jupiter.api.extension.BeforeEachCallback
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.api.extension.InvocationInterceptor
import org.junit.jupiter.api.extension.ReflectiveInvocationContext
import org.testcontainers.containers.Network
import org.yaml.snakeyaml.Yaml
import java.io.File
import java.lang.reflect.Method
Expand Down Expand Up @@ -85,13 +84,11 @@ class IrohaRunnerExtension : InvocationInterceptor, BeforeEachCallback {
}

private suspend fun WithIroha.init(extensionContext: ExtensionContext): List<AutoCloseable> {
val testInstance = extensionContext.testInstance.get()
val network = testInstance.cast<IrohaTest<*>>().network

val testInstance = extensionContext.testInstance.get().cast<IrohaTest<*>>()
val utilizedResources = mutableListOf<AutoCloseable>()

// start containers
val containers = createContainers(this, network)
val containers = createContainers(this, testInstance)
utilizedResources.addAll(containers)

val properties = testInstance::class.memberProperties
Expand Down Expand Up @@ -208,7 +205,7 @@ class IrohaRunnerExtension : InvocationInterceptor, BeforeEachCallback {

private suspend fun createContainers(
withIroha: WithIroha,
network: Network,
testInstance: IrohaTest<*>,
): List<IrohaContainer> = coroutineScope {
val keyPairs = mutableListOf<KeyPair>()
val portsList = mutableListOf<List<Int>>()
Expand All @@ -228,7 +225,7 @@ class IrohaRunnerExtension : InvocationInterceptor, BeforeEachCallback {
async {
val p2pPort = portsList[n][IrohaConfig.P2P_PORT_IDX]
val container = IrohaContainer {
this.networkToJoin = network
this.networkToJoin = testInstance.network
when {
withIroha.source.isNotEmpty() -> genesisPath = withIroha.source
else -> genesis = withIroha.sources.map { it.createInstance() }.toSingle()
Expand All @@ -239,6 +236,8 @@ class IrohaRunnerExtension : InvocationInterceptor, BeforeEachCallback {
this.trustedPeers = peerIds
this.ports = portsList[n]
this.fetchSize = withIroha.fetchSize
this.imageName = testInstance.imageName
this.imageTag = testInstance.imageTag
this.envs = withIroha.configs.associate { config ->
config.split(IROHA_CONFIG_DELIMITER).let {
it.first() to it.last()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import java.time.Duration
abstract class IrohaTest<T : Iroha2Client>(
val txTimeout: Duration = Duration.ofSeconds(30),
val network: Network = Network.newNetwork(),
val imageName: String = IrohaContainer.DEFAULT_IMAGE_NAME,
val imageTag: String = IrohaContainer.DEFAULT_IMAGE_TAG,
) {
lateinit var client: T
lateinit var containers: List<IrohaContainer>
Expand Down

0 comments on commit 724d482

Please sign in to comment.