pandoc / dockerfiles

Dockerfiles for various pandoc images
GNU General Public License v2.0
364 stars 98 forks source link

pandoc/extra unexpected behaviour in Github Actions #212

Closed mikebell closed 1 year ago

mikebell commented 1 year ago

I'm trying to automate a markdown to pdf conversion using the pandoc/extra image in github actions:

name: CV to PDF
permissions:
  id-token: write
  contents: read

on: 
  push:
    paths:
      - content/cv.md
  workflow_dispatch:

jobs:
  convert:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - uses: docker://pandoc/extra:3.1.1.0
        with:
          args: content/cv.md --output=content/cv.pdf --template eisvogel --listings -V block-headings
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1-node16
        with:
          aws-region: eu-west-2
          role-to-assume: arn:aws:iam::261964097300:role/github-mikebellio-deploy

      - run: aws s3 mv content/cv.pdf s3://mikebell.io/cv/
        shell: bash

When this runs it gives the following error:

Run docker://pandoc/extra:3.1.1.0
  with:
    args: content/cv.md --output=content/cv.pdf --template eisvogel --listings -V block-headings
/usr/bin/docker run --name pandocextra3110_5bb396 --label c9a4a5 --workdir /github/workspace --rm -e "INPUT_ARGS" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_REPOSITORY_OWNER_ID" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_REPOSITORY_ID" -e "GITHUB_ACTOR_ID" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKFLOW_REF" -e "GITHUB_WORKFLOW_SHA" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_ENVIRONMENT" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e "ACTIONS_ID_TOKEN_REQUEST_URL" -e "ACTIONS_ID_TOKEN_REQUEST_TOKEN" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/mikebell.io/mikebell.io":"/github/workspace" pandoc/extra:3.1.1.0 content/cv.md --output=content/cv.pdf --template eisvogel --listings -V block-headings
Could not find data file templates/eisvogel.latex

Running locally works as expected and generates the PDF:

docker run --rm \
       --volume "$(pwd):/data" \
       --user $(id -u):$(id -g) \
       pandoc/extra:3.1.1.0 cv.md -o cv.pdf --template eisvogel --listings -V block-headings

Happy to provide more information.

CAinDE commented 1 year ago

I'm also having the same issue but it's happening locally and I'm also trying to automate this in a pipeline.

mikebell commented 1 year ago

@CAinDE I finally got around to looking into this again and figured it out, you need to explicitly call the path:

- uses: docker://pandoc/extra:3.1.1.0
        with:
          args: content/cv.md --output=content/cv.pdf --template /.pandoc/templates/eisvogel.latex --listings -V block-headings

Doing this works. I'm not fully sure what the intended behavior is supposed to be but will leave this issue open.

daamien commented 1 year ago

Hi @mikebell !

thanks for reporting this issue and for the detailed workaround.

The problem occurs because Github Actions runners will always redefine the value of $HOME environment variable to /github/home.

This is hardcoded and users can't overide it.

See https://github.com/actions/runner/issues/863

A basic workaround would be to add a symlink inside the pandoc/extra image, like this

mkdir -p /github/home
ln -s /root $HOME 

but I'm a bit reluctant to do that sort of ugly patch just because someone at Github decided to mess with $HOME without any clear justification...

mikebell commented 1 year ago

Hey thanks for getting in touch, completely understand it's not down to the containter to fix the issue.

Would you be willing to accept an updated readme with a section on running it on GHA? Potentially updating https://github.com/pandoc/pandoc-action-example with an example for using the extra image.

daamien commented 1 year ago

Sure !

This should be documented

mikebell commented 1 year ago

Sorry! Finally gotten round to making the PR https://github.com/pandoc/pandoc-action-example/pull/30