diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 0377e6c..0000000 --- a/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM eclipse-temurin:17-jdk -WORKDIR /app - -COPY ./build/libs/* ./nextcloud-dlna.jar - -EXPOSE 8080 -CMD ["java","-jar","nextcloud-dlna.jar"] diff --git a/README.md b/README.md index fce6ce3..9e266c5 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,9 @@ thanek/nextcloud-dlna or, if used together with the official Nextcloud docker image using the docker-composer. See the [examples](./examples) directory. for more details about running nextcloud-dlna server in the docker container. -You can pass to the container other env variables that are listed below. +While using docker, you can pass to the container the `NC_DOMAIN` and `NC_PORT` environment variables and force the container +to check and wait for the nextcloud HTTP server to appear on the specified domain and port address. +You can also pass to the container other env variables that are listed below. Note that it would not work on Mac OS since docker is a Linux container and the `host` networking mode doesn't actually share the host's network interfaces. @@ -55,7 +57,7 @@ Available env variables with their default values that you can overwrite: | NEXTCLOUD_DLNA_INTERFACE | | (optional) interface the server will be listening on
if not given, the default local address will be used | | NEXTCLOUD_DLNA_FRIENDLY_NAME | Nextcloud-DLNA | friendly name of the DLNA service | | NEXTCLOUD_DATA_DIR | | nextcloud installation directory (that ends with /data) | -| NEXTCLOUD_DB_TYPE | mariadb | nextcloud database type (mysql, mariadb, postgresql) | +| NEXTCLOUD_DB_TYPE | mariadb | nextcloud database type (mysql, mariadb, postgres) | | NEXTCLOUD_DB_HOST | localhost | nextcloud database host | | NEXTCLOUD_DB_PORT | 3306 | nextcloud database port | | NEXTCLOUD_DB_NAME | nextcloud | nextcloud database name | diff --git a/build.gradle b/build.gradle index bbec057..230ed64 100644 --- a/build.gradle +++ b/build.gradle @@ -91,3 +91,8 @@ tasks.register('integrationTest', Test) { check.dependsOn integrationTest +processResources { + filesMatching('**/application.yml') { + expand(project.properties) + } +} diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..e5dfefc --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,19 @@ +FROM eclipse-temurin:17-jdk +WORKDIR /app + +COPY ./build/libs/* ./nextcloud-dlna.jar + +RUN set -ex; \ + export DEBIAN_FRONTEND=noninteractive; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + tzdata \ + netcat-openbsd \ + ; \ + rm -rf /var/lib/apt/lists/*; + +COPY --chmod=775 ./docker/start.sh /start.sh + +EXPOSE 8080 +ENTRYPOINT ["/start.sh"] +CMD ["java","-jar","nextcloud-dlna.jar"] diff --git a/docker-build-image.sh b/docker/build-image.sh similarity index 72% rename from docker-build-image.sh rename to docker/build-image.sh index 8a35a0b..1a7025f 100755 --- a/docker-build-image.sh +++ b/docker/build-image.sh @@ -1,6 +1,10 @@ #!/bin/bash -version=`./gradlew currentVersion | grep "Project version" | awk -F"version: " '{ print $2 }'` +dir=$(realpath "$(dirname "$0")") + +cd "$dir/../" || exit + +version=$(./gradlew currentVersion | grep "Project version" | awk -F"version: " '{ print $2 }') echo "This will create docker image for version $version." read -p "Continue [y/n]? " -n 1 -r @@ -21,9 +25,13 @@ docker buildx inspect --bootstrap docker buildx build \ --push \ --platform=linux/arm/v7,linux/arm64/v8,linux/amd64 \ + --file=./docker/Dockerfile \ --tag=thanek/nextcloud-dlna:$version . docker buildx build \ --push \ --platform=linux/arm/v7,linux/arm64/v8,linux/amd64 \ + --file=./docker/Dockerfile \ --tag=thanek/nextcloud-dlna . + +cd - || exit diff --git a/docker/start.sh b/docker/start.sh new file mode 100644 index 0000000..7671296 --- /dev/null +++ b/docker/start.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Wait for Nextcloud to come online +if [ -n "$NC_DOMAIN" ] && [ -n "$NC_PORT" ]; then + while ! nc -z "$NC_DOMAIN" "$NC_PORT"; do + echo "Waiting for Nextcloud to start on $NC_DOMAIN:$NC_PORT..." + sleep 5 + done + echo "Nextcloud found on $NC_DOMAIN:$NC_PORT!" +fi + +# Execute CMD +exec /__cacert_entrypoint.sh "$@" diff --git a/examples/docker-compose/docker-compose.yaml b/examples/docker-compose/docker-compose.yaml index 206f621..f8abebe 100644 --- a/examples/docker-compose/docker-compose.yaml +++ b/examples/docker-compose/docker-compose.yaml @@ -72,8 +72,6 @@ services: volumes: - app:/nextcloud network_mode: "host" - ports: - - "9999:9999" environment: - NEXTCLOUD_DLNA_SERVER_PORT=9999 - NEXTCLOUD_DLNA_FRIENDLY_NAME=Nextcloud diff --git a/examples/docker-standalone/run.sh b/examples/docker-standalone/run.sh index 7086777..b2697aa 100644 --- a/examples/docker-standalone/run.sh +++ b/examples/docker-standalone/run.sh @@ -4,7 +4,6 @@ docker run -d \ --name="nextcloud-dlna" \ --restart=unless-stopped \ --net=host \ - -p 9999:9999 \ -e NEXTCLOUD_DLNA_SERVER_PORT=9999 \ -e NEXTCLOUD_DLNA_FRIENDLY_NAME="Nextcloud" \ -e NEXTCLOUD_DB_HOST='localhost' \ diff --git a/src/integration/groovy/support/beans/dlna/upnp/UpnpServiceConfigurationInt.groovy b/src/integration/groovy/support/beans/dlna/upnp/UpnpServiceConfigurationInt.groovy index 91b269e..e4a1478 100644 --- a/src/integration/groovy/support/beans/dlna/upnp/UpnpServiceConfigurationInt.groovy +++ b/src/integration/groovy/support/beans/dlna/upnp/UpnpServiceConfigurationInt.groovy @@ -2,12 +2,12 @@ package support.beans.dlna.upnp import org.jupnp.DefaultUpnpServiceConfiguration import org.jupnp.model.message.OutgoingDatagramMessage +import org.jupnp.transport.Router import org.jupnp.transport.impl.DatagramIOConfigurationImpl import org.jupnp.transport.impl.DatagramIOImpl -import org.jupnp.transport.spi.DatagramIO -import org.jupnp.transport.spi.NetworkAddressFactory -import org.jupnp.transport.spi.StreamClient -import org.jupnp.transport.spi.StreamServer +import org.jupnp.transport.impl.MulticastReceiverConfigurationImpl +import org.jupnp.transport.impl.MulticastReceiverImpl +import org.jupnp.transport.spi.* import org.springframework.context.annotation.Profile import org.springframework.stereotype.Component @@ -31,10 +31,33 @@ class UpnpServiceConfigurationInt extends DefaultUpnpServiceConfiguration { return new MockDatagramIO(this, new DatagramIOConfigurationImpl()) } + @Override + public MulticastReceiver createMulticastReceiver(NetworkAddressFactory networkAddressFactory) { + return new MockMulticastReceiver( + new MulticastReceiverConfigurationImpl( + networkAddressFactory.getMulticastGroup(), + networkAddressFactory.getMulticastPort() + ) + ); + } + private void onOutgoingDatagramMessage(OutgoingDatagramMessage message) { outgoingDatagramMessages.add(message) } + class MockMulticastReceiver extends MulticastReceiverImpl { + MockMulticastReceiver(MulticastReceiverConfigurationImpl configuration) { + super(configuration) + } + + @Override + void init(NetworkInterface networkInterface, Router router, NetworkAddressFactory networkAddressFactory, DatagramProcessor datagramProcessor) throws InitializationException { + } + + @Override + public void run() {} + } + class MockDatagramIO extends DatagramIOImpl { private final UpnpServiceConfigurationInt upnpServiceConfiguration diff --git a/src/integration/resources/db/data.sql b/src/integration/resources/db/data.sql index 269d352..3937d21 100644 --- a/src/integration/resources/db/data.sql +++ b/src/integration/resources/db/data.sql @@ -23,7 +23,7 @@ INSERT INTO `oc_filecache` VALUES (584,2,'__groupfolders','29ff0edf73a32cb03e437d88fd049245',3,'__groupfolders',2,1,3012412,1696702221,1696702221,0,0,'',31,''), (586,2,'__groupfolders/1','e46cc72327dfc3ccaf32f0a167e6c6d1',584,'1',2,1,3012412,1696695701,1696695701,0,0,'',31,''), -(587,2,'__groupfolders/Nextcloud community.jpg','b9b3caef83a2a1c20354b98df6bcd9d0',586,'Nextcloud community.jpg',12,10,797325,1695737657,1695737657,0,0, +(587,2,'__groupfolders/1/Nextcloud community.jpg','b9b3caef83a2a1c20354b98df6bcd9d0',586,'Nextcloud community.jpg',12,10,797325,1695737657,1695737657,0,0, '',27,''), (4,2,'appdata_integration','bed7fa8a60170b5d88c9da5e69eaeb5a',3,'appdata_integration',2,1,10274496,1695737790,1695737790,0,0,'',31,''), diff --git a/src/integration/resources/nextcloud/app/data/__groupfolders/Nextcloud community.jpg b/src/integration/resources/nextcloud/app/data/__groupfolders/1/Nextcloud community.jpg similarity index 100% rename from src/integration/resources/nextcloud/app/data/__groupfolders/Nextcloud community.jpg rename to src/integration/resources/nextcloud/app/data/__groupfolders/1/Nextcloud community.jpg diff --git a/src/main/kotlin/net/schowek/nextclouddlna/util/ServerInfoProvider.kt b/src/main/kotlin/net/schowek/nextclouddlna/util/ServerInfoProvider.kt index 1473442..3b9614e 100644 --- a/src/main/kotlin/net/schowek/nextclouddlna/util/ServerInfoProvider.kt +++ b/src/main/kotlin/net/schowek/nextclouddlna/util/ServerInfoProvider.kt @@ -1,6 +1,5 @@ package net.schowek.nextclouddlna.util -import jakarta.annotation.PostConstruct import mu.KLogging import org.springframework.beans.factory.annotation.Value import org.springframework.context.annotation.Profile diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f116b70..e2be49b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,19 +1,21 @@ server: - port: ${NEXTCLOUD_DLNA_SERVER_PORT:8080} - interface: ${NEXTCLOUD_DLNA_INTERFACE:} - friendlyName: ${NEXTCLOUD_DLNA_FRIENDLY_NAME:Nextcloud-DLNA} + port: \${NEXTCLOUD_DLNA_SERVER_PORT:8080} + interface: \${NEXTCLOUD_DLNA_INTERFACE:} + friendlyName: \${NEXTCLOUD_DLNA_FRIENDLY_NAME:Nextcloud-DLNA} nextcloud: - filesDir: ${NEXTCLOUD_DATA_DIR} + filesDir: \${NEXTCLOUD_DATA_DIR} db: - type: ${NEXTCLOUD_DB_TYPE:mariadb} - host: ${NEXTCLOUD_DB_HOST:localhost} - port: ${NEXTCLOUD_DB_PORT:3306} - name: ${NEXTCLOUD_DB_NAME:nextcloud} - user: ${NEXTCLOUD_DB_USER:nextcloud} - pass: ${NEXTCLOUD_DB_PASS:nextcloud} + type: \${NEXTCLOUD_DB_TYPE:mariadb} + host: \${NEXTCLOUD_DB_HOST:localhost} + port: \${NEXTCLOUD_DB_PORT:3306} + name: \${NEXTCLOUD_DB_NAME:nextcloud} + user: \${NEXTCLOUD_DB_USER:nextcloud} + pass: \${NEXTCLOUD_DB_PASS:nextcloud} spring: + application: + version: ${version} jpa: hibernate: ddl-auto: none diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt new file mode 100644 index 0000000..7faea76 --- /dev/null +++ b/src/main/resources/banner.txt @@ -0,0 +1,7 @@ + _ _ _ _ _ + _ __ _____ _| |_ ___| | ___ _ _ __| | __| | |_ __ __ _ + | '_ \ / _ \ \/ / __/ __| |/ _ \| | | |/ _` |_____ / _` | | '_ \ / _` | + | | | | __/> <| || (__| | (_) | |_| | (_| |_____| (_| | | | | | (_| | + |_| |_|\___/_/\_\\__\___|_|\___/ \__,_|\__,_| \__,_|_|_| |_|\__,_| + +ver: ${spring.application.version} (powered by Spring Boot ${spring-boot.version}) \ No newline at end of file