Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbundled binaries #129

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin/*
!bin/download_link_matrix.rb
!bin/wkhtmltopdf
!bin/wkhtmltopdf-binary.rb
8 changes: 8 additions & 0 deletions .docker/Dockerfile-amazonlinux2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM amazonlinux:2

RUN yum install -y ruby libjpeg-turbo libpng libXrender fontconfig libXext gzip

WORKDIR /root/wkhtmltopdf_binary_gem
COPY . .

CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version
4 changes: 4 additions & 0 deletions .docker/Dockerfile-archlinux
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ ENV DEBIAN_FRONTEND noninteractive

RUN pacman -Sy --noconfirm ruby fontconfig freetype2 libjpeg libpng libxext libxrender

WORKDIR /root/wkhtmltopdf_binary_gem
COPY . .
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repo too heavy to copy all into the image. Why you copy it? We could mount directly repo folder to run

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is specifically to make this repo not heavy


CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version
# CMD /bin/bash
3 changes: 3 additions & 0 deletions .docker/Dockerfile-centos_6
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ RUN rm -f /etc/yum.repos.d/CentOS-Base.repo && \
yum update -y && \
yum install -y ruby libjpeg-turbo libpng libXrender fontconfig libXext

WORKDIR /root/wkhtmltopdf_binary_gem
COPY . .

CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version
6 changes: 5 additions & 1 deletion .docker/Dockerfile-centos_7
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
FROM centos:7

RUN yum install -y ruby libjpeg-turbo libpng libXrender fontconfig libXext
RUN yum -y groupinstall "Development Tools"
RUN yum install -y ruby libjpeg-turbo libXrender fontconfig libXext zlib-devel openssl11-libs

WORKDIR /root/wkhtmltopdf_binary_gem
COPY . .

CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version
3 changes: 3 additions & 0 deletions .docker/Dockerfile-centos_8
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ RUN dnf distro-sync -y

RUN yum install -y ruby libjpeg-turbo libpng libXrender fontconfig libXext

WORKDIR /root/wkhtmltopdf_binary_gem
COPY . .

CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version
5 changes: 4 additions & 1 deletion .docker/Dockerfile-debian_10
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ FROM debian:10
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update
RUN apt-get install -y ruby libjpeg62-turbo libpng16-16 libxrender1 libfontconfig1 libxext6
RUN apt-get install -y ruby libjpeg62-turbo libpng16-16 libxrender1 libfontconfig1 libxext6 curl

WORKDIR /root/wkhtmltopdf_binary_gem
COPY . .

CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version
5 changes: 4 additions & 1 deletion .docker/Dockerfile-debian_9
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ FROM debian:9
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update
RUN apt-get install -y ruby libjpeg62-turbo libpng16-16 libxrender1 libfontconfig1 libxext6
RUN apt-get install -y ruby libjpeg62-turbo libpng16-16 libxrender1 libfontconfig1 libxext6 curl

WORKDIR /root/wkhtmltopdf_binary_gem
COPY . .

CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version
5 changes: 4 additions & 1 deletion .docker/Dockerfile-rockylinux_8
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM rockylinux/rockylinux:8

RUN yum install -y ruby libjpeg-turbo libpng libXrender fontconfig libXext
RUN yum install -y ruby libjpeg-turbo libpng libXrender fontconfig libXext cpio

WORKDIR /root/wkhtmltopdf_binary_gem
COPY . .

CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version
5 changes: 4 additions & 1 deletion .docker/Dockerfile-ubuntu_16.04
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ FROM ubuntu:16.04
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update
RUN apt-get install -y ruby libjpeg8 libxrender1 libfontconfig1
RUN apt-get install -y ruby libjpeg-turbo8 libxrender1:arm64 libxtst6:arm64 libfontconfig1 curl

WORKDIR /root/wkhtmltopdf_binary_gem
COPY . .

CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version
5 changes: 4 additions & 1 deletion .docker/Dockerfile-ubuntu_18.04
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ FROM ubuntu:18.04
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update
RUN apt-get install -y ruby libjpeg8 libxrender1 libfontconfig1
RUN apt-get install -y ruby libjpeg-turbo8 libxrender1:arm64 libxtst6:arm64 libfontconfig1 curl

WORKDIR /root/wkhtmltopdf_binary_gem
COPY . .

CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version
5 changes: 4 additions & 1 deletion .docker/Dockerfile-ubuntu_20.04
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ FROM ubuntu:20.04
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update
RUN apt-get install -y ruby libjpeg8 libxrender1 libfontconfig1
RUN apt-get install -y ruby libjpeg-turbo8 libxrender1:arm64 libxtst6:arm64 libfontconfig1 curl

WORKDIR /root/wkhtmltopdf_binary_gem
COPY . .

CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version
22 changes: 5 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
.DS_Store
pkg/*
Gemfile.lock
bin/wkhtmltopdf_centos_6_amd64
bin/wkhtmltopdf_centos_7_amd64
bin/wkhtmltopdf_centos_8_amd64
bin/wkhtmltopdf_debian_9_amd64
bin/wkhtmltopdf_debian_10_amd64
bin/wkhtmltopdf_macos_cocoa
bin/wkhtmltopdf_ubuntu_16.04_amd64
bin/wkhtmltopdf_ubuntu_18.04_amd64
bin/wkhtmltopdf_ubuntu_20.04_amd64
bin/wkhtmltopdf_ubuntu_22.04_amd64
bin/wkhtmltopdf_centos_6_i386
bin/wkhtmltopdf_centos_7_i386
bin/wkhtmltopdf_debian_9_i386
bin/wkhtmltopdf_debian_10_i386
bin/wkhtmltopdf_ubuntu_16.04_i386
bin/wkhtmltopdf_ubuntu_18.04_i386
bin/wkhtmltopdf_archlinux_amd64

bin/*
!bin/download_link_matrix.rb
!bin/wkhtmltopdf
!bin/wkhtmltopdf-binary.rb
64 changes: 64 additions & 0 deletions bin/download_link_matrix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
links = [
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.msvc2015-win64.exe',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.msvc2015-win32.exe',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.mxe-cross-win64.7z',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.mxe-cross-win32.7z',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-2/wkhtmltox-0.12.6-2.macos-cocoa.pkg',

'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_amd64.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_i386.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_arm64.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_ppc64le.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.raspberrypi.buster_armhf.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.stretch_amd64.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.stretch_i386.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.stretch_arm64.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.raspberrypi.stretch_armhf.deb',

'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_arm64.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_ppc64el.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_arm64.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_ppc64le.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_i386.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_arm64.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_ppc64le.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.xenial_amd64.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.xenial_i386.deb',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.xenial_arm64.deb',

'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos8.x86_64.rpm',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos8.aarch64.rpm',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos8.ppc64le.rpm',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos7.x86_64.rpm',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos7.i686.rpm',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos7.aarch64.rpm',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos7.ppc64le.rpm',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos6.x86_64.rpm',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos6.i686.rpm',

'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.amazonlinux2.x86_64.rpm',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.amazonlinux2.aarch64.rpm',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-4/wkhtmltox-0.12.6-4.amazonlinux2_lambda.zip',

'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.opensuse.leap15.x86_64.rpm',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.opensuse.leap15.aarch64.rpm',
'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.opensuse.leap15.ppc64le.rpm',

'https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-3/wkhtmltox-0.12.6-3.archlinux-x86_64.pkg.tar.xz',
]

DOWNLOAD_LINK_MATRIX = {}

links.each do |link|
version, binary = link.sub('https://github.com/wkhtmltopdf/packaging/releases/download/','').split('/')
binary.sub!(/wkhtmltox[-_]#{version}\./, '')

platform, architecture = binary.split(/[\.\-\_]/,2)
architecture.sub!(/\.(pkg\.tar\.xz|rpm|deb|zip|exe|pkg|7z)/,'')

DOWNLOAD_LINK_MATRIX[platform] ||= {}
DOWNLOAD_LINK_MATRIX[platform][architecture] = link
end
92 changes: 65 additions & 27 deletions bin/wkhtmltopdf
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,107 @@

require 'rbconfig'
require 'zlib'
require File.expand_path(File.dirname(__FILE__) + '/download_link_matrix')

suffix = case RbConfig::CONFIG['host_os']
os_architecture = case RbConfig::CONFIG['host_os']
when /linux/
os = `. /etc/os-release 2> /dev/null && echo ${ID}_${VERSION_ID}`.strip

os = 'ubuntu_16.04' if os.start_with?('ubuntu_16.') ||
os = 'xenial' if os.start_with?('ubuntu_16.') ||
os.start_with?('ubuntu_17.') ||
os.start_with?('linuxmint_18.')

os = 'ubuntu_18.04' if os.start_with?('ubuntu_18.') ||
os = 'bionic' if os.start_with?('ubuntu_18.') ||
os.start_with?('ubuntu_19.') ||
os.start_with?('elementary') ||
os.start_with?('linuxmint_19.') ||
os.start_with?('pop') ||
os.start_with?('zorin')

os = 'ubuntu_20.04' if os.start_with?('ubuntu_20.') ||
os = 'focal' if os.start_with?('ubuntu_20.') ||
os.start_with?('ubuntu_21.') ||
os.start_with?('linuxmint_20.')

os = 'ubuntu_22.04' if os.start_with?('ubuntu_22.') ||
os = 'jammy' if os.start_with?('ubuntu_22.') ||
os.start_with?('linuxmint_21.')

os = 'centos_6' if (os.start_with?('amzn_') && os != 'amzn_2') ||
os = 'centos6' if (os.start_with?('amzn_') && os != 'amzn_2') ||
os.start_with?('centos_6') ||
(os.empty? && File.read('/etc/centos-release').start_with?('CentOS release 6'))

os = 'centos_7' if (os.start_with?('amzn_2') && !os.start_with?('amzn_20')) ||
os.start_with?('rhel_7.')
os = 'centos7' if os.start_with?('rhel_7.') ||
os.start_with?('centos_7')

os = 'centos8' if os.start_with?('rocky_8') ||
os.start_with?('centos_8') ||
os.start_with?('rhel_8.')

os = 'centos_8' if os.start_with?('rocky_8') || os.start_with?('rhel_8.')
os = 'amazonlinux2' if os.start_with?('amzn_2') && !os.start_with?('amzn_20')

os_based_on_debian_9 = os.start_with?('debian_9') ||
os.start_with?('deepin')
os = 'debian_9' if os_based_on_debian_9
os = 'stretch' if os_based_on_debian_9

os = 'debian_10' if !os_based_on_debian_9 && os.start_with?('debian')
os = 'buster' if !os_based_on_debian_9 && os.start_with?('debian')

os = 'archlinux' if os.start_with?('arch_') ||
os.start_with?('manjaro_')

architecture = RbConfig::CONFIG['host_cpu'] == 'x86_64' ? 'amd64' : 'i386'

"#{os}_#{architecture}"
architecture = case RbConfig::CONFIG['host_cpu']
when /x86_64/
%w[xenial focal bionic stretch buster].any?{|d| os == d} ? 'amd64' : 'x86_64'
when /aarch64/
%w[xenial focal bionic stretch buster].any?{|d| os == d} ? 'arm64' : 'aarch64'
when /arm64/
'arm64'
else
os.start_with?('centos') ? 'i686' : 'i386'
end

[os, architecture]
when /darwin/
'macos_cocoa'
['macos', 'cocoa']
else
'unknown'
['unknown', 'unknown']
end

download_path = DOWNLOAD_LINK_MATRIX[os_architecture[0]][os_architecture[1]]

suffix = "#{os_architecture[0]}_#{os_architecture[1]}"
suffix = ENV['WKHTMLTOPDF_HOST_SUFFIX'] unless ENV['WKHTMLTOPDF_HOST_SUFFIX'].to_s.empty?

gem_directory = File.expand_path(File.dirname(__FILE__))
downloaded_file_name = gem_directory + "/" + download_path.split('/')[-1]

binary = "#{__FILE__}_#{suffix}"
binary = "#{gem_directory}/#{binary}".sub('bin/bin', 'bin') unless binary.start_with?(gem_directory)

Dir.chdir(gem_directory) do
if !File.exist?("#{binary}.gz")
`curl -LJ --silent "#{download_path}" --output "#{downloaded_file_name}"`
`rpm2cpio "#{downloaded_file_name}" | cpio -idm --quiet` if downloaded_file_name.end_with?('.rpm')
`dpkg -x "#{downloaded_file_name}" .` if downloaded_file_name.end_with?('.deb')
`tar -xf "#{downloaded_file_name}"` if downloaded_file_name.end_with?('.tar.xz')
if downloaded_file_name.end_with?('.pkg')
`xar -xf "#{downloaded_file_name}"; cat Payload | gunzip -dc | cpio -i`
`cp "#{gem_directory}/usr/local/share/wkhtmltox-installer/wkhtmltox.tar.gz" "#{binary}.gz"`
elsif downloaded_file_name.end_with?('.tar.xz')
`gzip --best --quiet -c usr/bin/wkhtmltopdf > #{binary}.gz`
else
`gzip --best --quiet -c usr/local/bin/wkhtmltopdf > #{binary}.gz`
end
end

if File.exist?("#{binary}.gz") && !File.exist?(binary)
File.open binary, 'wb', 0o755 do |file|
Zlib::GzipReader.open("#{binary}.gz") { |gzip| file << gzip.read }
if File.exist?("#{binary}.gz") && !File.exist?("#{binary}")
File.open binary, 'wb', 0o755 do |file|
Zlib::GzipReader.open("#{binary}.gz") { |gzip| file << gzip.read }
end
end
end

unless File.exist? binary
raise 'Invalid platform, must be running on Ubuntu 16.04/18.04/20.04/22.04, ' \
'CentOS 6/7/8, Debian 9/10, Archlinux amd64, or Intel-based Cocoa macOS ' \
"(missing binary: #{binary})."
end
unless File.exist?("#{binary}")
raise 'Invalid platform, must be running on Ubuntu 16.04/18.04/20.04/22.04, ' \
'CentOS 6/7/8, Debian 9/10, Archlinux amd64, or Intel-based Cocoa macOS ' \
"(missing binary: #{binary})."
end

exec *$*.unshift(binary)
exec *$*.unshift(binary)
end
Binary file removed bin/wkhtmltopdf_archlinux_amd64.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_centos_6_amd64.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_centos_6_i386.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_centos_7_amd64.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_centos_7_i386.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_centos_8_amd64.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_debian_10_amd64.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_debian_10_i386.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_debian_9_amd64.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_debian_9_i386.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_macos_cocoa.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_ubuntu_16.04_amd64.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_ubuntu_16.04_i386.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_ubuntu_18.04_amd64.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_ubuntu_18.04_i386.gz
Binary file not shown.
Binary file removed bin/wkhtmltopdf_ubuntu_20.04_amd64.gz
Binary file not shown.
Loading