From 2aaa3947632638863e143c9be2c97059f9f28afd Mon Sep 17 00:00:00 2001 From: Konstantin Alekseev Date: Sat, 17 Feb 2024 16:39:47 +0200 Subject: [PATCH] Add ghostscript --- .github/workflows/ci.yml | 58 ++++++++++++++++++++++-------------- Makefile | 11 +++++-- fonts/layer_builder.sh | 10 ++----- ghostscript/layer_builder.sh | 12 ++++++++ 4 files changed, 58 insertions(+), 33 deletions(-) create mode 100755 ghostscript/layer_builder.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4447e28..d9be821 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,39 +5,51 @@ jobs: weasyprint-build: name: Build WeasyPrint runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]') " steps: - - uses: actions/checkout@v2 - - name: Build weasyprint - run: | - make build/weasyprint-layer-python3.12.zip + - uses: actions/checkout@v4 + - name: Build Layer + run: make build/weasyprint-layer-python3.12.zip - name: Test weasyprint run: | mkdir output make test.start.container & sleep 1 TEST_FILENAME=output/report.pdf make test.print.report - - name: Upload pdf - uses: actions/upload-artifact@v1 + run -rf build/opt + - name: Upload Build + uses: actions/upload-artifact@v4 + with: + name: WeasyPrint Layer Build + path: build + - name: Upload Test PDF + uses: actions/upload-artifact@v4 with: - name: WeasyPrint test results + name: WeasyPrint Test Results path: output - name: Create WeasyPrint Release - id: create_weasyprint_release if: startsWith(github.ref, 'refs/tags/weasyprint-') - uses: actions/create-release@latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: softprops/action-gh-release@4634c16e79c963813287e889244c50009e7f0981 with: - tag_name: ${{ github.ref }} - release_name: Release WeasyPrint layer - - name: Upload WeasyPrint Layer - if: startsWith(github.ref, 'refs/tags/weasyprint-') - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + files: | + ./build/weasyprint-layer-python3.12.zip + ./build/weasyprint-layer-python3.12-no-fonts.zip + + ghostscript-build: + name: Build GhostScript + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build Layer + run: | + make build/ghostscript-layer.zip + run -rf build/opt + - name: Upload Build + uses: actions/upload-artifact@v4 + with: + name: GhostScript Layer Build + path: build + - name: Create GhostScript Release + if: startsWith(github.ref, 'refs/tags/ghostscript-') + uses: softprops/action-gh-release@4634c16e79c963813287e889244c50009e7f0981 with: - upload_url: ${{ steps.create_weasyprint_release.outputs.upload_url }} - asset_path: ./build/weasyprint-layer-python3.12.zip - asset_name: weasyprint-layer-python3.12.zip - asset_content_type: application/zip + files: ./build/build/ghostscript-layer.zip diff --git a/Makefile b/Makefile index be9d15c..ad001b6 100644 --- a/Makefile +++ b/Makefile @@ -14,10 +14,10 @@ build/weasyprint-layer-python$(RUNTIME).zip: weasyprint/layer_builder.sh \ -v `pwd`/weasyprint:/out \ --entrypoint "/out/layer_builder.sh" \ -t public.ecr.aws/lambda/python:${RUNTIME} - mv -f ./weasyprint/layer.zip ./build/weasyprint-no-fonts-layer.zip + mv -f ./weasyprint/layer.zip ./build/weasyprint-layer-python${RUNTIME}-no-fonts.zip cd build && rm -rf ./opt && mkdir opt \ && unzip fonts-layer.zip -d opt \ - && unzip weasyprint-no-fonts-layer.zip -d opt \ + && unzip weasyprint-layer-python${RUNTIME}-no-fonts.zip -d opt \ && cd opt && zip -r9 ../weasyprint-layer-python${RUNTIME}.zip . build/fonts-layer.zip: fonts/layer_builder.sh | _build @@ -27,6 +27,13 @@ build/fonts-layer.zip: fonts/layer_builder.sh | _build -t public.ecr.aws/lambda/python:${RUNTIME} mv -f ./fonts/layer.zip $@ +build/ghostscript-layer.zip: ghostscript/layer_builder.sh | _build + ${DOCKER_RUN} \ + -v `pwd`/ghostscript:/out \ + --entrypoint "/out/layer_builder.sh" \ + -t public.ecr.aws/lambda/python:${RUNTIME} + mv -f ./ghostscript/layer.zip $@ + stack.diff: cd cdk-stacks && npm install && npm run build cdk diff --app ./cdk-stacks/bin/app.js --stack PrintStack --parameters uploadBucketName=${BUCKET} diff --git a/fonts/layer_builder.sh b/fonts/layer_builder.sh index b4779e9..5a2f1d8 100755 --- a/fonts/layer_builder.sh +++ b/fonts/layer_builder.sh @@ -13,16 +13,10 @@ dnf download dejavu-sans-mono-fonts rpmdev-extract -- *rpm mkdir /opt/fonts +# dnf download urw-base35-nimbus-roman-fonts +# find /tmp/*/usr/share/fonts -name '*.afm' -delete -o -name '*.t1' -delete cp -P -r /tmp/*/usr/share/fonts/* /opt/fonts -if [ "$INSTALL_MS_FONTS" = "yes" ]; then - PYTHON=python2 amazon-linux-extras install epel -y - yum install -y fontconfig xorg-x11-font-utils cabextract - curl -L -O https://downloads.sourceforge.net/project/mscorefonts2/rpms/msttcore-fonts-installer-2.6-1.noarch.rpm - rpm -i msttcore-fonts-installer-2.6-1.noarch.rpm - cp -P -r /usr/share/fonts/msttcore /opt/fonts/ -fi - cat > /opt/fonts/fonts.conf < diff --git a/ghostscript/layer_builder.sh b/ghostscript/layer_builder.sh new file mode 100755 index 0000000..2790fda --- /dev/null +++ b/ghostscript/layer_builder.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e +export VERSION="10.02.1" + +dnf install -y gcc tar +cd /tmp/ +curl -L -s https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs${VERSION//./}/ghostscript-${VERSION}.tar.gz | tar zxf - +cd ghostscript-* +./configure --prefix=/opt +make && make install +cd /opt +zip -r9 /out/layer.zip bin/gs