shelfio / libreoffice-lambda-base-image

MIT License
30 stars 18 forks source link

How to add fonts to this image? #18

Open atrudeau-vitall opened 1 year ago

atrudeau-vitall commented 1 year ago

I saw this comment about adding new fonts to the base docker image, and I was wondering how I'd go about that? The font I need doesn't seem to be on https://pkgs.org/.

For reference, I'd like to add this font. Any help is appreciated!

shiv4623 commented 1 year ago

Hi, do you know the full implementation process on how to build image and push image to the ECR?

samuelantonioli commented 1 year ago

Hey, I found a solution. Put your ttf files into a fonts/ directory in your repository and use the following Dockerfile:

Dockerfile

FROM public.ecr.aws/shelf/lambda-libreoffice-base:7.4-node16-x86_64
COPY ./ ${LAMBDA_TASK_ROOT}/
COPY ./fonts ${HOME}/.fonts
# dependency not supplied by lambda-libreoffice-base image
# https://github.com/shelfio/aws-lambda-libreoffice/issues/211
RUN fc-cache && yum install java-1.8.0-openjdk-devel -y
RUN npm install
CMD [ "app.handler" ]

What it does is it puts the fonts into the $HOME folder and installs them using fc-cache.

package.json

{
  "dependencies": {
    "@shelf/aws-lambda-libreoffice": "^5.0.0"
  }
}

serverless.yml

service: pdfgen-lambda
frameworkVersion: '3'
provider:
  name: aws
  ecr:    
    images:
      appimage:
        path: ./
functions:
  libreoffice:
    url: true
    image:
      name: appimage

And then

sls deploy
sls invoke --function libreoffice
adussarps commented 10 months ago

Thanks for the help !

adussarps commented 10 months ago

In the end it does not work with otf fonts. Would someone have a solution for it?

adussarps commented 10 months ago

In the end it does not work with otf fonts. Would someone have a solution for it?

Ok, the same approach worked but targeting another directory !

FROM --platform=linux/amd64 public.ecr.aws/shelf/lambda-libreoffice-base:7.4-node16-x86_64

COPY ./ ${LAMBDA_TASK_ROOT}/

RUN mkdir -p /usr/share/fonts/opentype

COPY ./fonts/marinanne  /usr/share/fonts/opentype

# dependency not supplied by lambda-libreoffice-base image
RUN fc-cache -f -v
RUN yum install java-1.8.0-openjdk-devel -y
RUN npm install --only=production

CMD [ "handler.handler" ]