diff --git a/Dockerfile b/Dockerfile index 6728ddd..4131a49 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,48 @@ -# Stage 1 - Build the frontend -FROM amd64/node:15.5-buster AS node-build-env +# Stage 1 - Build runtime image +FROM ghcr.io/linuxserver/baseimage-mono:LTS -RUN mkdir /appclient -WORKDIR /appclient +# set version label +ARG BUILD_DATE +ARG VERSION +ARG RDTCLIENT_VERSION +LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}" +LABEL maintainer="ravensorb" -COPY client/. . -RUN npm ci -RUN npx ng build --prod --output-path=out +# set environment variables +ARG DEBIAN_FRONTEND="noninteractive" +ENV XDG_CONFIG_HOME="/config/xdg" -# Stage 2 - Build the backend -FROM mcr.microsoft.com/dotnet/sdk:5.0.103-alpine3.13-amd64 AS dotnet-build-env +RUN mkdir /app || true && ln -s /config /data && mkdir -p /data/downloads /data/db || true && \ + echo "**** Updating package information ****" && \ + apt update -y -qq && \ + echo "**** install packages ****" && \ + apt install -y -qq wget jq && \ + echo "**** Installing dotnet ****" && \ + wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb && \ + dpkg -i packages-microsoft-prod.deb 2> /dev/null && \ + rm packages-microsoft-prod.deb && \ + apt update -y -qq && \ + apt install -y -qq apt-transport-https dotnet-runtime-5.0 aspnetcore-runtime-5.0 && \ + echo "**** install rtd-client ****" && \ + if [ -z ${RDTCLIENT_VERSION+x} ]; then \ + RDTCLIENT_VERSION=$(curl -sX GET https://api.github.com/repos/rogerfar/rdt-client/releases/latest | jq -r ".name"); \ + fi && \ + curl -o \ + /tmp/RealDebridClient.zip -L \ + "https://github.com/rogerfar/rdt-client/releases/download/${RDTCLIENT_VERSION}/RealDebridClient.zip" && \ + unzip /tmp/RealDebridClient.zip -d /app && \ + echo "**** cleanup ****" && \ + apt-get -y -qq -o Dpkg::Use-Pty=0 clean && apt-get -y -qq -o Dpkg::Use-Pty=0 purge && \ + rm -rf \ + /tmp/* \ + /var/lib/apt/lists/* \ + /var/tmp/* || true -RUN mkdir /appserver -WORKDIR /appserver +WORKDIR /data -COPY server/. . +# add local files +COPY root/ / -RUN if [ "$BUILDPLATFORM" = "arm/v7" ] ; then dotnet restore -r linux-arm RdtClient.sln ; else dotnet restore RdtClient.sln ; fi -RUN if [ "$BUILDPLATFORM" = "arm/v7" ] ; then dotnet publish -r linux-arm -c Release -o out ; else dotnet publish -c Release -o out ; fi - -# Stage 3 - Build runtime image -FROM mcr.microsoft.com/dotnet/aspnet:5.0.3-buster-slim AS base - -RUN addgroup --quiet --gid 1000 dotnet -RUN adduser --system --uid 1000 --group dotnet --shell /bin/sh - -RUN mkdir /app - -WORKDIR /app -COPY --from=dotnet-build-env /appserver/out . -COPY --from=node-build-env /appclient/out ./wwwroot - -RUN chown -R dotnet:dotnet /app - -USER 1000 - -ENTRYPOINT ["dotnet", "RdtClient.Web.dll"] \ No newline at end of file +# ports and volumes +EXPOSE 6500 +VOLUME ["/config", "/data" ] diff --git a/Dockerfile.build b/Dockerfile.build new file mode 100644 index 0000000..39f19b5 --- /dev/null +++ b/Dockerfile.build @@ -0,0 +1,71 @@ +# Stage 1 - Build the frontend +FROM amd64/node:15.5-buster AS node-build-env + +RUN mkdir /appclient +WORKDIR /appclient + +RUN \ + git clone https://github.com/rogerfar/rdt-client.git . && \ + cd client && \ + npm ci && \ + npx ng build --prod --output-path=out + +# Stage 2 - Build the backend +FROM mcr.microsoft.com/dotnet/sdk:5.0.103-alpine3.13-amd64 AS dotnet-build-env + +RUN mkdir /appserver +WORKDIR /appserver + +RUN \ + git clone https://github.com/rogerfar/rdt-client.git . && \ + cd server && \ + if [ "$BUILDPLATFORM" = "arm/v7" ] ; then dotnet restore -r linux-arm RdtClient.sln ; else dotnet restore RdtClient.sln ; fi && \ + if [ "$BUILDPLATFORM" = "arm/v7" ] ; then dotnet publish -r linux-arm -c Release -o out ; else dotnet publish -c Release -o out ; fi + +# Stage 3 - Build runtime image +FROM ghcr.io/linuxserver/baseimage-mono:LTS + +# set version label +ARG BUILD_DATE +ARG VERSION +ARG RDTCLIENT_VERSION +LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}" +LABEL maintainer="ravensorb" + +# set environment variables +ARG DEBIAN_FRONTEND="noninteractive" +ENV XDG_CONFIG_HOME="/config/xdg" + +RUN mkdir /app || true && ln -s /config /data && mkdir -p /data/downloads /data/db || true && \ + echo "**** Updating package information ****" && \ + apt update -y -qq && \ + apt install -y -qq wget p7zip-full && \ + echo "**** Installing dotnet ****" && \ + wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb && \ + dpkg -i packages-microsoft-prod.deb 2> /dev/null && \ + rm packages-microsoft-prod.deb && \ + apt update -y -qq && \ + apt install -y -qq apt-transport-https dotnet-runtime-5.0 aspnetcore-runtime-5.0 && \ + echo "**** Setting permissions ****" && \ + chown -R abc:abc /data && \ + echo "**** Cleaning image ****" && \ + apt-get -y -qq -o Dpkg::Use-Pty=0 clean && apt-get -y -qq -o Dpkg::Use-Pty=0 purge && \ + rm -rf \ + /tmp/* \ + /var/lib/apt/lists/* \ + /var/tmp/* || true + +WORKDIR /app +COPY --from=dotnet-build-env /appserver/server/out . +COPY --from=node-build-env /appclient/client/out ./wwwroot + +RUN 7z a /data/downloads/RealDebridClient.zip . + +WORKDIR /data + +# add local files +COPY root/ / + +# ports and volumes +EXPOSE 6500 +VOLUME ["/config", "/data" ] diff --git a/docker-build-dev.bat b/docker-build-dev.bat index 54a27d4..26f00b0 100644 --- a/docker-build-dev.bat +++ b/docker-build-dev.bat @@ -1,5 +1,5 @@ docker stop rdtclientdev docker rm rdtclientdev -docker build --tag rdtclientdev . +docker build -f Dockerfile.build --tag rdtclientdev . docker run --cap-add=NET_ADMIN -d -v C:/Temp/RdtClient/:/data/downloads -v C:/Temp/RdtClient/:/data/db --log-driver json-file --log-opt max-size=10m -p 6500:6500 --name rdtclientdev rdtclientdev docker exec -it rdtclientdev /bin/bash \ No newline at end of file diff --git a/docker-compose-build-linux.yml b/docker-compose-build-linux.yml new file mode 100644 index 0000000..a8c83fd --- /dev/null +++ b/docker-compose-build-linux.yml @@ -0,0 +1,21 @@ +version: '3.3' + +services: + rdtclient: + container_name: rdtclient + image: rogerfar/rdtclient + build: + context: . + dockerfile: Dockerfile.build + volumes: + - ./data/downoads:/data/downloads + - ./data/db:/data/db + restart: always + logging: + driver: json-file + options: + max-size: 10m + ports: + - 6500:6500 + cap_add: + - NET_ADMIN diff --git a/docker-compose-build-win.yml b/docker-compose-build-win.yml new file mode 100644 index 0000000..abf6f3a --- /dev/null +++ b/docker-compose-build-win.yml @@ -0,0 +1,21 @@ +version: '3.3' + +services: + rdtclient: + container_name: rdtclient + image: rogerfar/rdtclient + build: + context: . + dockerfile: Dockerfile.build + volumes: + - 'C:/Downloads/:/data/downloads' + - 'C:/Docker/rdtclient/:/data/db' + restart: always + logging: + driver: json-file + options: + max-size: 10m + ports: + - 6500:6500 + cap_add: + - NET_ADMIN \ No newline at end of file diff --git a/docker-publish.bat b/docker-publish.bat index cea421d..55308fc 100644 --- a/docker-publish.bat +++ b/docker-publish.bat @@ -1 +1 @@ -docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag rogerfar/rdtclient . \ No newline at end of file +docker buildx build -f Dockerfile.build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag rogerfar/rdtclient . \ No newline at end of file diff --git a/dotnet-publish.ps1 b/dotnet-publish.ps1 index 1d40703..7d4a95e 100644 --- a/dotnet-publish.ps1 +++ b/dotnet-publish.ps1 @@ -23,10 +23,13 @@ dotnet publish -c Release -o ..\out cd .. cd out -Add-Type -Assembly System.IO.Compression.FileSystem -$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal $location = Get-Location -[System.IO.Compression.ZipFile]::CreateFromDirectory($location, "$location/../RealDebridClient.zip", $compressionLevel, $false) +$compress = @{ + Path=$location + CompressionLevel = "Fastest" + DestinationPath = "$location/../RealDebridClient.zip" +} +Compress-Archive @compress cd .. diff --git a/root/etc/cont-init.d/30-config b/root/etc/cont-init.d/30-config new file mode 100755 index 0000000..2dc3776 --- /dev/null +++ b/root/etc/cont-init.d/30-config @@ -0,0 +1,13 @@ +#!/usr/bin/with-contenv bash + +# cleanup pid if it exists +[[ -e /config/rtdclient.pid ]] && \ + rm -rf /config/rtdclient.pid + +[[ -e /data/rtdclient.pid ]] && \ + rm -rf /data/rtdclient.pid + +# permissions +echo "Setting permissions" +chown -R abc:abc \ + /app /data /config diff --git a/root/etc/services.d/rtdclient/run b/root/etc/services.d/rtdclient/run new file mode 100755 index 0000000..3c8d04d --- /dev/null +++ b/root/etc/services.d/rtdclient/run @@ -0,0 +1,13 @@ +#!/usr/bin/with-contenv bash + +if [ -n "${UMASK_SET}" ] && [ -z "${UMASK}" ]; then + echo -e "You are using a legacy method of defining umask\nplease update your environment variable from UMASK_SET to UMASK\nto keep the functionality after July 2021" + umask ${UMASK_SET} +fi + +echo "Changing to /app folder" +cd /app || exit + +echo "Starting rtdclient" +exec \ + s6-setuidgid abc dotnet RdtClient.Web.dll \ No newline at end of file