I'm trying to generate a static website with jekyll, including the generation of a per article pdf file.
Here is my jekyll module :
require 'pdfkit'
module Jekyll
Jekyll::Hooks.register :site, :post_write do |post|
post.posts.docs.each do |post|
filename = post.site.dest + post.id + ".pdf"
dirname = File.dirname(filename)
Dir.mkdir(dirname) unless File.exists?(dirname)
kit = PDFKit.new(post.content, :page_size => 'Letter')
kit.stylesheets << './css/bootstrap.min.css'
kit.to_file(filename)
end
end
end
Everything is working properly on my workstation, so i suppose there is a problem with my pipeline.
Here is my .gitlab-ci.yml :
stages:
- build
- deploy
build:
image: registry.gitlab.com/thalion59fr/jekyll-ci:master
stage: build
script:
- bundle
- gem list
- bundle exec jekyll build --trace
only:
- master
artifacts:
paths:
- _site/
deploy:
image: registry.gitlab.com/thalion59fr/jekyll-ci:master
stage: deploy
script:
- aero deploy --directory _site
dependencies:
- build
And the Dockerfile of the registry.gitlab.com/thalion59fr/jekyll-ci:master image : (based on this one, I will make a proper Dockerfile with inheritance later)
FROM alpine
MAINTAINER David Von Lehman <david@aerobatic.com>
ENV LANGUAGE=en_US
ENV LANG=en_US.UTF-8
ENV JEKYLL_ENV=development
ENV LC_ALL=en_US
RUN apk --update add zlib-dev build-base libxml2-dev \
libxslt-dev readline-dev \
libffi-dev ruby-dev yaml-dev zlib libxml2 \
build-base ruby-io-console readline libxslt ruby yaml libffi nodejs ruby-irb \
ruby-json ruby-rake ruby-rdoc git bash curl ttf-freefont fontconfig
RUN gem clean && gem install --no-ri --no-rdoc \
bundler json:1.8.6 nokogiri:1.7.0.1 jekyll:3.4.0 wkhtmltopdf-installer jekyll-pdf
RUN rm -rf /usr/lib/ruby/gems/*/cache/*.gem
# Install the aerobatic-cli globally
RUN npm install -g aerobatic-cli@1.0.33
And finaly, the error message :
$ bundle exec jekyll build --trace
Configuration file: /builds/Thalion59fr/jekyll-wulin/_config.yml
Source: /builds/Thalion59fr/jekyll-wulin
Destination: /builds/Thalion59fr/jekyll-wulin/_site
Incremental build: disabled. Enable with --incremental
Generating...
bundler: failed to load command: jekyll (/usr/bin/jekyll)
Errno::EPIPE: Broken pipe
/usr/lib/ruby/gems/2.3.0/gems/pdfkit-0.8.2/lib/pdfkit/pdfkit.rb:64:in `write'
/usr/lib/ruby/gems/2.3.0/gems/pdfkit-0.8.2/lib/pdfkit/pdfkit.rb:64:in `puts'
/usr/lib/ruby/gems/2.3.0/gems/pdfkit-0.8.2/lib/pdfkit/pdfkit.rb:64:in `block in to_pdf'
/usr/lib/ruby/gems/2.3.0/gems/pdfkit-0.8.2/lib/pdfkit/pdfkit.rb:63:in `popen'
/usr/lib/ruby/gems/2.3.0/gems/pdfkit-0.8.2/lib/pdfkit/pdfkit.rb:63:in `to_pdf'
/usr/lib/ruby/gems/2.3.0/gems/pdfkit-0.8.2/lib/pdfkit/pdfkit.rb:76:in `to_file'
/builds/Thalion59fr/jekyll-wulin/_plugins/topdf.rb:31:in `block (2 levels) in <module:Jekyll>'
/builds/Thalion59fr/jekyll-wulin/_plugins/topdf.rb:19:in `each'
/builds/Thalion59fr/jekyll-wulin/_plugins/topdf.rb:19:in `block in <module:Jekyll>'
/usr/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/hooks.rb:98:in `block in trigger'
/usr/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/hooks.rb:97:in `each'
/usr/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/hooks.rb:97:in `trigger'
/usr/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/site.rb:211:in `write'
/usr/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/site.rb:71:in `process'
/usr/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/command.rb:26:in `process_site'
/usr/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/commands/build.rb:63:in `build'
/usr/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/commands/build.rb:34:in `process'
/usr/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/commands/build.rb:16:in `block (2 levels) in init_with_program'
/usr/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
/usr/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
/usr/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
/usr/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
/usr/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
/usr/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/exe/jekyll:13:in `<top (required)>'
/usr/bin/jekyll:22:in `load'
/usr/bin/jekyll:22:in `<top (required)>'
ERROR: Job failed: exit code 1
Thanks for your help ! David
I finally solved the problem by modifying the building-image:
And by installing wkhtmltopdf via the packages manager AFTER the gimli gem :
As you can see, I gave up using jekyll to generate the pdf. I use gimli to generate pdf documents before the "jekyll build". Then I use some liquid markup in the posts layout :
xvfb is here to allow wkhtmltopdf to be execute headless, and the script comme from here : https://gist.github.com/tyleramos/3744901
It's not realy neat, but it will do for now. I now have to work on the css, but it's going to be easy with gimli.