Skip to content

Commit

Permalink
Use gradle-oci for container images in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Aug 1, 2024
1 parent 20c3dfa commit d8c449f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 47 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
22 changes: 21 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.hivemq.extension)
alias(libs.plugins.defaults)
alias(libs.plugins.oci)
alias(libs.plugins.license)
}

Expand All @@ -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 {
Expand All @@ -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")
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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" }
Expand All @@ -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" }
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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() {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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),
Expand All @@ -283,4 +287,4 @@ void containerExisting_nodeStarted_containerUsed() throws IOException {
private @NotNull HiveMQContainer createHiveMQNode() throws IOException {
return createHiveMQNode(createDockerAzuriteConnectionString());
}
}
}

This file was deleted.

0 comments on commit d8c449f

Please sign in to comment.