Skip to content

Commit

Permalink
refactor: using docker image instead of docker compose for http reque…
Browse files Browse the repository at this point in the history
…st logger container
  • Loading branch information
hamidonos committed Nov 6, 2023
1 parent fcd18e2 commit b2e1eec
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,15 +43,14 @@ 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();

@RegisterExtension
static EdcRuntimeExtension consumer = getConsumer();

@Container
public static DockerComposeContainer<?> httpRequestLoggerContainer = getHttpRequestLoggerContainer(LOG_CONSUMER);
public static HttpRequestLoggerContainer httpRequestLoggerContainer = getHttpRequestLoggerContainer(LOG_CONSUMER);

@BeforeAll
static void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.eclipse.edc.samples.util;

import org.testcontainers.containers.*;
import org.testcontainers.images.builder.*;

public class HttpRequestLoggerContainer extends GenericContainer<HttpRequestLoggerContainer> {

public HttpRequestLoggerContainer(ImageFromDockerfile dockerImage) {
super(dockerImage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion transfer/transfer-02-consumer-pull/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
4 changes: 2 additions & 2 deletions util/http-request-logger/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit b2e1eec

Please sign in to comment.