Skip to content

Commit

Permalink
Add support for x386 debian 11/12, amd64 debian 11/12, arm64 debian9/…
Browse files Browse the repository at this point in the history
…10/11/12 with test

- Added binaries for x386 debian 11/12, amd64 debian 11/12, arm64 debian9/10/11 and made them available for testing on GitHub Actions
  - Since we can't select arm64 platform in GitHub Actions on github.com, use [docker/setup-qemu-action](https://github.com/docker/setup-qemu-action) to virtually realize testing on arm64.
  - It was difficult to use the same docker-compose.yml and Dockerfile for x86 and arm64, so create docker-compose.yml and Dockerfile for arm64 version.
- Since we are using docker to test on x86 ubuntu, we don't need multiple versions of Ruby on ubuntu, so we only use one version of Ruby.
- Fixed a bug that the order of arguments of `assert_equal` method was reversed.
- Loosened conditions for passing the test
  - Only 0.12.6.1 binaries are available under newer distributions such as debian11, so make the tests pass.
- Add Ruby 3.2 to CI matrix
- Fix a broken archlinux test
  - Fix an error that the libssl library could not be found
- update github actions
  • Loading branch information
willnet committed Nov 21, 2023
1 parent f7928e1 commit c64d327
Show file tree
Hide file tree
Showing 22 changed files with 204 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .docker/Dockerfile-archlinux
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ FROM archlinux

ENV DEBIAN_FRONTEND noninteractive

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

CMD /root/wkhtmltopdf_binary_gem/bin/wkhtmltopdf --version
8 changes: 8 additions & 0 deletions .docker/Dockerfile-debian_10_arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM --platform=arm64 debian:10

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
8 changes: 8 additions & 0 deletions .docker/Dockerfile-debian_11
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM debian:11

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
8 changes: 8 additions & 0 deletions .docker/Dockerfile-debian_11_arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM --platform=arm64 debian:11

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
8 changes: 8 additions & 0 deletions .docker/Dockerfile-debian_12
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM debian:12

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
8 changes: 8 additions & 0 deletions .docker/Dockerfile-debian_12_arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM --platform=arm64 debian:12

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
8 changes: 8 additions & 0 deletions .docker/Dockerfile-debian_9_arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM --platform=arm64 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
54 changes: 49 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ name: CI
on: [push, pull_request]

jobs:
tests:
runs-on: ${{ matrix.os }}
tests-on-x86-mac:
runs-on: macos-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
ruby-version: ['2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1']
ruby-version: ['2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install Ruby ${{ matrix.ruby-version }} on ${{ matrix.os }}
uses: ruby/setup-ruby@v1
Expand All @@ -22,3 +21,48 @@ jobs:

- name: Run tests with Ruby ${{ matrix.ruby-version }} on ${{ matrix.os }}
run: bundle exec rake
tests-on-x86-docker:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.2']
steps:
- uses: actions/checkout@v4

- name: Install Ruby ${{ matrix.ruby-version }} on ubuntu
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}

- name: Install dependencies
run: bundle install

- name: Run tests on docker(x86)
run: bundle exec rake
tests-on-arm:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.2']
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- uses: actions/checkout@v4
- name: Install Ruby ${{ matrix.ruby-version }} on ubuntu
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- name: Run tests on docker(arm64)
env:
ARM: 1
COMPOSE_FILE: docker-compose-arm.yml
run: |
set -xeu
sudo apt update
sudo apt-get install -y docker-compose
bundle install
bundle exec rake
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ bin/wkhtmltopdf_centos_7_amd64
bin/wkhtmltopdf_centos_8_amd64
bin/wkhtmltopdf_debian_9_amd64
bin/wkhtmltopdf_debian_10_amd64
bin/wkhtmltopdf_debian_11_amd64
bin/wkhtmltopdf_debian_12_amd64
bin/wkhtmltopdf_debian_9_arm64
bin/wkhtmltopdf_debian_10_arm64
bin/wkhtmltopdf_debian_11_arm64
bin/wkhtmltopdf_debian_12_arm64
bin/wkhtmltopdf_macos_cocoa
bin/wkhtmltopdf_ubuntu_16.04_amd64
bin/wkhtmltopdf_ubuntu_18.04_amd64
Expand Down
21 changes: 17 additions & 4 deletions bin/wkhtmltopdf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
require 'rbconfig'
require 'zlib'

def architecture
case RbConfig::CONFIG['host_cpu']
when *%w[arm64 aarch64 arch64]
'arm64'
when 'x86_64'
'amd64'
else
'i386'
end
end

suffix = case RbConfig::CONFIG['host_os']
when /linux/
os = `. /etc/os-release 2> /dev/null && echo ${ID}_${VERSION_ID}`.strip
Expand Down Expand Up @@ -44,13 +55,15 @@ suffix = case RbConfig::CONFIG['host_os']
os.start_with?('deepin')
os = 'debian_9' if os_based_on_debian_9

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

os = 'debian_11' if !os_based_on_debian_9 && os.start_with?('debian_11')

os = 'debian_12' if !os_based_on_debian_9 && os.start_with?('debian_12')

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

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

"#{os}_#{architecture}"
when /darwin/
'macos_cocoa'
Expand All @@ -70,7 +83,7 @@ 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 ' \
'CentOS 6/7/8, Debian 9/10/11/12, Archlinux amd64, Debian 9/10/11/12 arm64, or Intel-based Cocoa macOS ' \
"(missing binary: #{binary})."
end

Expand Down
Binary file added bin/wkhtmltopdf_debian_10_arm64.gz
Binary file not shown.
Binary file added bin/wkhtmltopdf_debian_11_amd64.gz
Binary file not shown.
Binary file added bin/wkhtmltopdf_debian_11_arm64.gz
Binary file not shown.
Binary file added bin/wkhtmltopdf_debian_11_i386.gz
Binary file not shown.
Binary file added bin/wkhtmltopdf_debian_12_amd64.gz
Binary file not shown.
Binary file added bin/wkhtmltopdf_debian_12_arm64
Binary file not shown.
Binary file added bin/wkhtmltopdf_debian_12_arm64.gz
Binary file not shown.
Binary file added bin/wkhtmltopdf_debian_12_i386.gz
Binary file not shown.
Binary file added bin/wkhtmltopdf_debian_9_arm64.gz
Binary file not shown.
30 changes: 30 additions & 0 deletions docker-compose-arm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: '3'

services:
debian_9:
build:
context: .
dockerfile: .docker/Dockerfile-debian_9_arm
volumes:
- .:/root/wkhtmltopdf_binary_gem

debian_10:
build:
context: .
dockerfile: .docker/Dockerfile-debian_10_arm
volumes:
- .:/root/wkhtmltopdf_binary_gem

debian_11:
build:
context: .
dockerfile: .docker/Dockerfile-debian_11_arm
volumes:
- .:/root/wkhtmltopdf_binary_gem

debian_12:
build:
context: .
dockerfile: .docker/Dockerfile-debian_12_arm
volumes:
- .:/root/wkhtmltopdf_binary_gem
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ services:
volumes:
- .:/root/wkhtmltopdf_binary_gem

debian_11:
build:
context: .
dockerfile: .docker/Dockerfile-debian_11
volumes:
- .:/root/wkhtmltopdf_binary_gem

debian_12:
build:
context: .
dockerfile: .docker/Dockerfile-debian_12
volumes:
- .:/root/wkhtmltopdf_binary_gem

centos_6:
build:
context: .
Expand All @@ -64,6 +78,7 @@ services:
dockerfile: .docker/Dockerfile-centos_8
volumes:
- .:/root/wkhtmltopdf_binary_gem

rockylinux_8:
build:
context: .
Expand Down
56 changes: 38 additions & 18 deletions test/test_with_docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,82 @@ def macos?
ENV['RUNNER_OS'] && ENV['RUNNER_OS'] == 'macOS'
end

def arm?
ENV['ARM']
end

class WithDockerTest < Minitest::Test
SETUP = begin
`docker-compose build --no-cache` unless macos?
end
`docker-compose build --no-cache` if !macos?
end

def test_centos_6
test with: 'centos_6'
test_on_x86 with: 'centos_6'
end

def test_centos_7
test with: 'centos_7'
test_on_x86 with: 'centos_7'
end

def test_centos_8
test with: 'centos_8'
test_on_x86 with: 'centos_8'
end

def test_debian_9
test with: 'debian_9'
test_on_x86_and_arm with: 'debian_9'
end

def test_debian_10
test with: 'debian_10'
test_on_x86_and_arm with: 'debian_10'
end

def test_debian_11
test_on_x86_and_arm with: 'debian_11'
end

def test_debian_12
test_on_x86_and_arm with: 'debian_12'
end

def test_with_ubuntu_16
test with: 'ubuntu_16.04'
test_on_x86 with: 'ubuntu_16.04'
end

def test_with_ubuntu_18
test with: 'ubuntu_18.04'
test_on_x86 with: 'ubuntu_18.04'
end

def test_with_ubuntu_20
test with: 'ubuntu_20.04'
test_on_x86 with: 'ubuntu_20.04'
end

def test_with_ubuntu_22
test with: 'ubuntu_22.04'
test_on_x86 with: 'ubuntu_22.04'
end

def test_with_archlinux
test with: 'archlinux'
test_on_x86 with: 'archlinux'
end

def test_rockylinux_8
test with: 'rockylinux_8'
test_on_x86 with: 'rockylinux_8'
end

def test_with_macos
assert_equal(`bin/wkhtmltopdf --version`.strip, 'wkhtmltopdf 0.12.6 (with patched qt)') if macos?
assert_equal('wkhtmltopdf 0.12.6 (with patched qt)', `bin/wkhtmltopdf --version`.strip) if macos?
end

private

def test(with:)
assert_equal(`docker-compose run --rm #{with}`.strip, 'wkhtmltopdf 0.12.6 (with patched qt)') unless macos?
def test_on_x86(with:)
test_on_docker(with: with) if !macos? && !arm?
end

def test_on_x86_and_arm(with:)
test_on_docker(with: with) unless macos?
end

def test_on_docker(with:)
assert_match(/wkhtmltopdf 0\.12\.6(.1)? \(with patched qt\)/, `docker-compose run --rm #{with}`.strip)
end
end

0 comments on commit c64d327

Please sign in to comment.