title: Jekyll : Generating file with PDFKit in a gitlab-ci pipeline
body: <p>I'm trying to generate a static website with jekyll, including the generation of a per article pdf file.</p>
  
  <p>Here is my jekyll module :</p>
  
  <pre><code>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 =&gt; 'Letter')
            kit.stylesheets &lt;&lt; './css/bootstrap.min.css'
            kit.to_file(filename)
        end
    end
  
  end
  </code></pre>
  
  <p>Everything is working properly on my workstation, so i suppose there is a problem with my pipeline.</p>
  
  <p>Here is my .gitlab-ci.yml :</p>
  
  <pre><code>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
  </code></pre>
  
  <p>And the Dockerfile of the registry.gitlab.com/thalion59fr/jekyll-ci:master image :
  (based on <a href="https://hub.docker.com/r/aerobatic/jekyll/" rel="nofollow noreferrer">this one</a>, I will make a proper Dockerfile with inheritance later)</p>
  
  <pre><code>FROM alpine
  MAINTAINER David Von Lehman &lt;david@aerobatic.com&gt;
  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 &amp;&amp; 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
  </code></pre>
  
  <p>And finaly, the error message :</p>
  
  <pre><code>$ 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 &lt;module:Jekyll&gt;'
    /builds/Thalion59fr/jekyll-wulin/_plugins/topdf.rb:19:in `each'
    /builds/Thalion59fr/jekyll-wulin/_plugins/topdf.rb:19:in `block in &lt;module:Jekyll&gt;'
    /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 `&lt;top (required)&gt;'
    /usr/bin/jekyll:22:in `load'
    /usr/bin/jekyll:22:in `&lt;top (required)&gt;'
  ERROR: Job failed: exit code 1
  </code></pre>
  
  <p>Thanks for your help !
  David</p>