Skip to content

Commit

Permalink
Add ghostscript
Browse files Browse the repository at this point in the history
  • Loading branch information
kalekseev committed Feb 18, 2024
1 parent e4bdd95 commit 2aaa394
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 33 deletions.
58 changes: 35 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down
10 changes: 2 additions & 8 deletions fonts/layer_builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
<?xml version="1.0" ?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
Expand Down
12 changes: 12 additions & 0 deletions ghostscript/layer_builder.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2aaa394

Please sign in to comment.