Installing fonts in nodejs container using nodejsbuilder?

I am trying to use the Sharp nodejs library to render text on a template image. I want to use a specific font and you can’t use the standard ways as specific by W3C to dynamically load a font due to an underlying library not supporting it

The way is apparently to install the font into the operating system, or in our case, into the container. I found the following article How to install custom fonts on a nodejs image using fontconfig | Constant Solutions on how to do just that.

The problem is that I don’t really build the container myself. I just do “fly deploy” on my nodejs app and the magic happens. How can I get custom commands into the generated container?

I ssh console in and do it manually. fontconfig is already installed so I only really have to copy files to the correct place and run the fc-cache command which works nice

So I was thinking “let’s copy files from inside nodejs when it starts” but that is a no-go due to file permissions.

So, is there a way to run essentially the following to commands with correct permission

cp ./fonts/*.ttf /usr/share/fonts/truetype/
fc-cache -f -v

somewhere during startup?

Problem solved eventually. Created a Dockerfile, set it up, installed what needed to be installed, debugged the create image for a couple of hours because of stupid COPY errors in the Dockerfile and now it works (and needed a couple of changes in fly.toml)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.