CONTINUOUS INTEGRATION

Gotenberg’s API in your CI, ready in seconds

Tests that make PDFs through Gotenberg start it as a service container next to the job. Marqius Kern answers Gotenberg’s API from a 41 MB image, so the service is pulled, started and healthy in seconds, and your tests call the same routes with the same fields.

The service, in your workflow:

services:
  gotenberg:
    image: marqius/kern
    ports:
      - 3000:3000

In our test on a fresh Ubuntu machine, started as a GitHub-hosted runner starts a service, it was pulled, started and healthy in under 6 seconds.

THE WORKFLOW

One service, one health check.

Save this as .github/workflows/pdf.yml in your repository. GitHub starts the service before the steps, waits until its health check passes, and the steps reach it at http://localhost:3000:

.github/workflows/pdf.yml
name: PDF tests
on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    services:
      gotenberg:
        image: marqius/kern
        ports:
          - 3000:3000
        options: >-
          --health-cmd "curl --fail --silent http://localhost:3000/health"
          --health-interval 1s
          --health-timeout 2s
          --health-retries 30
    env:
      GOTENBERG_URL: http://localhost:3000
    steps:
      - uses: actions/checkout@v4
      - name: Make a PDF through the service
        run: |
          echo '<h1>Hello from CI</h1>' > index.html
          curl --fail --silent --show-error --form files=@index.html "$GOTENBERG_URL/forms/chromium/convert/html" -o hello.pdf
          head -c 5 hello.pdf
      - name: Run your tests
        run: echo "Your test command here, with GOTENBERG_URL set to $GOTENBERG_URL"

Put your own test command in the last step. Most Gotenberg client libraries read the server’s address from a setting or an environment variable; GOTENBERG_URL is set for the whole job here.

Already on Gotenberg? The same workflow works with image: gotenberg/gotenberg:8: Marqius Kern takes Gotenberg’s routes, form fields, flags and health check, so switching is the image line, and switching back is too.

A job that runs in a container (container: in the job) reaches the service by its name instead: http://gotenberg:3000.

WITH YOUR LICENCE

Your key, as a secret.

Open-source projects’ CI runs are free with a Community licence, and run without a key too: Marqius Kern then says in its log that it has none.

To run with your key, add it as a repository secret named MARQIUS_LICENCE (Settings, Secrets and variables, Actions), and pass it to the service:

     services:
       gotenberg:
         image: marqius/kern
+        env:
+          MARQIUS_LICENCE: ${{ secrets.MARQIUS_LICENCE }}

The service’s log then starts with the line marqius-kern is licensed to and your name.

LICENCE

Free for open source. Licensed for business.

Personal, teaching and open-source use is free with a Community licence, including open-source projects’ CI runs and documentation builds.

  1. Get your free key on marqius.com/licence/marqius-kern, then sign in with Google.
  2. Tick “I’ll use Marqius Kern only for personal, teaching or open-source work”.
  3. Get my free key, then Copy key.
  4. Set it as the variable MARQIUS_LICENCE on your server.

Anything done by or for a business, including internal tools and client work, needs a paid licence. See the plans and prices.

QUESTIONS & ANSWERS

Questions

How do I run Gotenberg in GitHub Actions?

As a service container: list it under services in the job, with its port and a health check, and the steps reach it at http://localhost:3000. With Marqius Kern’s image, the same API comes from a 41 MB image.

How long does the service take to be ready?

In our test on a fresh Ubuntu machine, started as a GitHub-hosted runner starts a service: Marqius Kern’s image was pulled in 4 seconds and healthy under 2 seconds after it started, under 6 seconds in all; Gotenberg 8’s image took 54 seconds to pull, 56 in all. A runner that has the image already skips the pull.

Why does my job wait before the first step?

GitHub starts the services first and waits until each health check passes. A smaller image is pulled sooner, and a server that answers its health check at once lets the steps start sooner.

How do the steps reach the service?

At http://localhost:3000 when the job runs on the runner, as it does unless the job has a container of its own; then by the service’s name, http://gotenberg:3000.

Does it need a licence in CI?

Open-source projects’ CI is free with a Community licence, and works without a key. A business’s CI needs a paid licence: add it as the MARQIUS_LICENCE secret and pass it to the service.

READY WHEN YOU ARE

Change one line. Keep your documents.

Compare your own documents side by side first, as the switching guide shows, then switch.