Librum-Reader / Librum-Server

The Librum server
https://librumreader.com
GNU Affero General Public License v3.0
302 stars 22 forks source link

Arm Version of Docker Image Not Functional Due to Unsupported Base Image #31

Open MarcOrfilaCarreras opened 9 months ago

MarcOrfilaCarreras commented 9 months ago

Hi guys,

The arm version of the Docker image seems to be encountering issues, possibly stemming from the utilization of the base image "mcr.microsoft.com/dotnet/aspnet," which lacks support for arm architecture.

The logs from the container:

exec /bin/sh: exec format error
exec /bin/sh: exec format error
exec /bin/sh: exec format error
exec /bin/sh: exec format error

I'm using a Raspberry Pi 4, by the way.

Audiosutras commented 8 months ago

Issue on Raspberry PI 5 as well (aarch64)

KhaaL commented 8 months ago

Thanks for this info, I'm also on arm (aarch64) and running the official compose.yml caused errors for me:

[+] Running 2/0
 ✔ Container librum_db  Running                                                            0.0s 
 ✔ Container librum     Recreated                                                          0.1s 
Attaching to librum, librum_db
librum     | exec /bin/sh: exec format error
librum exited with code 0
librum exited with code 1
librum exited with code 1
librum exited with code 1
librum exited with code 1
librum exited with code 1
librum exited with code 1
librum exited with code 1
librum_db  | 2024-03-31 17:46:31 14 [Warning] Access denied for user 'librum'@'localhost' (using password: YES)
librum exited with code 1
librum_db  | 2024-03-31 17:46:51 15 [Warning] Access denied for user 'librum'@'localhost' (using password: YES)
xiaket commented 4 months ago

I digged into this issue a bit, it looks like it is a known issue from this comment. The Presentation.dll binary in the arm64 container is of filetype: Presentation.dll: PE32 executable (console) Intel 80386 Mono/.Net assembly, for MS Windows.

However, it looks like mcr.microsoft.com/dotnet/aspnet does support arm64 images:

ubuntu@ubuntu:~$ docker manifest inspect mcr.microsoft.com/dotnet/aspnet
{
   "schemaVersion": 2,
   "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
   "manifests": [
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 1580,
         "digest": "sha256:54a062825622483023caafadb465e7873d8fe48454f9ca607bf73b5f51a0016b",
         "platform": {
            "architecture": "amd64",
            "os": "linux"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 1580,
         "digest": "sha256:2dd1e590b6b8f297ed593272109d0c28272f957d6971e87ea348ea5b531a2a1c",
         "platform": {
            "architecture": "arm",
            "os": "linux",
            "variant": "v7"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 1580,
         "digest": "sha256:45c6e36d00122b036d5ab95c167ac4a8dd69a2395d26d4dd3a368bbc09809047",
         "platform": {
            "architecture": "arm64",
            "os": "linux"
         }
      }
   ]
}
ubuntu@ubuntu:~$ docker image inspect mcr.microsoft.com/dotnet/aspnet:8.0 | jq -r ".[0].Architecture"
arm64
ubuntu@ubuntu:~$ docker image inspect mcr.microsoft.com/dotnet/aspnet:8.0 | jq -r ".[0].RepoDigests[0]"
mcr.microsoft.com/dotnet/aspnet@sha256:72bd33dd8f9829cf9681f0a6bc4b43972ec4860a9560ad2b9f4872b548af0add

I'm able to find the matching image here.

xiaket commented 4 months ago

I followed the manual installation instruction on a rpi4(Linux ubuntu 5.4.0-1107-raspi #119-Ubuntu SMP PREEMPT Thu Apr 4 16:03:46 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux), and the generated Presentation.dll is still a 80386 Mono/.Net assembly. So we'll need to change things in dotnet land to make it work on an arm64 machine.

xiaket commented 4 months ago

The following patch for Presentation.csproj works if you invoke dotnet publish with -r linux-arm64 flag:

diff --git a/src/Presentation/Presentation.csproj b/src/Presentation/Presentation.csproj
index dfaa402..2ddc5f5 100644
--- a/src/Presentation/Presentation.csproj
+++ b/src/Presentation/Presentation.csproj
@@ -4,6 +4,7 @@
     <TargetFramework>net8.0</TargetFramework>
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>disable</Nullable>
+    <RuntimeIdentifiers>linux-arm64</RuntimeIdentifiers>
   </PropertyGroup>

   <ItemGroup>
@@ -17,6 +18,12 @@
     <PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
     <PackageReference Include="AutoMapper" Version="12.0.0" />
     <PackageReference Include="Stripe.net" Version="43.15.0" />
+    <PackageReference Include="System.Runtime.Handles" Version="4.3.0" />
+    <PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
+    <PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
+    <PackageReference Include="System.Threading" Version="4.3.0" />
+    <PackageReference Include="System.Threading.Tasks" Version="4.3.0" />
+    <PackageReference Include="System.Text.Encoding.Extensions" Version="4.3.0" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.10">

The generated file looks like:

ubuntu@ubuntu:~/hack/Librum-Server/src/Presentation$ file bin/Release/net8.0/linux-arm64/Presentation.dll
bin/Release/net8.0/linux-arm64/Presentation.dll: PE32+ executable (console) Aarch64 Mono/.Net assembly, for MS Windows

But then the other generated dlls also need a patch like above(as they are still Intel 80386 Mono/.Net assembly). I know nothing about dotnet so I'll stop now and wait for someone knows better. :)