Skip to content

Commit

Permalink
add puppeteer installer
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed May 29, 2023
1 parent 60a5066 commit 247a1a1
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .ci/prepare_machine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ else
:
fi

npm i -g puppeteer

# ensure we have a test database in place for tests
/etc/init.d/mysql start
mysql -e "create database IF NOT EXISTS test;" -uroot -proot
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/citest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ jobs:
run: sudo ./.ci/prepare_machine.sh
- name: ./.ci/install_deps.sh
run: sudo su naemon -c ./.ci/install_deps.sh
- name: ./script/install_puppeteer.sh
run: sudo ./script/install_puppeteer.sh
- name: make citest
run: sudo su naemon -c 'eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib) && make citest'
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -1827,6 +1827,7 @@ script/enable_debug_timer.sh
script/generate_timeperiod_transitions.pl
script/grafana_export.sh
script/html2pdf.sh
script/install_puppeteer.sh
script/Makefile.thruk
script/nagexp
script/nagimp
Expand Down
11 changes: 10 additions & 1 deletion docs/documentation/faq.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,18 @@ phantomjs is no longer required and has been replaced by puppeteer.
=== puppeteer
puppeteer is required to create PDF reports with the reports2 plugin. You can read
more about puppeteer on https://pptr.dev/ OMD starting with version 5 has puppeteer
more about puppeteer on https://pptr.dev/. OMD starting with version 5 has puppeteer
already included.
There are a couple of ways to install puppeteer, the easiest is to use
the shipping installer:
#> /usr/share/thruk/script/install_puppeteer.sh
This will install puppeteer into /var/lib/thruk/puppeteer
It requires node and npm to be installed.
=== How can I enable the business process addon.
It works out of the box with OMD. If not using OMD, some manual steps
Expand Down
1 change: 1 addition & 0 deletions script/Makefile.thruk
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ local_install: local_patches
cp -p script/grafana_export.sh ${DESTDIR}${DATADIR}/script/
cp -p script/html2pdf.sh ${DESTDIR}${DATADIR}/script/
cp -p script/puppeteer.js ${DESTDIR}${DATADIR}/script/
cp -p script/install_puppeteer.sh ${DESTDIR}${DATADIR}/script/
cp -p script/pnp_export.sh ${DESTDIR}${DATADIR}/script/
cp -p support/convert_old_datafile.pl ${DESTDIR}${DATADIR}/script/convert_old_datafile
cp -p script/thruk_auth ${DESTDIR}${DATADIR}/
Expand Down
3 changes: 3 additions & 0 deletions script/grafana_export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ if [ -n "$OMD_ROOT" ]; then
export NODE_PATH=$OMD_ROOT/lib/node_modules/
fi
fi
if [ -z "$NODE_PATH" ] && [ -d /var/lib/thruk/puppeteer/node_modules ]; then
export NODE_PATH=/var/lib/thruk/puppeteer/node_modules
fi

node $DIR/puppeteer.js "$INPUT" "${TEMPFILE}.png" "$WIDTH" "$HEIGHT" "$THRUK_SESSION_ID" 2>&1
rc=$?
Expand Down
3 changes: 3 additions & 0 deletions script/html2pdf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ if [ -n "$OMD_ROOT" ]; then
export NODE_PATH=$OMD_ROOT/lib/node_modules/
fi
fi
if [ -z "$NODE_PATH" ] && [ -d /var/lib/thruk/puppeteer/node_modules ]; then
export NODE_PATH=/var/lib/thruk/puppeteer/node_modules
fi

node $DIR/puppeteer.js "$INPUT" "${OUTPUT}.pdf" "1600" "1200" "" $IS_REPORT 2>&1
mv "${OUTPUT}.pdf" "${OUTPUT}"
Expand Down
41 changes: 41 additions & 0 deletions script/install_puppeteer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

DEST=$1
if [ -z "$DEST" ]; then
DEST=/var/lib/thruk/puppeteer
fi

type npm >/dev/null 2>&1 || (
echo "npm is required to install puppeteer"
exit 1
)

set -e
mkdir -p $DEST
cd $DEST
export PUPPETEER_DOWNLOAD_PATH=$DEST/chromium
echo "module.exports = {}" > .puppeteerrc.cjs
mkdir -p node_modules
npm i progress puppeteer
set +e

MISSING=$(ldd $DEST/chromium/chrome/*/chrome-*/chrome | grep "=> not found")
if [ -n "$MISSING" ]; then
if test -x /usr/bin/yum; then
yum -y install alsa-lib atk at-spi2-atk libdrm libXcomposite libXdamage libxkbcommon libXrandr mesa-libgbm nss
elif test -x /usr/bin/dnf; then
yum -y install alsa-lib atk at-spi2-atk cups-libs libdrm libXcomposite libXdamage libxkbcommon libXrandr mesa-libgbm nss
elif test -x /usr/bin/dnf; then
apt-get install -y libasound2 libatk1.0-0 libatk-bridge2.0-0 libgbm1 libnspr4 libnss3 libxcomposite1 libxdamage1 libxkbcommon0 libxrandr2
fi

MISSING=$(ldd $DEST/chromium/chrome/*/chrome-*/chrome | grep "=> not found")
if [ -n "$MISSING" ]; then
echo "chrome requires some libraries to work:"
echo "$MISSING"
exit 1
fi
fi

echo ""
echo "puppeteer and chromium successfully installed in $DEST"

0 comments on commit 247a1a1

Please sign in to comment.