Skip to content

Tests: Support Docker #1677

Closed
Closed

Description

@swharden

Rendering in Linux is different than Windows when it comes to pixel alignment (#340) and fonts (#1649, #1310, #1079) and it is helpful to have an easy way to inspect images rendered using Linux.

ScottPlot tests work on my machine in Linux using WSL, but it seems more useful to run these tests in a Docker container

I am able to build the project in docker, but the NUnit3 tests fail to run:

System.IO.FileNotFoundException: 
  Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Culture=neutral, PublicKeyToken=null'. 
  The system cannot find the file specified.

FROM mcr.microsoft.com/dotnet/runtime:6.0

version: "2"
services:
scottplot-test:
build:
context: .
dockerfile: ./Dockerfile
volumes:
- ../../:/app
entrypoint: [ "/bin/sh", "-c" ]
command:
- |
cd /app/src/tests/
dotnet add package Microsoft.Bcl.AsyncInterfaces
dotnet restore
dotnet build --no-restore
dotnet test --no-restore --diag logs.txt
cat logs.txt

Activity

  1. grabul commented on Mar 12, 2022

    @grabul

    Hi,
    since I'm a 'docker beginner' tried to make the same approach described here

    copied the following Dockerfile into folder dev/ScottPlot5

    FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
    WORKDIR /source
    
    # copy csproj and restore as distinct layers
    COPY ScottPlot/*.csproj ScottPlot/
    RUN dotnet restore ScottPlot/ScottPlot.csproj
    
    # copy and build lib
    COPY ScottPlot/* ScottPlot/
    WORKDIR /source/ScottPlot
    RUN dotnet build -c release --no-restore
    RUN apt-get update
    RUN apt-get install -y fontconfig
    
    # test stage -- exposes optional entrypoint
    # target entrypoint with: docker build --target test
    FROM build AS test
    WORKDIR /source/ScottPlotTests
    COPY ScottPlotTests/* .
    ENTRYPOINT ["dotnet", "test", "--logger:trx"]
    
    FROM build AS publish
    RUN dotnet publish -c release --no-build -o /app
    
    # final stage/image
    FROM mcr.microsoft.com/dotnet/runtime:6.0
    WORKDIR /app
    COPY --from=publish /app .
    ENTRYPOINT ["dotnet", "ScottPlot.dll"]
    

    create a TestResult folder under ScottPlot5/
    calling from powershell

    docker build --pull --target test -t scottplot-test .

    and run container with

    docker run --rm -v $pwd\ScottPlot5\TestResults:/source/ScottPlotTests/TestResults scottplot-test

    after that in the TestResult folder I got the test results.

    Had two issues:

    1. Before installing the fontconfig library I got an error that the libSkiaSharp could not be loaded.
      (SkiaSharp has a dependency of the fontconfig lib)
    The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.TypeInitializationException: The type initializer for 'SkiaSharp.SKObject' threw an exception.
     ---> System.DllNotFoundException: Unable to load shared library 'libSkiaSharp' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibSkiaSharp: cannot open shared object file: No such file or directory
       at SkiaSharp.SkiaApi.sk_version_get_milestone()
       at SkiaSharp.SkiaSharpVersion.get_Native()
       at SkiaSharp.SkiaSharpVersion.CheckNativeLibraryCompatible(Boolean throwIfIncompatible)
       at SkiaSharp.SKObject..cctor()
       --- End of inner exception stack trace ---
       at SkiaSharp.SKObject.DeregisterHandle(IntPtr handle, SKObject instance)
       at SkiaSharp.SKObject.set_Handle(IntPtr value)
       at SkiaSharp.SKNativeObject.Dispose(Boolean disposing)
       at SkiaSharp.SKObject.Dispose(Boolean disposing)
       at SkiaSharp.SKPaint.Dispose(Boolean disposing)
       at SkiaSharp.SKNativeObject.Finalize()
    
    1. had to add the following lines into the project file of ScottPlot assembly
    	<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
    	<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    

    because of error

    error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [/source/ScottPlot/ScottPlot.csproj]

    hope that helps ...

  2. swharden commented on May 6, 2022

    @swharden
    MemberAuthor

    Thank you so much @grabul!

    This will help a lot when I pick-up work on ScottPlot 5 again! You said you're a Docker beginner, but I'm far more of a beginner, and I really appreciate you looking into this and sharing your findings. 🚀✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions