From 311ba78b88fb15f16acf8980bb7a2b1b346333eb Mon Sep 17 00:00:00 2001 From: Shawn Anderson Date: Wed, 15 Mar 2023 15:16:26 -0400 Subject: [PATCH 1/4] Fixed execute permission on service run file. Added healthcheck to Dockerfile and docker-compose file. Updated scripts for addtional functionality --- Dockerfile | 4 ++++ docker-build-dev.ps1 | 2 +- docker-compose.yml | 12 ++++++++--- docker-publish.ps1 | 21 ++++++++++++++++--- .../etc/s6-overlay/s6-rc.d/svc-rdt-client/run | 0 5 files changed, 32 insertions(+), 7 deletions(-) mode change 100644 => 100755 root/etc/s6-overlay/s6-rc.d/svc-rdt-client/run diff --git a/Dockerfile b/Dockerfile index 9d7ac81..4b5e039 100644 --- a/Dockerfile +++ b/Dockerfile @@ -85,6 +85,7 @@ RUN \ ENV PATH "$PATH:/usr/share/dotnet" +# Copy files for app WORKDIR /app COPY --from=dotnet-build-env /appserver/server/out . COPY --from=node-build-env /appclient/client/out ./wwwroot @@ -93,3 +94,6 @@ COPY --from=node-build-env /appclient/root/ / # ports and volumes EXPOSE 6500 VOLUME ["/config", "/data" ] + +# Check Status +HEALTHCHECK --interval=30s --timeout=30s --start-period=30s --retries=3 CMD curl --fail http://localhost:6500 || exit \ No newline at end of file diff --git a/docker-build-dev.ps1 b/docker-build-dev.ps1 index a184ece..e3808fd 100755 --- a/docker-build-dev.ps1 +++ b/docker-build-dev.ps1 @@ -17,7 +17,7 @@ Write-Host "removing Container (if exists)" docker rm rdtclientdev Write-Host "Building Container" -$dockerArgs = @( "build", "--force-rm", "--tag", "rdtclientdev", "--progress=$BuildProgress", "." ) +$dockerArgs = @( "build", "--force-rm", "--network host", "--tag", "rdtclientdev", "--progress=$BuildProgress", "." ) if ($IgnoreBuildCache.IsPresent) { $dockerArgs += @("--no-cace" ) } & docker $dockerArgs diff --git a/docker-compose.yml b/docker-compose.yml index 7987cf4..fe7af7b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,9 +4,9 @@ services: rdtclient: image: rogerfar/rdtclient container_name: rdtclient - build: - context: . - dockerfile: Dockerfile + # build: + # context: . + # dockerfile: Dockerfile environment: - PUID=1001 - PGID=1001 @@ -20,3 +20,9 @@ services: max-size: 10m ports: - '6500:6500' + healthcheck: + test: curl --fail http://localhost:6500 || exit 1 + interval: 30s + retries: 3 + start_period: 30s + timeout: 30s diff --git a/docker-publish.ps1 b/docker-publish.ps1 index c49e274..7132ccb 100755 --- a/docker-publish.ps1 +++ b/docker-publish.ps1 @@ -1,4 +1,4 @@ -#!/bin/pwsh +#!/usr/bin/env pwsh <# .SYNOPSIS Helper script to execute docker buildx @@ -34,12 +34,27 @@ param( [string]$Version = "", [string]$DockerAccount = "rogerfar", - [string]$Platforms = "linux/arm/v7,linux/arm64/v8,linux/amd64" + [string]$Platforms = "linux/arm/v7,linux/arm64/v8,linux/amd64", + [switch]$SkipPush, + [switch]$SkipCache, + [switch]$OutputToDocker ) $imageName = "$($DockerAccount)/rdtclient" -$dockerArgs = @( "buildx", "build", "--no-cache", "--push", "--platform", $Platforms, "--tag", "$($imageName):latest", "." ) +$dockerArgs = @( "buildx", "build", "--network=default", "--platform", $Platforms, "--tag", "$($imageName):latest", "." ) + +if (-Not $SkipPush.IsPresent) { + $dockerArgs += @("--push") +} + +if (-Not $SkipCache.IsPresent) { + $dockerArgs += @("--no-cache") +} + +if ($OutputToDocker.IsPresent) { + $dockerArgs += @("--output=type=docker") +} if ([string]::IsNullOrEmpty($Version)) { $Version = (Get-Content "package.json" | ConvertFrom-Json).version diff --git a/root/etc/s6-overlay/s6-rc.d/svc-rdt-client/run b/root/etc/s6-overlay/s6-rc.d/svc-rdt-client/run old mode 100644 new mode 100755 From caabc769e44ac3f8f6410a70086a91370c075861 Mon Sep 17 00:00:00 2001 From: Shawn Anderson Date: Thu, 16 Mar 2023 09:40:01 -0400 Subject: [PATCH 2/4] Updated docker image to use Alpine (reduces in image size). Cleaned up s6-overlay config. --- .gitignore | 1 + Dockerfile | 16 +++++----------- docker-build-dev.ps1 | 7 ++++--- docker-publish.ps1 | 3 ++- root/etc/s6-overlay/s6-rc.d/init-rdt-client/run | 2 +- root/etc/s6-overlay/s6-rc.d/init-rdt-client/type | 2 +- root/etc/s6-overlay/s6-rc.d/init-rdt-client/up | 2 +- root/etc/s6-overlay/s6-rc.d/svc-rdt-client/run | 5 +++++ root/etc/s6-overlay/s6-rc.d/svc-rdt-client/type | 2 +- .../contents.d/svc-rdt-client} | 0 10 files changed, 21 insertions(+), 19 deletions(-) rename root/etc/s6-overlay/s6-rc.d/{init-rdt-client/dependencies.d/legacy-services => user/contents.d/svc-rdt-client} (100%) diff --git a/.gitignore b/.gitignore index 5abc6f4..aa1877b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ node_modules/ RealDebridClient.zip server/RdtClient.Web/appsettings.Development.json data +Dockerfile.dev \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4b5e039..ed2c445 100644 --- a/Dockerfile +++ b/Dockerfile @@ -65,22 +65,16 @@ ENV RDTCLIENT_BRANCH="main" RUN \ mkdir -p /data/downloads /data/db || true && \ echo "**** Updating package information ****" && \ - apt-get update -y -qq && \ + apk update && \ echo "**** Install pre-reqs ****" && \ - apt-get install -y -qq wget dos2unix && \ - apt-get install -y libc6 libgcc1 libgssapi-krb5-2 libssl1.1 libstdc++6 zlib1g libicu60 && \ + apk add bash icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib && \ echo "**** Installing dotnet ****" && \ - wget -q https://dot.net/v1/dotnet-install.sh && \ - chmod +x ./dotnet-install.sh && \ - bash ./dotnet-install.sh -c LTS -v latest --runtime dotnet --install-dir /usr/share/dotnet && \ - bash ./dotnet-install.sh -c LTS -v latest --runtime aspnetcore --install-dir /usr/share/dotnet && \ - echo "**** Cleaning image ****" && \ - apt-get -y -qq -o Dpkg::Use-Pty=0 clean && apt-get -y -qq -o Dpkg::Use-Pty=0 purge && \ + apk add aspnetcore6-runtime && \ echo "**** Setting permissions ****" && \ chown -R abc:abc /data && \ rm -rf \ /tmp/* \ - /var/lib/apt/lists/* \ + /var/cache/apk/* \ /var/tmp/* || true ENV PATH "$PATH:/usr/share/dotnet" @@ -93,7 +87,7 @@ COPY --from=node-build-env /appclient/root/ / # ports and volumes EXPOSE 6500 -VOLUME ["/config", "/data" ] +VOLUME [ "/data" ] # Check Status HEALTHCHECK --interval=30s --timeout=30s --start-period=30s --retries=3 CMD curl --fail http://localhost:6500 || exit \ No newline at end of file diff --git a/docker-build-dev.ps1 b/docker-build-dev.ps1 index e3808fd..ca5ccaf 100755 --- a/docker-build-dev.ps1 +++ b/docker-build-dev.ps1 @@ -2,8 +2,9 @@ param( [string]$TempPath="c:/Temp/RtdClient", + [string]$Dockerfile="Dockerfile", [switch]$AutoAttach, - [switch]$IgnoreBuildCache, + [switch]$SkipCache, [string]$BuildProgress="auto" ) @@ -17,8 +18,8 @@ Write-Host "removing Container (if exists)" docker rm rdtclientdev Write-Host "Building Container" -$dockerArgs = @( "build", "--force-rm", "--network host", "--tag", "rdtclientdev", "--progress=$BuildProgress", "." ) -if ($IgnoreBuildCache.IsPresent) { $dockerArgs += @("--no-cace" ) } +$dockerArgs = @( "build", "--force-rm", "--tag", "rdtclientdev", "--progress=$BuildProgress", "--file", $Dockerfile, "." ) +if ($SkipCache.IsPresent) { $dockerArgs += @("--no-cache" ) } & docker $dockerArgs Write-Host "Starting Container" diff --git a/docker-publish.ps1 b/docker-publish.ps1 index 7132ccb..f66f38f 100755 --- a/docker-publish.ps1 +++ b/docker-publish.ps1 @@ -35,6 +35,7 @@ param( [string]$Version = "", [string]$DockerAccount = "rogerfar", [string]$Platforms = "linux/arm/v7,linux/arm64/v8,linux/amd64", + [string]$Dockerfile = "Dockerfile", [switch]$SkipPush, [switch]$SkipCache, [switch]$OutputToDocker @@ -42,7 +43,7 @@ param( $imageName = "$($DockerAccount)/rdtclient" -$dockerArgs = @( "buildx", "build", "--network=default", "--platform", $Platforms, "--tag", "$($imageName):latest", "." ) +$dockerArgs = @( "buildx", "build", "--network=default", "--platform", $Platforms, "--tag", "$($imageName):latest", "--file", $Dockerfile, "." ) if (-Not $SkipPush.IsPresent) { $dockerArgs += @("--push") diff --git a/root/etc/s6-overlay/s6-rc.d/init-rdt-client/run b/root/etc/s6-overlay/s6-rc.d/init-rdt-client/run index 2dc3776..e6d57a8 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-rdt-client/run +++ b/root/etc/s6-overlay/s6-rc.d/init-rdt-client/run @@ -10,4 +10,4 @@ # permissions echo "Setting permissions" chown -R abc:abc \ - /app /data /config + /app /data diff --git a/root/etc/s6-overlay/s6-rc.d/init-rdt-client/type b/root/etc/s6-overlay/s6-rc.d/init-rdt-client/type index 3d92b15..bdd22a1 100644 --- a/root/etc/s6-overlay/s6-rc.d/init-rdt-client/type +++ b/root/etc/s6-overlay/s6-rc.d/init-rdt-client/type @@ -1 +1 @@ -oneshot \ No newline at end of file +oneshot diff --git a/root/etc/s6-overlay/s6-rc.d/init-rdt-client/up b/root/etc/s6-overlay/s6-rc.d/init-rdt-client/up index 4c37b14..58d2821 100644 --- a/root/etc/s6-overlay/s6-rc.d/init-rdt-client/up +++ b/root/etc/s6-overlay/s6-rc.d/init-rdt-client/up @@ -1 +1 @@ -etc/s6-overlay/s6-rc.d/init-rdt-client/run \ No newline at end of file +/etc/s6-overlay/s6-rc.d/init-rdt-client/run \ No newline at end of file diff --git a/root/etc/s6-overlay/s6-rc.d/svc-rdt-client/run b/root/etc/s6-overlay/s6-rc.d/svc-rdt-client/run index 3c8d04d..4d94f9c 100755 --- a/root/etc/s6-overlay/s6-rc.d/svc-rdt-client/run +++ b/root/etc/s6-overlay/s6-rc.d/svc-rdt-client/run @@ -5,6 +5,11 @@ if [ -n "${UMASK_SET}" ] && [ -z "${UMASK}" ]; then umask ${UMASK_SET} fi +# permissions +echo "Setting permissions" +chown -R abc:abc \ + /app /data + echo "Changing to /app folder" cd /app || exit diff --git a/root/etc/s6-overlay/s6-rc.d/svc-rdt-client/type b/root/etc/s6-overlay/s6-rc.d/svc-rdt-client/type index 1780f9f..5883cff 100644 --- a/root/etc/s6-overlay/s6-rc.d/svc-rdt-client/type +++ b/root/etc/s6-overlay/s6-rc.d/svc-rdt-client/type @@ -1 +1 @@ -longrun \ No newline at end of file +longrun diff --git a/root/etc/s6-overlay/s6-rc.d/init-rdt-client/dependencies.d/legacy-services b/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-rdt-client similarity index 100% rename from root/etc/s6-overlay/s6-rc.d/init-rdt-client/dependencies.d/legacy-services rename to root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-rdt-client From 7974e33fc2073e8fa317f9ec5db33b712a62d2cd Mon Sep 17 00:00:00 2001 From: Shawn Anderson Date: Thu, 16 Mar 2023 10:22:25 -0400 Subject: [PATCH 3/4] Fixed issue with the SkipCache parameter --- docker-publish.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-publish.ps1 b/docker-publish.ps1 index f66f38f..3e88b62 100755 --- a/docker-publish.ps1 +++ b/docker-publish.ps1 @@ -49,7 +49,7 @@ if (-Not $SkipPush.IsPresent) { $dockerArgs += @("--push") } -if (-Not $SkipCache.IsPresent) { +if ($SkipCache.IsPresent) { $dockerArgs += @("--no-cache") } @@ -65,4 +65,5 @@ $dockerArgs += @("--tag", "$($imageName):$($Version)" ) $dockerApps += @("--build-arg", "VERSION=$($Version)" ) Write-Host "Generating docker image $imageName for $Platforms" +Write-Host "Args: $dockerArgs" & docker $dockerArgs From ff0c8061b50bddf58d8d6e6fa9fd47050d69424f Mon Sep 17 00:00:00 2001 From: Shawn Anderson Date: Thu, 16 Mar 2023 10:22:25 -0400 Subject: [PATCH 4/4] Fixed issue with the SkipCache parameter --- Dockerfile | 2 +- docker-publish.ps1 | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ed2c445..fbf94b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,7 +45,7 @@ RUN \ fi # Stage 3 - Build runtime image -FROM ghcr.io/linuxserver/baseimage-ubuntu:bionic +FROM ghcr.io/linuxserver/baseimage-alpine:3.17 ARG TARGETPLATFORM ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} ARG BUILDPLATFORM diff --git a/docker-publish.ps1 b/docker-publish.ps1 index f66f38f..3e88b62 100755 --- a/docker-publish.ps1 +++ b/docker-publish.ps1 @@ -49,7 +49,7 @@ if (-Not $SkipPush.IsPresent) { $dockerArgs += @("--push") } -if (-Not $SkipCache.IsPresent) { +if ($SkipCache.IsPresent) { $dockerArgs += @("--no-cache") } @@ -65,4 +65,5 @@ $dockerArgs += @("--tag", "$($imageName):$($Version)" ) $dockerApps += @("--build-arg", "VERSION=$($Version)" ) Write-Host "Generating docker image $imageName for $Platforms" +Write-Host "Args: $dockerArgs" & docker $dockerArgs