From d8c449f076e6c039e16ce2c3ffdee1e21f2eb782 Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Thu, 1 Aug 2024 21:49:07 +0200 Subject: [PATCH] Use gradle-oci for container images in tests --- .github/workflows/check.yml | 8 ++--- build.gradle.kts | 22 ++++++++++++- gradle/libs.versions.toml | 3 ++ .../azure/AzureDiscoveryExtensionIT.java | 22 +++++++------ .../discovery/azure/DockerImageNames.java | 32 ------------------- 5 files changed, 40 insertions(+), 47 deletions(-) delete mode 100644 src/integrationTest/java/com/hivemq/extensions/cluster/discovery/azure/DockerImageNames.java diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ded9910..3f99672 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -17,10 +17,8 @@ jobs: java-version: 11 - name: Setup Gradle uses: gradle/actions/setup-gradle@d9c87d481d55275bb5441eef3fe0e46805f9ef70 # v3 - - name: Login to Docker Hub - uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} - name: Check run: ./gradlew check + env: + ORG_GRADLE_PROJECT_dockerHubUsername: ${{ secrets.DOCKER_USERNAME }} + ORG_GRADLE_PROJECT_dockerHubPassword: ${{ secrets.DOCKER_TOKEN }} diff --git a/build.gradle.kts b/build.gradle.kts index 56d1353..f297c1c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,7 @@ plugins { alias(libs.plugins.hivemq.extension) alias(libs.plugins.defaults) + alias(libs.plugins.oci) alias(libs.plugins.license) } @@ -21,12 +22,25 @@ hivemqExtension { dependencies { compileOnly(libs.jetbrains.annotations) - hivemqProvided(libs.logback.classic) implementation(libs.azure.storage.blob) implementation(libs.owner.java8) } +oci { + registries { + dockerHub { + optionalCredentials() + } + registry("mcr") { + url = uri("https://mcr.microsoft.com") + exclusiveContent { + includeGroup("azure-storage") + } + } + } +} + @Suppress("UnstableApiUsage") testing { suites { @@ -46,9 +60,15 @@ testing { implementation(libs.testcontainers) implementation(libs.testcontainers.hivemq) implementation(libs.testcontainers.toxiproxy) + implementation(libs.gradleOci.junitJupiter) implementation(libs.azure.storage.blob) runtimeOnly(libs.logback.classic) } + ociImageDependencies { + runtime("hivemq:hivemq4:latest") { isChanging = true } + runtime("azure-storage:azurite:3.29.0").tag("latest") + runtime("shopify:toxiproxy:2.1.0").tag("latest") + } } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 219b8c5..0f13874 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,7 @@ [versions] awaitility = "4.2.1" azure-storage-blob = "12.25.4" +gradleOci-junitJupiter = "0.6.0" hivemq-extensionSdk = "4.7.5" jetbrains-annotations = "24.1.0" junit-jupiter = "5.10.0" @@ -12,6 +13,7 @@ testcontainers = "1.19.8" [libraries] awaitility = { module = "org.awaitility:awaitility", version.ref = "awaitility" } azure-storage-blob = { module = "com.azure:azure-storage-blob", version.ref = "azure-storage-blob" } +gradleOci-junitJupiter = { module = "io.github.sgtsilvio:gradle-oci-junit-jupiter", version.ref = "gradleOci-junitJupiter" } jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "jetbrains-annotations" } logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" } mockito = { module = "org.mockito:mockito-core", version.ref = "mockito" } @@ -23,4 +25,5 @@ testcontainers-toxiproxy = { module = "org.testcontainers:toxiproxy", version.re [plugins] hivemq-extension = { id = "com.hivemq.extension", version = "3.1.0" } defaults = { id = "io.github.sgtsilvio.gradle.defaults", version = "0.2.0" } +oci = { id = "io.github.sgtsilvio.gradle.oci", version = "0.15.1" } license = { id = "com.github.hierynomus.license", version = "0.16.1" } diff --git a/src/integrationTest/java/com/hivemq/extensions/cluster/discovery/azure/AzureDiscoveryExtensionIT.java b/src/integrationTest/java/com/hivemq/extensions/cluster/discovery/azure/AzureDiscoveryExtensionIT.java index d1ab41e..9c38e9b 100644 --- a/src/integrationTest/java/com/hivemq/extensions/cluster/discovery/azure/AzureDiscoveryExtensionIT.java +++ b/src/integrationTest/java/com/hivemq/extensions/cluster/discovery/azure/AzureDiscoveryExtensionIT.java @@ -20,6 +20,7 @@ import com.azure.storage.blob.BlobContainerClient; import com.azure.storage.blob.BlobContainerClientBuilder; import com.azure.storage.blob.models.BlobItem; +import io.github.sgtsilvio.gradle.oci.junit.jupiter.OciImages; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -40,10 +41,11 @@ import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; -import static com.hivemq.extensions.cluster.discovery.azure.DockerImageNames.*; import static java.util.concurrent.TimeUnit.SECONDS; import static org.awaitility.Awaitility.await; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; @SuppressWarnings("resource") class AzureDiscoveryExtensionIT { @@ -54,10 +56,11 @@ class AzureDiscoveryExtensionIT { private static final @NotNull String BLOB_CONTAINER_NAME = "hivemq-discovery"; private final @NotNull Network network = Network.newNetwork(); - private final @NotNull GenericContainer azureriteContainer = new GenericContainer<>(AZURITE_IMAGE) // - .withExposedPorts(AZURITE_PORT) // - .withNetwork(network) // - .withNetworkAliases(AZURITE_NETWORK_ALIAS); + private final @NotNull GenericContainer azureriteContainer = + new GenericContainer<>(OciImages.getImageName("azure-storage/azurite")) // + .withExposedPorts(AZURITE_PORT) // + .withNetwork(network) // + .withNetworkAliases(AZURITE_NETWORK_ALIAS); @BeforeEach void setUp() { @@ -116,7 +119,8 @@ void twoNodesInCluster_oneNodeStarted_threeNodesInCluster() throws IOException, @Test void twoNodesInCluster_oneNodeCannotReachAzure_nodeFileDeleted() throws IOException, TimeoutException { - final ToxiproxyContainer toxiproxy = new ToxiproxyContainer(TOXIPROXY_IMAGE).withNetwork(network).withNetworkAliases(TOXIPROXY_NETWORK_ALIAS); + final ToxiproxyContainer toxiproxy = new ToxiproxyContainer(OciImages.getImageName("shopify/toxiproxy")) // + .withNetwork(network).withNetworkAliases(TOXIPROXY_NETWORK_ALIAS); try (toxiproxy) { toxiproxy.start(); @@ -272,7 +276,7 @@ void containerExisting_nodeStarted_containerUsed() throws IOException { final Path configFile = Files.createTempDirectory("az-extension-test").resolve("azDiscovery.properties"); Files.writeString(configFile, createConfig(connectionString)); - return new HiveMQContainer(HIVEMQ_IMAGE) // + return new HiveMQContainer(OciImages.getImageName("hivemq/hivemq4")) // .withHiveMQConfig(MountableFile.forClasspathResource("config.xml")) .withExtension(MountableFile.forClasspathResource("hivemq-azure-cluster-discovery-extension")) .withFileInExtensionHomeFolder(MountableFile.forHostPath(configFile), @@ -283,4 +287,4 @@ void containerExisting_nodeStarted_containerUsed() throws IOException { private @NotNull HiveMQContainer createHiveMQNode() throws IOException { return createHiveMQNode(createDockerAzuriteConnectionString()); } -} \ No newline at end of file +} diff --git a/src/integrationTest/java/com/hivemq/extensions/cluster/discovery/azure/DockerImageNames.java b/src/integrationTest/java/com/hivemq/extensions/cluster/discovery/azure/DockerImageNames.java deleted file mode 100644 index c80e00a..0000000 --- a/src/integrationTest/java/com/hivemq/extensions/cluster/discovery/azure/DockerImageNames.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2021-present HiveMQ GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.hivemq.extensions.cluster.discovery.azure; - -import org.jetbrains.annotations.NotNull; -import org.testcontainers.utility.DockerImageName; - -public final class DockerImageNames { - - public static final @NotNull DockerImageName AZURITE_IMAGE = DockerImageName.parse("mcr.microsoft.com/azure-storage/azurite:3.29.0"); - - public static final @NotNull DockerImageName TOXIPROXY_IMAGE = DockerImageName.parse("shopify/toxiproxy:2.1.0"); - - public static final @NotNull DockerImageName HIVEMQ_IMAGE = - DockerImageName.parse("hivemq/hivemq4").withTag("latest"); - - public DockerImageNames() { - } -}