Skip to content

Feature/oci image #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ oci {
}
}
}
imageMapping {
mapModule("com.hivemq", "hivemq-enterprise") {
toImage("hivemq/hivemq4")
}
}
imageDefinitions.register("main") {
allPlatforms {
dependencies {
runtime("com.hivemq:hivemq-enterprise:latest") { isChanging = true }
}
layers {
layer("hivemqExtension") {
contents {
permissions("opt/hivemq/", 0b111_111_101)
permissions("opt/hivemq/extensions/", 0b111_111_101)
into("opt/hivemq/extensions") {
from(zipTree(tasks.hivemqExtensionZip.flatMap { it.archiveFile }))
}
}
}
}
}
}
}

@Suppress("UnstableApiUsage")
Expand Down Expand Up @@ -66,7 +89,7 @@ testing {
}
oci.of(this) {
imageDependencies {
runtime("hivemq:hivemq4:latest") { isChanging = true }
runtime(project).tag("latest")
runtime("azure-storage:azurite:3.33.0").tag("latest")
runtime("shopify:toxiproxy:2.1.0").tag("latest")
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ testcontainers-toxiproxy = { module = "org.testcontainers:toxiproxy", version.re
defaults = { id = "io.github.sgtsilvio.gradle.defaults", version = "0.2.0" }
hivemq-extension = { id = "com.hivemq.extension", version = "3.2.0" }
license = { id = "com.github.hierynomus.license", version = "0.16.1" }
oci = { id = "io.github.sgtsilvio.gradle.oci", version = "0.16.0" }
oci = { id = "io.github.sgtsilvio.gradle.oci", version = "0.17.0" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
22 changes: 12 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
import org.testcontainers.utility.MountableFile;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -74,7 +71,7 @@ void tearDown() {
}

@Test
void threeNodesFormCluster() throws IOException, TimeoutException {
void threeNodesFormCluster() throws TimeoutException {
final WaitingConsumer consumer1 = new WaitingConsumer();
final WaitingConsumer consumer2 = new WaitingConsumer();
final WaitingConsumer consumer3 = new WaitingConsumer();
Expand All @@ -95,7 +92,7 @@ void threeNodesFormCluster() throws IOException, TimeoutException {
}

@Test
void twoNodesInCluster_oneNodeStarted_threeNodesInCluster() throws IOException, TimeoutException {
void twoNodesInCluster_oneNodeStarted_threeNodesInCluster() throws TimeoutException {
final WaitingConsumer consumer1 = new WaitingConsumer();
final WaitingConsumer consumer2 = new WaitingConsumer();
final WaitingConsumer consumer3 = new WaitingConsumer();
Expand All @@ -118,7 +115,7 @@ void twoNodesInCluster_oneNodeStarted_threeNodesInCluster() throws IOException,
}

@Test
void twoNodesInCluster_oneNodeCannotReachAzure_nodeFileDeleted() throws IOException, TimeoutException {
void twoNodesInCluster_oneNodeCannotReachAzure_nodeFileDeleted() throws TimeoutException {
final ToxiproxyContainer toxiproxy = new ToxiproxyContainer(OciImages.getImageName("shopify/toxiproxy")) //
.withNetwork(network).withNetworkAliases(TOXIPROXY_NETWORK_ALIAS);
try (toxiproxy) {
Expand Down Expand Up @@ -153,7 +150,7 @@ void twoNodesInCluster_oneNodeCannotReachAzure_nodeFileDeleted() throws IOExcept
}

@Test
void threeNodesInCluster_oneNodeStopped_twoNodesInCluster() throws IOException, TimeoutException {
void threeNodesInCluster_oneNodeStopped_twoNodesInCluster() throws TimeoutException {
final WaitingConsumer consumer1 = new WaitingConsumer();
final WaitingConsumer consumer2 = new WaitingConsumer();
final WaitingConsumer consumer3 = new WaitingConsumer();
Expand Down Expand Up @@ -187,7 +184,7 @@ void threeNodesInCluster_oneNodeStopped_twoNodesInCluster() throws IOException,
}

@Test
void wrongConnectionString_reloadRightConnectionString_clusterCreated() throws IOException, TimeoutException {
void wrongConnectionString_reloadRightConnectionString_clusterCreated() throws TimeoutException {
final String wrongConnectionString = "DefaultEndpointsProtocol=http;" + //
"AccountName=devstoreaccount1;" +
"AccountKey=XXX8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;" +
Expand All @@ -211,7 +208,7 @@ void wrongConnectionString_reloadRightConnectionString_clusterCreated() throws I
}

@Test
void containerNotExisting_nodeStarted_containerCreated() throws IOException {
void containerNotExisting_nodeStarted_containerCreated() {
final BlobContainerClient blobContainerClient = new BlobContainerClientBuilder().connectionString(createHostAzuriteConnectionString())
.containerName(BLOB_CONTAINER_NAME)
.buildClient();
Expand All @@ -228,7 +225,7 @@ void containerNotExisting_nodeStarted_containerCreated() throws IOException {
}

@Test
void containerExisting_nodeStarted_containerUsed() throws IOException {
void containerExisting_nodeStarted_containerUsed() {
final BlobContainerClient blobContainerClient = new BlobContainerClientBuilder().connectionString(createHostAzuriteConnectionString())
.containerName(BLOB_CONTAINER_NAME)
.buildClient();
Expand Down Expand Up @@ -271,20 +268,16 @@ void containerExisting_nodeStarted_containerUsed() throws IOException {
return createAzuriteConnectionString("127.0.0.1", azureriteContainer.getMappedPort(AZURITE_PORT));
}

private @NotNull HiveMQContainer createHiveMQNode(final @NotNull String connectionString) throws IOException {

final Path configFile = Files.createTempDirectory("az-extension-test").resolve("azDiscovery.properties");
Files.writeString(configFile, createConfig(connectionString));

return new HiveMQContainer(OciImages.getImageName("hivemq/hivemq4")) //
private @NotNull HiveMQContainer createHiveMQNode(final @NotNull String connectionString) {
return new HiveMQContainer(OciImages.getImageName("hivemq/extensions/hivemq-azure-cluster-discovery-extension")
.asCompatibleSubstituteFor("hivemq/hivemq4")) //
.withHiveMQConfig(MountableFile.forClasspathResource("config.xml"))
.withExtension(MountableFile.forClasspathResource("hivemq-azure-cluster-discovery-extension"))
.withFileInExtensionHomeFolder(MountableFile.forHostPath(configFile),
"hivemq-azure-cluster-discovery-extension")
.withCopyToContainer(Transferable.of(createConfig(connectionString)),
"/opt/hivemq/extensions/hivemq-azure-cluster-discovery-extension/azDiscovery.properties")
.withNetwork(network);
}

private @NotNull HiveMQContainer createHiveMQNode() throws IOException {
private @NotNull HiveMQContainer createHiveMQNode() {
return createHiveMQNode(createDockerAzuriteConnectionString());
}
}