Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fontconfig error: Cannot load default config file on Docker #598

Closed
3 tasks done
sambeckingham opened this issue Mar 28, 2020 · 3 comments
Closed
3 tasks done

Fontconfig error: Cannot load default config file on Docker #598

sambeckingham opened this issue Mar 28, 2020 · 3 comments

Comments

@sambeckingham
Copy link

sambeckingham commented Mar 28, 2020

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am using the latest version of Magick.NET
  • I have searched open and closed issues to ensure it has not already been reported

Description

Have a .NET Core server (3.1) that generates multiple image then uses montage to piece them back together. Works completely fine locally, but when I build it for Docker I get the following stack trace:

Fontconfig error: Cannot load default config file
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HLUJBD5J604S", Request id "0HLUJBD5J604S:00000001": An unhandled exception was t
hrown by the application.
ImageMagick.MagickTypeErrorException: UnableToReadFont `helvetica' @ error/annotate.c/RenderFreetype/1
392
   at ImageMagick.MagickImageCollection.NativeMagickImageCollection.Montage(IMagickImage image, Montag
eSettings settings)
   at ImageMagick.MagickImageCollection.Montage(MontageSettings settings)
   at ACPosterMaker.Server.ImageProcessor.GenerateMontage() in /source/ACPosterMaker.Server/ImageProce
ssor.cs:line 102

Here is my DockerFile:

# https://hub.docker.com/_/microsoft-dotnet-core
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
RUN apt-get update && apt-get install -y libfreetype6 
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.sln .
COPY ACPosterMaker.Server/*.csproj ./ACPosterMaker.Server/
RUN dotnet restore

# copy everything else and build app
COPY ACPosterMaker.Server/. ./ACPosterMaker.Server/
WORKDIR /source/ACPosterMaker.Server
RUN dotnet publish -c release -o /app

# final stage/image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
RUN apt-get update && apt-get install -y libfreetype6 
WORKDIR /app
COPY --from=build /app ./
ENTRYPOINT ["dotnet", "ACPosterMaker.Server.dll"]

Note I added libfreetype6 on both stages after reading #298 and it made no difference. There was some information about cross compilation in the docs which point to some shell scripts on an Azure endpoint, but it said I didn't have permissions to access it.

Steps to Reproduce

You can clone my repo here: https://github.com/sambeckingham/ACPatternMaker

docker build . -t acpm-server
docker run --name poster-server -p 5001:80 acpm-server

Then post a dataURL string like

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBAgQCwkLEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD/wAARCAANAA0DASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAACAMF/8QAJBAAAQMCBAcAAAAAAAAAAAAAAQACAwURBAYhUhIWF0FhgdH/xAAVAQEBAAAAAAAAAAAAAAAAAAAFBv/EABkRAAMAAwAAAAAAAAAAAAAAAAABAgQRFP/aAAwDAQACEQMRAD8ACs9AxDZLOhf6so8sYkklkUhHkXSKGSabPOQ950O1aXTukO14u2wfUR1bKOsNQz//2Q==

to http://localhost:5001/QrCodeGenerator .

This should return an image made of 16 QR codes, however you will observe in the terminal that an error is thrown.

System Configuration

  • Magick.NET version: Q8-AnyCPU 7.15.5
  • Environment (Operating system, version and so on):
  • Additional information:
@sambeckingham
Copy link
Author

sambeckingham commented Mar 28, 2020

Update:

Managed to get the Fontconfig error: Cannot load default config file to disappear by adding
EXPORT FILECONFIG_PATH=/etc/fonts after the RUN step in the dockerfile.

Also sh'd onto the container and saw which fonts are installed with fc-list, only DejaVu Sans. I passed these in MontageSettings and the stack trace now reads

ImageMagick.MagickTypeErrorException: UnableToReadFont `DejaVu Sans' @ error/annotate.c/RenderFreetype/1392`

Almost 😢

@dlemstra
Copy link
Owner

dlemstra commented Mar 29, 2020

I was using this technique before in my CI build:

RUN apt-get update \
 && apt-get install -y cabextract wget xfonts-utils \
 && curl -s -o ttf-mscorefonts-installer_3.7_all.deb http://ftp.us.debian.org/debian/pool/contrib/m/msttcorefonts/ttf-mscorefonts-installer_3.7_all.deb \
 && sh -c "echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections" \
 && dpkg -i ttf-mscorefonts-installer_3.7_all.deb

Just created a PR for this in your project: sambeckingham/ACPatternMaker#3. I don't know how you got rid of the Fontconfig error but I am now able call the API and get an image

@sambeckingham
Copy link
Author

Tested and it works, thanks so much. The Fontconfig error: Cannot load default config file is because there's FONTCONFIG_PATH set, can slap an ENV FONTCONFIG_PATH=/etc/fonts to make it go away, although I'm not sure if it causes any problems with Magick.NET anyway. Worth mentioning for anyone else who has the issue in the future though 👍

Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants