Skip to content

Commit

Permalink
Merge pull request #2 from iCHEF/upgrade-wkhtmltopdf-to-0-12-5
Browse files Browse the repository at this point in the history
[Upgrade wkhtmltopdf] - [2] upgrade wkhtmltopdf to 0.12.5
  • Loading branch information
holisHsu authored Apr 23, 2021
2 parents d6e4def + 58b04cc commit d2f2f73
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testrunner
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
current_dir := $(shell pwd)

sync-lib-and-bin-from-testrunner:
# usage:
# cd ../ && git clone https://github.com/heroku/heroku-buildpack-testrunner
# make sync-lib-and-bin-from-testrunner testrunner-dir=../heroku-buildpack-testrunner
mkdir -p ${current_dir}/testrunner

rm -rf ${current_dir}/testrunner/lib
cp -rf ${testrunner-dir}/lib ${current_dir}/testrunner/lib

rm -rf ${current_dir}/testrunner/bin
cp -rf ${testrunner-dir}/bin ${current_dir}/testrunner/bin

prepare-testrunner-image:
# Prepare test-runner image for "Different OS"
#
# You will get following images by build this target
#
# 1. heroku-16-buildpack-test-runner
# 2. heroku-20-buildpack-test-runner
docker build . \
-f $(current_dir)/docker/Dockerfile.testrunner \
-t heroku-16-buildpack-test-runner \
--build-arg ubuntu_version=16

docker build . \
-f $(current_dir)/docker/Dockerfile.testrunner \
-t heroku-20-buildpack-test-runner \
--build-arg ubuntu_version=20

docker-test:
# usage
# make docker-test image=heroku-20-buildpack-test-runner
docker run -it -v $(current_dir):/app/buildpack:ro ${image}
53 changes: 31 additions & 22 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

set -e

WHITE="\e[97m"
GREEN="\e[32m"
YELLOW="\e[33m"

BUILD_DIR=$1
CACHE_DIR=$2

Expand All @@ -11,40 +15,45 @@ TMP_PATH="$BUILD_DIR/tmp"
mkdir -p $CACHE_DIR $BIN_PATH $TMP_PATH

[ -z "$WKHTMLTOPDF_VERSION" ] && WKHTMLTOPDF_VERSION="0.12.4"
WKHTMLTOPDF_URL="https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/${WKHTMLTOPDF_VERSION}/wkhtmltox-${WKHTMLTOPDF_VERSION}_linux-generic-amd64.tar.xz"
WKHTMLTOPDF_TAR="$CACHE_DIR/wkhtmltox.tar.xz"
WKHTMLTOPDF_PATH="$TMP_PATH/wkhtmltox"
WKHTMLTOPDF_BINARIES="$WKHTMLTOPDF_PATH/bin"

BIN_DIR=$(cd $(dirname $0); pwd)
FONTS_DIR=$(cd "$BIN_DIR/../fonts"; pwd)

if [ -f $WKHTMLTOPDF_TAR ]; then
echo "-----> Using wkhtmltopdf tar from cache"
echo -e "${GREEN}-----> OS${WHITE}"
echo $OSTYPE
echo $(cat /etc/os-release | grep VERSION_CODENAME)

OS_VERSIONCODE=$(cat /etc/os-release | grep VERSION_CODENAME)

if [[ "$OS_VERSIONCODE" == *"VERSION_CODENAME=focal"* ]]; then
# focal is codename of ubuntu 20
WKHTMLTOPDF_DEB="wkhtmltox_0.12.5-1.focal_amd64.deb"
elif [[ "$OS_VERSIONCODE" == *"VERSION_CODENAME=xenial"* ]]; then
# install wkhtmltopdf for ubuntu 16
WKHTMLTOPDF_DEB="wkhtmltox_0.12.5-1.xenial_amd64.deb"
else
echo "-----> Downloading wkhtmltopdf tar"
curl -L $WKHTMLTOPDF_URL -o $WKHTMLTOPDF_TAR
# default version is for ubuntu 16
echo -e "${YELLOW}WARNING: ${OS_VERSIONCODE} not supported, install default wkhtmltopdf deb for Ubuntu 16${WHITE}"
WKHTMLTOPDF_DEB="wkhtmltox_0.12.5-1.xenial_amd64.deb"
fi

echo "-----> Unpacking tar"
tar -xf $WKHTMLTOPDF_TAR -C $TMP_PATH
WKHTMLTOPDF_URL="https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/${WKHTMLTOPDF_DEB}"

echo "-----> Setting permissions"
chmod +x $WKHTMLTOPDF_BINARIES/*
echo -e "${GREEN}-----> Downloading wkhtmltopdf deb${WHITE}"
wget $WKHTMLTOPDF_URL

echo "-----> Moving binaries to the right place"
mv $WKHTMLTOPDF_BINARIES/* $BIN_PATH/
echo -e "${GREEN}-----> Install wkhtmltopdf${WHITE}"
apt update
yes | apt install xfonts-75dpi xfonts-base
yes | dpkg -i ./$WKHTMLTOPDF_DEB

mkdir -p "$BUILD_DIR"/.profile.d
cat <<EOF >"$BUILD_DIR"/.profile.d/wkhtmltopdf.sh
export PATH="/app/bin:\$PATH"
EOF
echo -e "${GREEN}-----> Cleaning up${WHITE}"
rm -rf $WKHTMLTOPDF_DEB

echo "-----> Cleaning up"
rm -rf $WKHTMLTOPDF_PATH

echo "-----> Installing fonts"
echo -e "${GREEN}-----> Installing fonts${WHITE}"
mkdir -p $1/.fonts
ls $FONTS_DIR
cp $FONTS_DIR/* $1/.fonts/
fc-cache -fv $1/.fonts

exit 0
17 changes: 17 additions & 0 deletions docker/Dockerfile.testrunner
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG ubuntu_version

FROM heroku/heroku:$ubuntu_version

WORKDIR /usr/local/lib

RUN curl --silent https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/shunit2/shunit2-2.1.6.tgz | tar xz

ENV SHUNIT_HOME /usr/local/lib/shunit2-2.1.6

# content in directory testrunner is copy from https://github.com/heroku/heroku-buildpack-testrunner
# it provide utils to run test of this project
ADD testrunner/bin /app/testrunner/bin
ADD testrunner/lib /app/testrunner/lib

CMD ["-c", "/app/buildpack"]
ENTRYPOINT ["/app/testrunner/bin/run"]
11 changes: 11 additions & 0 deletions test/compile_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

. ${BUILDPACK_TEST_RUNNER_HOME}/lib/test_utils.sh

testCompile() {
${BUILDPACK_HOME}/bin/compile ${BUILD_DIR} ${BUILD_DIR} # this comand can see echo logs

wkhtmltopdf http://google.com google.pdf

assertEquals "google.pdf" "$(ls -a | grep google.pdf)"
}

0 comments on commit d2f2f73

Please sign in to comment.