From 72b0c9272d1cc812e250782673a3ad91c720e3be Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Sun, 24 Jul 2022 15:53:06 -0500 Subject: [PATCH] ci: Do not use single-file builds for MUSL Single-file builds incur a performance cost. Mainly because the runtime must extract the contents of the C# application to a temp directory in order for it to run. In a Docker container, single-file offers no tangible benefit because the user isn't interacting directly with those files. To gain some performance improvement, single-file is disabled for MUSL builds. Furthermore, the docker image is reconfigured to place the Recyclarr binary files in a different directory. Previously, as a single-file binary, it was placed in the container at `/usr/local/bin`, but now that it is a multiple-file application, it now lives in `/app/recyclarr`. --- .github/workflows/build.yml | 7 ++++++- ci/Publish.ps1 | 22 ++++++++++++++------- docker/Dockerfile | 5 +++-- docker/scripts/build/build-using-clone.sh | 5 ++--- docker/scripts/build/build-using-release.sh | 2 +- docker/scripts/build/build.sh | 2 ++ 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ce677ef1..83c981c9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,9 +70,14 @@ jobs: with: dotnet-version: ${{ env.dotnetVersion }} + - name: Determine if single file build or not + if: contains(matrix.runtime, 'musl') + id: single_file + run: echo '::set-output name=arg::-noSingleFile' + - name: Publish shell: pwsh - run: ci/Publish.ps1 ${{ matrix.runtime }} + run: ci/Publish.ps1 ${{ matrix.runtime }} ${{ steps.single_file.outputs.arg }} - name: Upload Artifacts uses: actions/upload-artifact@v3 diff --git a/ci/Publish.ps1 b/ci/Publish.ps1 index 53b7b850..5ae6445d 100644 --- a/ci/Publish.ps1 +++ b/ci/Publish.ps1 @@ -1,18 +1,26 @@ [CmdletBinding()] param ( [Parameter(Mandatory = $true)] - [string] $runtime + [string] $runtime, + [Parameter()] + [switch] $noSingleFile ) $ErrorActionPreference = "Stop" +if (-not $noSingleFile) { + $singleFileArgs = @( + "--self-contained=true" + "-p:PublishSingleFile=true" + "-p:IncludeNativeLibrariesForSelfExtract=true" + "-p:PublishReadyToRunComposite=true" + "-p:PublishReadyToRunShowWarnings=true" + "-p:EnableCompressionInSingleFile=true" + ) +} + dotnet publish src\Recyclarr ` --output publish\$runtime ` --configuration Release ` --runtime $runtime ` - --self-contained true ` - -p:PublishSingleFile=true ` - -p:IncludeNativeLibrariesForSelfExtract=true ` - -p:PublishReadyToRunComposite=true ` - -p:PublishReadyToRunShowWarnings=true ` - -p:EnableCompressionInSingleFile=true + $singleFileArgs diff --git a/docker/Dockerfile b/docker/Dockerfile index 97b89c6d..8b7a7edf 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -16,7 +16,8 @@ RUN ./build.sh FROM alpine AS final # Required by environment and/or dotnet -ENV RECYCLARR_APP_DATA=/config \ +ENV PATH="${PATH}:/app/recyclarr" \ + RECYCLARR_APP_DATA=/config \ CRON_SCHEDULE="@daily" \ DOTNET_BUNDLE_EXTRACT_BASE_DIR=/tmp/.net \ # The GLOBALIZATION variable is so that we do not need libicu installed (saves us ~40MB). @@ -26,7 +27,7 @@ RUN set -ex; \ apk add --no-cache bash libstdc++ tzdata supercronic; \ mkdir -p "$DOTNET_BUNDLE_EXTRACT_BASE_DIR" && chmod 777 "$DOTNET_BUNDLE_EXTRACT_BASE_DIR"; -COPY --chmod=555 --from=build /build/recyclarr /usr/local/bin +COPY --from=build /build/publish /app/recyclarr/ COPY --chmod=555 ./scripts/prod/*.sh / USER 1000:1000 diff --git a/docker/scripts/build/build-using-clone.sh b/docker/scripts/build/build-using-clone.sh index 20c73852..56d3f829 100644 --- a/docker/scripts/build/build-using-clone.sh +++ b/docker/scripts/build/build-using-clone.sh @@ -1,8 +1,7 @@ #!/usr/bin/env bash set -ex +# Do not shallow clone because gitversion needs history! git clone -b $BUILD_FROM_BRANCH "https://github.com/$REPOSITORY.git" source -cd source -pwsh ./ci/Publish.ps1 $runtime -cp ./publish/$runtime/recyclarr .. +dotnet publish source/src/Recyclarr -o publish -c Release -r $runtime diff --git a/docker/scripts/build/build-using-release.sh b/docker/scripts/build/build-using-release.sh index c569335a..93b61f63 100644 --- a/docker/scripts/build/build-using-release.sh +++ b/docker/scripts/build/build-using-release.sh @@ -11,4 +11,4 @@ fi # Download and extract the recyclarr binary from the release wget --quiet -O recyclarr.zip "https://github.com/$REPOSITORY/releases/$download_path/recyclarr-$runtime.zip" -unzip recyclarr.zip +unzip recyclarr.zip -d publish diff --git a/docker/scripts/build/build.sh b/docker/scripts/build/build.sh index d917c91a..72205a0b 100644 --- a/docker/scripts/build/build.sh +++ b/docker/scripts/build/build.sh @@ -14,3 +14,5 @@ if [ -z "$BUILD_FROM_BRANCH" ]; then else . ./build-using-clone.sh fi + +chmod a+rx publish/recyclarr