diff --git a/.docker/Dockerfile-centos_6 b/.docker/Dockerfile-centos_6 new file mode 100644 index 00000000..b15c5d5a --- /dev/null +++ b/.docker/Dockerfile-centos_6 @@ -0,0 +1,5 @@ +FROM centos:6 + +RUN yum install -y ruby libjpeg-turbo libpng libXrender fontconfig libXext + +CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version diff --git a/.docker/Dockerfile-centos_7 b/.docker/Dockerfile-centos_7 new file mode 100644 index 00000000..00923778 --- /dev/null +++ b/.docker/Dockerfile-centos_7 @@ -0,0 +1,5 @@ +FROM centos:7 + +RUN yum install -y ruby libjpeg-turbo libpng libXrender fontconfig libXext + +CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version diff --git a/.docker/Dockerfile-debian_8 b/.docker/Dockerfile-debian_8 new file mode 100644 index 00000000..da33b16e --- /dev/null +++ b/.docker/Dockerfile-debian_8 @@ -0,0 +1,8 @@ +FROM debian:8 + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update +RUN apt-get install -y ruby libjpeg62-turbo libpng12-0 libxrender1 libfontconfig1 libxext6 + +CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version diff --git a/.docker/Dockerfile-debian_9 b/.docker/Dockerfile-debian_9 new file mode 100644 index 00000000..cc66dfaf --- /dev/null +++ b/.docker/Dockerfile-debian_9 @@ -0,0 +1,8 @@ +FROM debian:9 + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update +RUN apt-get install -y ruby libjpeg62-turbo libpng16-16 libxrender1 libfontconfig1 libxext6 + +CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version diff --git a/.docker/Dockerfile-ubuntu_14.04 b/.docker/Dockerfile-ubuntu_14.04 new file mode 100644 index 00000000..d3eb10ae --- /dev/null +++ b/.docker/Dockerfile-ubuntu_14.04 @@ -0,0 +1,8 @@ +FROM ubuntu:14.04 + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update +RUN apt-get install -y ruby libjpeg8 libxrender1 libfontconfig1 + +CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version diff --git a/.docker/Dockerfile-ubuntu_16.04 b/.docker/Dockerfile-ubuntu_16.04 new file mode 100644 index 00000000..9a971b1b --- /dev/null +++ b/.docker/Dockerfile-ubuntu_16.04 @@ -0,0 +1,8 @@ +FROM ubuntu:16.04 + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update +RUN apt-get install -y ruby libjpeg8 libxrender1 libfontconfig1 + +CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version diff --git a/.docker/Dockerfile-ubuntu_18.04 b/.docker/Dockerfile-ubuntu_18.04 new file mode 100644 index 00000000..d2e46a11 --- /dev/null +++ b/.docker/Dockerfile-ubuntu_18.04 @@ -0,0 +1,8 @@ +FROM ubuntu:18.04 + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update +RUN apt-get install -y ruby libjpeg8 libxrender1 libfontconfig1 + +CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version diff --git a/.gitignore b/.gitignore index 088af208..4f3a9da5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,17 @@ pkg/* +bin/wkhtmltopdf_centos_6_amd64 +bin/wkhtmltopdf_centos_7_amd64 +bin/wkhtmltopdf_debian_8_amd64 +bin/wkhtmltopdf_debian_9_amd64 +bin/wkhtmltopdf_macos_cocoa +bin/wkhtmltopdf_macos_carbon +bin/wkhtmltopdf_ubuntu_14.04_amd64 +bin/wkhtmltopdf_ubuntu_16.04_amd64 +bin/wkhtmltopdf_ubuntu_18.04_amd64 +bin/wkhtmltopdf_centos_6_i386 +bin/wkhtmltopdf_centos_7_i386 +bin/wkhtmltopdf_debian_8_i386 +bin/wkhtmltopdf_debian_9_i386 +bin/wkhtmltopdf_ubuntu_14.04_i386 +bin/wkhtmltopdf_ubuntu_16.04_i386 +bin/wkhtmltopdf_ubuntu_18.04_i386 diff --git a/CHANGELOG b/CHANGELOG index f50dd6b0..c9f7b39e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +# 0.12.5 +Update `wkhtmltopdf` binaries with version 0.12.5 + # 0.12.4 Update `wkhtmltopdf` binaries with version 0.12.4 diff --git a/README.md b/README.md new file mode 100644 index 00000000..34646012 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# wkhtmltopdf_binary_gem + +## Extracting binaries + +Hints for extracting binaries from https://wkhtmltopdf.org/downloads.html (dpkg and rpm2cpio is available on Homebrew). + +Debian/Ubuntu + + dpkg -x wkhtmltox_0.12.5-1.trusty_amd64.deb . + +CentOS + + rpm2cpio wkhtmltox-0.12.5-1.centos7.x86_64.rpm | cpio -idmv + +macOS + + xar -xf wkhtmltox-0.12.5-1.macos-cocoa.pkg + cat Payload | gunzip -dc | cpio -i + +## Compression + +Binaries should be compressed with `gzip --best` after extracting. The matching binary will be extracted on first +execution of `bin/wkhtmltopdf`. + +## Testing with Docker + +Make sure you have Docker and Docker Compose installed (see https://docs.docker.com/compose/install/ for more +information). + +There are Dockerfiles for the supported Linux based distributions under `.docker`. You can build them all with +`docker-compose build` and run each individually with e.g. `docker-compose run ubuntu_18.04`. + +There also is a rudimentary minitest test that simply invokes `docker-compose run` for each distribution and +expects to see the output of `wkhtmltopdf --version`. Just run `rake` to run it. + +You can clean up after testing with `docker-compose down --rmi all`. diff --git a/Rakefile b/Rakefile index c9a610ae..b0c5ab7d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,15 @@ require 'rubygems' require 'rubygems/package_task' +require 'rake/testtask' spec = eval(File.new("wkhtmltopdf-binary.gemspec").readlines.join("\n")) Gem::PackageTask.new(spec) do |pkg| pkg.need_tar = true end + +Rake::TestTask.new do |t| + t.libs << 'test' +end + +desc 'Run tests' +task default: :test diff --git a/bin/wkhtmltopdf b/bin/wkhtmltopdf index 313aa602..eabe5b12 100755 --- a/bin/wkhtmltopdf +++ b/bin/wkhtmltopdf @@ -8,14 +8,38 @@ # of the License at http://www.apache.org/licenses/LICENSE-2.0 require 'rbconfig' +require 'zlib' suffix = case RbConfig::CONFIG['host_os'] -when /linux/ - (RbConfig::CONFIG['host_cpu'] == 'x86_64') ? 'linux_amd64' : 'linux_x86' -when /darwin/ - 'darwin_x86' -else - raise "Invalid platform. Must be running on linux or intel-based Mac OS." + when /linux/ + os = `. /etc/os-release 2> /dev/null && echo ${ID}_${VERSION_ID}`.strip + + # CentOS 6 doesn't have `/etc/os-release`. + if os.empty? && File.read('/etc/centos-release').start_with?('CentOS release 6') + os = 'centos_6' + end + + architecture = RbConfig::CONFIG['host_cpu'] == 'x86_64' ? 'amd64' : 'i386' + + "#{os}_#{architecture}" + when /darwin/ + RbConfig::CONFIG['host_cpu'] == 'x86_64' ? 'macos_cocoa' : 'macos_carbon' + else + 'unknown' + end + +binary = "#{__FILE__}_#{suffix}" + +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 + +unless File.exist? binary + raise 'Invalid platform, must be running on Ubuntu 14.04/16.04/18.04 ' \ + 'CentOS 6/7, Debian 8/9, or intel-based macOS ' \ + "(missing binary: #{binary})." end -system *$*.unshift("#{__FILE__}_#{suffix}") +system *$*.unshift(binary) diff --git a/bin/wkhtmltopdf_centos_6_amd64.gz b/bin/wkhtmltopdf_centos_6_amd64.gz new file mode 100755 index 00000000..0c0e008b Binary files /dev/null and b/bin/wkhtmltopdf_centos_6_amd64.gz differ diff --git a/bin/wkhtmltopdf_centos_6_i386.gz b/bin/wkhtmltopdf_centos_6_i386.gz new file mode 100755 index 00000000..fd81a618 Binary files /dev/null and b/bin/wkhtmltopdf_centos_6_i386.gz differ diff --git a/bin/wkhtmltopdf_centos_7_amd64.gz b/bin/wkhtmltopdf_centos_7_amd64.gz new file mode 100755 index 00000000..f19061dd Binary files /dev/null and b/bin/wkhtmltopdf_centos_7_amd64.gz differ diff --git a/bin/wkhtmltopdf_centos_7_i386.gz b/bin/wkhtmltopdf_centos_7_i386.gz new file mode 100755 index 00000000..18a96019 Binary files /dev/null and b/bin/wkhtmltopdf_centos_7_i386.gz differ diff --git a/bin/wkhtmltopdf_darwin_x86 b/bin/wkhtmltopdf_darwin_x86 deleted file mode 100755 index 23c6042c..00000000 Binary files a/bin/wkhtmltopdf_darwin_x86 and /dev/null differ diff --git a/bin/wkhtmltopdf_debian_8_amd64.gz b/bin/wkhtmltopdf_debian_8_amd64.gz new file mode 100755 index 00000000..14ad9c63 Binary files /dev/null and b/bin/wkhtmltopdf_debian_8_amd64.gz differ diff --git a/bin/wkhtmltopdf_debian_8_i386.gz b/bin/wkhtmltopdf_debian_8_i386.gz new file mode 100755 index 00000000..16ab0bd5 Binary files /dev/null and b/bin/wkhtmltopdf_debian_8_i386.gz differ diff --git a/bin/wkhtmltopdf_debian_9_amd64.gz b/bin/wkhtmltopdf_debian_9_amd64.gz new file mode 100755 index 00000000..705708a5 Binary files /dev/null and b/bin/wkhtmltopdf_debian_9_amd64.gz differ diff --git a/bin/wkhtmltopdf_debian_9_i386.gz b/bin/wkhtmltopdf_debian_9_i386.gz new file mode 100755 index 00000000..d6c8b7a2 Binary files /dev/null and b/bin/wkhtmltopdf_debian_9_i386.gz differ diff --git a/bin/wkhtmltopdf_linux_amd64 b/bin/wkhtmltopdf_linux_amd64 deleted file mode 100755 index a90fa1c7..00000000 Binary files a/bin/wkhtmltopdf_linux_amd64 and /dev/null differ diff --git a/bin/wkhtmltopdf_linux_x86 b/bin/wkhtmltopdf_linux_x86 deleted file mode 100755 index 2870aeb9..00000000 Binary files a/bin/wkhtmltopdf_linux_x86 and /dev/null differ diff --git a/bin/wkhtmltopdf_macos_carbon.gz b/bin/wkhtmltopdf_macos_carbon.gz new file mode 100755 index 00000000..584d8707 Binary files /dev/null and b/bin/wkhtmltopdf_macos_carbon.gz differ diff --git a/bin/wkhtmltopdf_macos_cocoa.gz b/bin/wkhtmltopdf_macos_cocoa.gz new file mode 100755 index 00000000..8bc0b68e Binary files /dev/null and b/bin/wkhtmltopdf_macos_cocoa.gz differ diff --git a/bin/wkhtmltopdf_ubuntu_14.04_amd64.gz b/bin/wkhtmltopdf_ubuntu_14.04_amd64.gz new file mode 100755 index 00000000..ba264b8e Binary files /dev/null and b/bin/wkhtmltopdf_ubuntu_14.04_amd64.gz differ diff --git a/bin/wkhtmltopdf_ubuntu_14.04_i386.gz b/bin/wkhtmltopdf_ubuntu_14.04_i386.gz new file mode 100755 index 00000000..7cfd134e Binary files /dev/null and b/bin/wkhtmltopdf_ubuntu_14.04_i386.gz differ diff --git a/bin/wkhtmltopdf_ubuntu_16.04_amd64.gz b/bin/wkhtmltopdf_ubuntu_16.04_amd64.gz new file mode 100755 index 00000000..c7689951 Binary files /dev/null and b/bin/wkhtmltopdf_ubuntu_16.04_amd64.gz differ diff --git a/bin/wkhtmltopdf_ubuntu_16.04_i386.gz b/bin/wkhtmltopdf_ubuntu_16.04_i386.gz new file mode 100755 index 00000000..d81692d9 Binary files /dev/null and b/bin/wkhtmltopdf_ubuntu_16.04_i386.gz differ diff --git a/bin/wkhtmltopdf_ubuntu_18.04_amd64.gz b/bin/wkhtmltopdf_ubuntu_18.04_amd64.gz new file mode 100755 index 00000000..5831e409 Binary files /dev/null and b/bin/wkhtmltopdf_ubuntu_18.04_amd64.gz differ diff --git a/bin/wkhtmltopdf_ubuntu_18.04_i386.gz b/bin/wkhtmltopdf_ubuntu_18.04_i386.gz new file mode 100755 index 00000000..a7a2f539 Binary files /dev/null and b/bin/wkhtmltopdf_ubuntu_18.04_i386.gz differ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..00d47ea0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,52 @@ +version: '3' + +services: + + ubuntu_14.04: + build: + context: . + dockerfile: .docker/Dockerfile-ubuntu_14.04 + volumes: + - .:/root/wkhtmltopdf_binary_gem + + ubuntu_16.04: + build: + context: . + dockerfile: .docker/Dockerfile-ubuntu_16.04 + volumes: + - .:/root/wkhtmltopdf_binary_gem + + ubuntu_18.04: + build: + context: . + dockerfile: .docker/Dockerfile-ubuntu_18.04 + volumes: + - .:/root/wkhtmltopdf_binary_gem + + debian_8: + build: + context: . + dockerfile: .docker/Dockerfile-debian_8 + volumes: + - .:/root/wkhtmltopdf_binary_gem + + debian_9: + build: + context: . + dockerfile: .docker/Dockerfile-debian_9 + volumes: + - .:/root/wkhtmltopdf_binary_gem + + centos_6: + build: + context: . + dockerfile: .docker/Dockerfile-centos_6 + volumes: + - .:/root/wkhtmltopdf_binary_gem + + centos_7: + build: + context: . + dockerfile: .docker/Dockerfile-centos_7 + volumes: + - .:/root/wkhtmltopdf_binary_gem diff --git a/test/test_with_docker.rb b/test/test_with_docker.rb new file mode 100644 index 00000000..05e18c71 --- /dev/null +++ b/test/test_with_docker.rb @@ -0,0 +1,46 @@ +require 'minitest/autorun' + +class WithDockerTest < Minitest::Test + # Run code before a group of test (see: https://github.com/seattlerb/minitest#how-to-run-code-before-a-group-of-tests) + SETUP = begin + `docker-compose build` + end + + def test_centos_6 + test with: 'centos_6' + end + + def test_centos_7 + test with: 'centos_7' + end + + def test_debian_8 + test with: 'debian_8' + end + + def test_debian_9 + test with: 'debian_9' + end + + def test_with_ubuntu_14 + test with: 'ubuntu_14.04' + end + + def test_with_ubuntu_16 + test with: 'ubuntu_16.04' + end + + def test_with_ubuntu_18 + test with: 'ubuntu_18.04' + end + + def test_with_macos + assert_equal `bin/wkhtmltopdf --version`.strip, 'wkhtmltopdf 0.12.5 (with patched qt)' + end + + private + + def test(with:) + assert_equal `docker-compose run --rm #{with}`.strip, 'wkhtmltopdf 0.12.5 (with patched qt)' + end +end diff --git a/wkhtmltopdf-binary.gemspec b/wkhtmltopdf-binary.gemspec index 713ed937..bb676814 100644 --- a/wkhtmltopdf-binary.gemspec +++ b/wkhtmltopdf-binary.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = "wkhtmltopdf-binary" - s.version = "0.12.4" + s.version = "0.12.5" s.license = "Apache-2.0" s.author = "Zakir Durumeric" s.email = "zakird@gmail.com" @@ -12,4 +12,6 @@ Gem::Specification.new do |s| s.has_rdoc = false s.executables << "wkhtmltopdf" s.require_path = '.' + + s.add_development_dependency "minitest" end