From b2e1eec0f2fda4599fa459a5014d7bdf875c6f7f Mon Sep 17 00:00:00 2001 From: hamidonos Date: Mon, 6 Nov 2023 13:28:46 +0100 Subject: [PATCH] refactor: using docker image instead of docker compose for http request logger container --- .../transfer/Transfer02consumerPullTest.java | 4 +-- .../transfer/Transfer03providerPushTest.java | 5 ++-- .../transfer/Transfer04eventConsumerTest.java | 3 ++- .../util/HttpRequestLoggerContainer.java | 11 ++++++++ .../samples/util/HttpRequestLoggerUtil.java | 26 +++++++++++-------- .../util/http-request-logger-wrapper.yaml | 13 ---------- transfer/transfer-02-consumer-pull/README.md | 2 +- util/http-request-logger/Dockerfile | 4 +-- 8 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 system-tests/src/test/java/org/eclipse/edc/samples/util/HttpRequestLoggerContainer.java delete mode 100644 system-tests/src/test/java/org/eclipse/edc/samples/util/http-request-logger-wrapper.yaml diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer02consumerPullTest.java b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer02consumerPullTest.java index f3d897ce..1c0b8a55 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer02consumerPullTest.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer02consumerPullTest.java @@ -19,7 +19,7 @@ import org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates; import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.edc.junit.extensions.EdcRuntimeExtension; -import org.eclipse.edc.samples.util.HttpRequestLoggerConsumer; +import org.eclipse.edc.samples.util.*; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -59,7 +59,7 @@ public class Transfer02consumerPullTest { static EdcRuntimeExtension consumer = getConsumer(); @Container - public static DockerComposeContainer httpRequestLoggerContainer = getHttpRequestLoggerContainer(LOG_CONSUMER); + public static HttpRequestLoggerContainer httpRequestLoggerContainer = getHttpRequestLoggerContainer(LOG_CONSUMER); @BeforeAll static void setUp() { diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer03providerPushTest.java b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer03providerPushTest.java index 5e8c6a8d..37c6d9f4 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer03providerPushTest.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer03providerPushTest.java @@ -18,7 +18,7 @@ import org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates; import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.edc.junit.extensions.EdcRuntimeExtension; -import org.eclipse.edc.samples.util.HttpRequestLoggerConsumer; +import org.eclipse.edc.samples.util.*; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -43,7 +43,6 @@ public class Transfer03providerPushTest { private static final HttpRequestLoggerConsumer LOG_CONSUMER = new HttpRequestLoggerConsumer(); private static final String START_TRANSFER_FILE_PATH = "transfer/transfer-03-provider-push/resources/start-transfer.json"; - @RegisterExtension static EdcRuntimeExtension provider = getProvider(); @@ -51,7 +50,7 @@ public class Transfer03providerPushTest { static EdcRuntimeExtension consumer = getConsumer(); @Container - public static DockerComposeContainer httpRequestLoggerContainer = getHttpRequestLoggerContainer(LOG_CONSUMER); + public static HttpRequestLoggerContainer httpRequestLoggerContainer = getHttpRequestLoggerContainer(LOG_CONSUMER); @BeforeAll static void setUp() { diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer04eventConsumerTest.java b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer04eventConsumerTest.java index aa200722..a6b85e77 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer04eventConsumerTest.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer04eventConsumerTest.java @@ -18,6 +18,7 @@ import org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates; import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.edc.junit.extensions.EdcRuntimeExtension; +import org.eclipse.edc.samples.util.*; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -49,7 +50,7 @@ public class Transfer04eventConsumerTest { static EdcRuntimeExtension consumer = getConsumer(CONSUMER_WITH_LISTENER_MODULE_PATH); @Container - static DockerComposeContainer httpRequestLoggerContainer = getHttpRequestLoggerContainer(); + static HttpRequestLoggerContainer httpRequestLoggerContainer = getHttpRequestLoggerContainer(); @BeforeAll static void setUp() { diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/util/HttpRequestLoggerContainer.java b/system-tests/src/test/java/org/eclipse/edc/samples/util/HttpRequestLoggerContainer.java new file mode 100644 index 00000000..d3f8ea35 --- /dev/null +++ b/system-tests/src/test/java/org/eclipse/edc/samples/util/HttpRequestLoggerContainer.java @@ -0,0 +1,11 @@ +package org.eclipse.edc.samples.util; + +import org.testcontainers.containers.*; +import org.testcontainers.images.builder.*; + +public class HttpRequestLoggerContainer extends GenericContainer { + + public HttpRequestLoggerContainer(ImageFromDockerfile dockerImage) { + super(dockerImage); + } +} diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/util/HttpRequestLoggerUtil.java b/system-tests/src/test/java/org/eclipse/edc/samples/util/HttpRequestLoggerUtil.java index ef8d726c..e900406d 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/util/HttpRequestLoggerUtil.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/util/HttpRequestLoggerUtil.java @@ -14,27 +14,31 @@ package org.eclipse.edc.samples.util; -import org.testcontainers.containers.DockerComposeContainer; import org.testcontainers.containers.output.ToStringConsumer; -import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.images.builder.*; + +import java.util.*; import static org.eclipse.edc.samples.common.FileTransferCommon.getFileFromRelativePath; public class HttpRequestLoggerUtil { - private static final String HTTP_REQUEST_LOGGER_DOCKER_COMPOSE_FILE_PATH = "system-tests/src/test/java/org/eclipse/edc/samples/util/http-request-logger-wrapper.yaml"; - - private static final String HTTP_REQUEST_LOGGER = "http-request-logger"; + private static final String HTTP_REQUEST_LOGGER_DOCKERFILE_PATH = "util/http-request-logger/Dockerfile"; + private static final String PORT_BINDING = "4000:4000"; - public static DockerComposeContainer getHttpRequestLoggerContainer() { - return new DockerComposeContainer<>(getFileFromRelativePath(HTTP_REQUEST_LOGGER_DOCKER_COMPOSE_FILE_PATH)) - .withLocalCompose(true) - .waitingFor(HttpRequestLoggerUtil.HTTP_REQUEST_LOGGER, Wait.forLogMessage(".*started.*", 1)); + public static HttpRequestLoggerContainer getHttpRequestLoggerContainer() { + var container = new HttpRequestLoggerContainer(getDockerImage()); + container.setPortBindings(List.of(PORT_BINDING)); + return container; } - public static DockerComposeContainer getHttpRequestLoggerContainer(ToStringConsumer toStringConsumer) { + public static HttpRequestLoggerContainer getHttpRequestLoggerContainer(ToStringConsumer toStringConsumer) { return getHttpRequestLoggerContainer() - .withLogConsumer(HTTP_REQUEST_LOGGER, toStringConsumer); + .withLogConsumer(toStringConsumer); } + private static ImageFromDockerfile getDockerImage() { + return new ImageFromDockerfile() + .withDockerfile(getFileFromRelativePath(HTTP_REQUEST_LOGGER_DOCKERFILE_PATH).toPath()); + } } diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/util/http-request-logger-wrapper.yaml b/system-tests/src/test/java/org/eclipse/edc/samples/util/http-request-logger-wrapper.yaml deleted file mode 100644 index aa3aefbb..00000000 --- a/system-tests/src/test/java/org/eclipse/edc/samples/util/http-request-logger-wrapper.yaml +++ /dev/null @@ -1,13 +0,0 @@ -# This wraps the http request logger container in the correct context (project root). -# Needed for test execution. - -version: "3.8" - -services: - http-request-logger: - image: http-request-logger - build: - context: ../../../../../../../../.. - dockerfile: util/http-request-logger/Dockerfile - ports: - - "4000:4000" \ No newline at end of file diff --git a/transfer/transfer-02-consumer-pull/README.md b/transfer/transfer-02-consumer-pull/README.md index 145c1bfa..c1e41227 100644 --- a/transfer/transfer-02-consumer-pull/README.md +++ b/transfer/transfer-02-consumer-pull/README.md @@ -29,7 +29,7 @@ As a pre-requisite, you need to have a http server that runs on port 4000 and lo be mandatory to get the EndpointDataReference that will be used to get the data. ```bash -docker build -f util/http-request-logger/Dockerfile -t http-request-logger . +docker build -t http-request-logger util/http-request-logger docker run -p 4000:4000 http-request-logger ``` diff --git a/util/http-request-logger/Dockerfile b/util/http-request-logger/Dockerfile index 87e6ed51..7d355c1c 100644 --- a/util/http-request-logger/Dockerfile +++ b/util/http-request-logger/Dockerfile @@ -2,11 +2,11 @@ FROM gradle:jdk17 AS build WORKDIR /home/gradle/project/ COPY --chown=gradle:gradle . /home/gradle/project/ -RUN gradle util:http-request-logger:build +RUN gradle build FROM openjdk:17-slim WORKDIR /app -COPY --from=build /home/gradle/project/util/http-request-logger/build/libs/http-request-logger.jar /app/http-request-logger.jar +COPY --from=build /home/gradle/project/build/libs/http-request-logger.jar /app/http-request-logger.jar CMD ["java","-jar","/app/http-request-logger.jar"] \ No newline at end of file