diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 6ef47926..5a88474a 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -1,4 +1,3 @@ - name: Release docker image on: @@ -19,14 +18,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - cache: maven - - name: Build with Maven - run: mvn --batch-mode --update-snapshots package - name: Log in to the Container registry uses: docker/login-action@v3 with: diff --git a/.gitignore b/.gitignore index c94b0d78..29d32cd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1,29 @@ +### Build and Compilation ### /target/ -.settings /bin/ + +### Editor ### +.settings/ +.settings/org.eclipse.core.resources.prefs +.settings/org.eclipse.jdt.core.prefs +.settings/org.eclipse.m2e.core.prefs /.project /.classpath .pydevproject *.iml -*.log -**/site/sphinx/build/* .idea +.vscode/ +*.swp +*.swo +*~ -### Eclipse ### -.settings/org.eclipse.core.resources.prefs -.settings/org.eclipse.jdt.core.prefs -.settings/org.eclipse.m2e.core.prefs +### Logs ### +*.log +spring-shell.log -### Docker ### -docker-compose-local* +### Documentation ### +**/site/sphinx/build/* -### Spring ### -spring-shell.log +### Docker ### +*compose*.yml +!compose.yml diff --git a/Dockerfile b/Dockerfile index 384078fe..32ce67b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,12 @@ -FROM eclipse-temurin:17-jre +# syntax=docker/dockerfile:1 -# deployment unit -COPY target/ChannelFinder-*.jar /channelfinder/ChannelFinder-*.jar +FROM eclipse-temurin:17-jdk AS builder +WORKDIR /build +RUN apt-get update && apt-get install -y maven +COPY . . +RUN mvn --batch-mode --update-snapshots clean package -DskipTests -CMD ["java", "-jar", "/channelfinder/ChannelFinder-*.jar", "--spring.config.name=application"] +FROM eclipse-temurin:17-jre AS runner +WORKDIR /app +COPY --from=builder /build/target/ChannelFinder-*.jar ./channelfinder.jar +CMD ["java", "-jar", "/app/channelfinder.jar", "--spring.config.name=application"] diff --git a/README.md b/README.md index 6ccdc9df..be565d34 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ ChannelFinder is a Java EE5 REST-style web service. The directory data is held i ### Docker Compose -For using docker containers there is a barebones [docker compose file](./docker-compose.yml). +For using docker containers there is a barebones [docker compose file](./compose.yml). ### Manual Installation diff --git a/docker-compose.yml b/compose.yml similarity index 66% rename from docker-compose.yml rename to compose.yml index b85191b0..8ecc006d 100644 --- a/docker-compose.yml +++ b/compose.yml @@ -1,4 +1,3 @@ -version: "3" services: channelfinder: build: . @@ -8,21 +7,15 @@ services: - channelfinder-net ports: - "8443:8443" - depends_on: - - elasticsearch environment: - - ELASTICSEARCH_NETWORK_HOST=elasticsearch-cf - command: > - /bin/bash -c " - until curl --silent --fail http://elasticsearch-cf:9200/_cluster/health; do - echo 'Waiting for Elasticsearch' - sleep 1 - done - java -jar /channelfinder/ChannelFinder-*.jar" + - ELASTICSEARCH_NETWORK_HOST=elasticsearch + depends_on: + elasticsearch: + condition: service_healthy elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:8.11.2 - hostname: elasticsearch-cf + hostname: elasticsearch networks: - channelfinder-net ports: @@ -35,6 +28,11 @@ services: EPICS_PVAS_INTF_ADDR_LIST: "0.0.0.0" volumes: - channelfinder-es-data:/usr/share/elasticsearch/data + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9200/_cluster/health"] + interval: 10s + timeout: 5s + retries: 3 volumes: channelfinder-es-data: driver: local diff --git a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderChannelsIT.java b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderChannelsIT.java index 7139666c..c47a518c 100644 --- a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderChannelsIT.java +++ b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderChannelsIT.java @@ -37,7 +37,6 @@ /** * Integration tests for ChannelFinder and Elasticsearch with focus on usage of * {@link org.phoebus.channelfinder.CFResourceDescriptors#CHANNEL_RESOURCE_URI}. - * Existing dockerization is used with docker-compose-integrationtest.yml and Dockerfile.integrationtest. * * @author Lars Johansson * diff --git a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderIT.java b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderIT.java index dcf8de10..3dce271b 100644 --- a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderIT.java +++ b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderIT.java @@ -31,7 +31,6 @@ /** * Integration tests for ChannelFinder and Elasticsearch with focus on endpoints being available. - * Existing dockerization is used with docker-compose-integrationtest.yml and Dockerfile.integrationtest. * * @author Lars Johansson * diff --git a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderPropertiesIT.java b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderPropertiesIT.java index 0e8ece42..e91f85d3 100644 --- a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderPropertiesIT.java +++ b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderPropertiesIT.java @@ -38,7 +38,6 @@ /** * Integration tests for ChannelFinder and Elasticsearch with focus on usage of * {@link org.phoebus.channelfinder.CFResourceDescriptors#PROPERTY_RESOURCE_URI}. - * Existing dockerization is used with docker-compose-integrationtest.yml and Dockerfile.integrationtest. * * @author Lars Johansson * diff --git a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderScrollIT.java b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderScrollIT.java index 28390252..ea60d7ee 100644 --- a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderScrollIT.java +++ b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderScrollIT.java @@ -33,7 +33,6 @@ /** * Integration tests for ChannelFinder and Elasticsearch with focus on usage of * {@link org.phoebus.channelfinder.CFResourceDescriptors#SCROLL_RESOURCE_URI}. - * Existing dockerization is used with docker-compose-integrationtest.yml and Dockerfile.integrationtest. * * @author Lars Johansson * diff --git a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderTagsIT.java b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderTagsIT.java index 4228151c..a22e19ed 100644 --- a/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderTagsIT.java +++ b/src/test/java/org/phoebus/channelfinder/docker/ChannelFinderTagsIT.java @@ -38,7 +38,6 @@ /** * Integration tests for ChannelFinder and Elasticsearch with focus on usage of * {@link org.phoebus.channelfinder.CFResourceDescriptors#TAG_RESOURCE_URI}. - * Existing dockerization is used with docker-compose-integrationtest.yml and Dockerfile.integrationtest. * * @author Lars Johansson * diff --git a/src/test/java/org/phoebus/channelfinder/docker/ITUtil.java b/src/test/java/org/phoebus/channelfinder/docker/ITUtil.java index 843f71b8..f42c1b71 100644 --- a/src/test/java/org/phoebus/channelfinder/docker/ITUtil.java +++ b/src/test/java/org/phoebus/channelfinder/docker/ITUtil.java @@ -75,7 +75,7 @@ public class ITUtil { public static final ObjectMapper MAPPER = new ObjectMapper(); public static final String CHANNELFINDER = "channelfinder"; - public static final String INTEGRATIONTEST_DOCKER_COMPOSE = "docker-compose-integrationtest.yml"; + public static final String INTEGRATIONTEST_DOCKER_COMPOSE = "src/test/resources/compose.yml"; // code coverage diff --git a/Dockerfile.integrationtest b/src/test/resources/Dockerfile similarity index 87% rename from Dockerfile.integrationtest rename to src/test/resources/Dockerfile index 2df2ee9a..959ae56d 100644 --- a/Dockerfile.integrationtest +++ b/src/test/resources/Dockerfile @@ -19,9 +19,9 @@ FROM eclipse-temurin:17-jre # deployment unit -COPY target/ChannelFinder-*.jar /channelfinder/ChannelFinder-*.jar +COPY ../../../target/ChannelFinder-*.jar /channelfinder/ChannelFinder-*.jar # code coverage -COPY target/jacoco/jacocoagent.jar /channelfinder/jacocoagent.jar +COPY ../../../target/jacoco/jacocoagent.jar /channelfinder/jacocoagent.jar CMD ["java", "-jar", "/channelfinder/ChannelFinder-*.jar", "--spring.config.name=application"] diff --git a/src/test/resources/INTEGRATIONTEST_DOCKER_RUN.md b/src/test/resources/INTEGRATIONTEST_DOCKER_RUN.md index 70e49c06..fcb96d9b 100644 --- a/src/test/resources/INTEGRATIONTEST_DOCKER_RUN.md +++ b/src/test/resources/INTEGRATIONTEST_DOCKER_RUN.md @@ -73,12 +73,12 @@ mvn clean install test-compile failsafe:integration-test failsafe:verify --batch ##### Build * (Re) Build after change in `src/main/java` in order for change to be tested -* `Dockerfile.integrationtest` relies on built code and not on Maven central +* `Dockerfile` relies on built code and not on Maven central * Requires a deployable jar ##### Configuration -* Configuration in folder `src/test/java` and package `org.phoebus.channelfinder.docker`, e.g. urls and port numbers, is coupled to files `Dockerfile.integrationtest` and `docker-compose-integrationtest.yml` (beside `src/main/resources/application.properties`) +* Configuration in folder `src/test/java` and package `org.phoebus.channelfinder.docker`, e.g. urls and port numbers, is coupled to files `src/test/resources/Dockerfile` and `src/test/resources/compose.yml` (beside `src/main/resources/application.properties`) ##### Debug diff --git a/src/test/resources/INTEGRATIONTEST_DOCKER_TUTORIAL.md b/src/test/resources/INTEGRATIONTEST_DOCKER_TUTORIAL.md index 9a47f86a..cde23d94 100644 --- a/src/test/resources/INTEGRATIONTEST_DOCKER_TUTORIAL.md +++ b/src/test/resources/INTEGRATIONTEST_DOCKER_TUTORIAL.md @@ -33,8 +33,8 @@ It is possible to test ChannelFinder API by running ChannelFinder and Elasticsea ##### Files * folder `src/test/java` and package `org.phoebus.channelfinder.docker` -* [docker-compose-integrationtest.yml](docker-compose-integrationtest.yml) -* [Dockerfile.integrationtest](Dockerfile.integrationtest) +* [compose.yml](src/test/resources/compose.yml) +* [Dockerfile](src/test/resources/Dockerfile) ### Examples @@ -87,7 +87,7 @@ How ### How it works - big picture -Integration tests are implemented in test class annotated with `@Testcontainers`. Test class starts a docker container for the application (ChannelFinder service) and another docker container for elastic (Elasticsearch) through `docker-compose-integrationtest.yml` and `Dockerfile.integrationtest` after which JUnit tests are run. +Integration tests are implemented in test class annotated with `@Testcontainers`. Test class starts a docker container for the application (ChannelFinder service) and another docker container for elastic (Elasticsearch) through `src/test/resources/compose.yml` and `src/test/resources/Dockerfile` after which JUnit tests are run. ``` @Testcontainers @@ -320,8 +320,8 @@ public class ChannelFinderChannelsIT { ##### Note -* (Re) Build after change in `src/main/java` is needed in order for change to be tested as `Dockerfile.integrationtest` relies on built code. -* Configuration in folder `src/test/java` and package `org.phoebus.channelfinder.docker`, e.g. urls and port numbers, is coupled to files `Dockerfile.integrationtest` and `docker-compose-integrationtest.yml` (beside `src/main/resources/application.properties`). +* (Re) Build after change in `src/main/java` is needed in order for change to be tested as `Dockerfile` relies on built code. +* Configuration in folder `src/test/java` and package `org.phoebus.channelfinder.docker`, e.g. urls and port numbers, is coupled to files `src/test/resources/Dockerfile` and `src/test/resources/compose.yml` (beside `src/main/resources/application.properties`). * Both positive and negative tests are important to ensure validation works as expected. ### How to run diff --git a/docker-compose-integrationtest.yml b/src/test/resources/compose.yml similarity index 96% rename from docker-compose-integrationtest.yml rename to src/test/resources/compose.yml index 834050f9..5975aae2 100644 --- a/docker-compose-integrationtest.yml +++ b/src/test/resources/compose.yml @@ -16,12 +16,11 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ------------------------------------------------------------------------------ -version: "3.7" services: channelfinder: - build: - context: . - dockerfile: Dockerfile.integrationtest + build: + context: ../../.. + dockerfile: src/test/resources/Dockerfile hostname: channelfinder networks: - channelfinder-net