Github job checkout code in container on custom path

Hello everybody,

I am working on setting up a ci workflow for this docker-based project, see GitHub - b310-digital/mindmapper: Mindmapping made simple: Host and create your own mindmaps. Share your mindmap sessions with others and collaborate on mindmaps. .

The basic idea is to build, tag and push the docker image in one job. In other jobs, I want to use the built docker image and execute tests and linter inside the docker container. This ensures that ci workflow and local development setup produce the same results.

The problem is that the github actions/checkout@v2 checks out the code to path /__w/mindmapper/mindmapper, but the project docker image expects the code to be in /home/node/app. This means that executing tests and linter inside the docker container fail because the code is missing :frowning: . My goal is to have code checked out (or be mounted) to /home/node/app inside the docker container.

name: Docker Image CI

on:
    push:
        branches:
            - main
    pull_request:
        branches:
            - main

jobs:
    mindmapper-build:
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v2
            - name: Set up QEMU
              uses: docker/setup-qemu-action@v1
            - name: Set up Docker Buildx
              uses: docker/setup-buildx-action@v1
            - name: Login to GitHub Container Registry
              uses: docker/login-action@v1
              with:
                  registry: ghcr.io
                  username: ${{ github.repository_owner }}
                  password: ${{ secrets.GITHUB_TOKEN }}
            - name: Build and export to Docker
              uses: docker/build-push-action@v2
              with:
                  context: .
                  target: development
                  push: true
                  tags: |
                      ghcr.io/b310-digital/mindmapper/ci:${{ github.sha }}-dev

    mindmapper-backend-lint-2:
        runs-on: ubuntu-latest
        needs: mindmapper-build
        defaults:
            run:
                # This working directory is also defined in the WORKDIR defined in the project's Dockerfile
                working-directory: /home/node/app
        container:
            image: ghcr.io/b310-digital/mindmapper/ci:${{ github.sha }}-dev
            options: --user root

        steps:
            # This checkout action adds the repository code to `/__w/mindmapper/mindmapper` and not to `/home/node/app` wherethe container expects the code to be
            - uses: actions/checkout@v2
            # Fails because code is not present in /home/node/app
            - run: npm --prefix mindmapper-backend run lint

I have the feeling that the answer is obvious, but I cannot find it. Thank you very much for the help.

Cheers

That’s not possible with a job container, though you could manually start a container that does it. Adding a symlink inside the job might work depending on what exactly those tools expect. Otherwise configuring the tools to use a different location might be your best option.