How to use github actions/checkout@v2 inside own docker container

Viewed 482

I have my own php image, which I would like to use for my project to run tests on.

container: rela589n/doctrine-event-sourcing-php:latest

services:
  test_db:
    image: postgres:13-alpine
    env:
      POSTGRES_DB: des
      POSTGRES_USER: des_user
      POSTGRES_PASSWORD: p@$$w0rd

steps:
  - uses: actions/checkout@v2

  - whatever_needed_to_run_tests_inside_container

This fails on checkout action with such error:

EACCES: permission denied, open '/__w/doctrine-event-sourcing/doctrine-event-sourcing/6977c4d4-3881-44e9-804e-ae086752556e.tar.gz'

And this is logical as in fresh docker container there's no such folder structure. What i thought to do is run checkout action inside virtual machine provided runs-on: ubuntu-20.04 and configure volume for docker so that it will have access to code. However I have no idea neither is it a good practice to do this way nor how to implement this. I guess even if it is possible to do this way it won't work for other actions.

2 Answers

Had the same issue when trying to use my own Docker image. In my case, installing everything I need on the fly was not an option, so I had to fix this issue. It appears that GitHub runs the Docker image with user 1001 named runner and group 121 named docker. After adding the group, adding the user and adding the user to sudoers the problem was solved. Notice that the checkout path starts with /_w which is strange. If I perform actions/checkout@v2 without my container, the path is /home/runner. Not sure how to solve that yet.

Thanks, this really helped me to find the issue when trying to deploy a CDK project from within a Docker container on Github Actions.

I was getting a permission denied error after checking out the code, and trying to deploy it.

Error: EACCES: permission denied, mkdir '/__w/arm-test/arm-test/cdk.out/asset.7d21b14f781f8b0e4ebb3b30c66614a80f71a2c1637298e5557a97662fce0abe'

This issue had the workaround of running the container with the same user and group as the Github Actions runner, so that it matched with the permissions of the source code directory: https://github.com/actions/runner/issues/691

jobs:
  configure:
    runs-on: ubuntu-latest
    outputs:
      uid_gid: ${{ steps.get-user.outputs.uid_gid }}
    steps:
      - id: get-user
        run: echo "::set-output name=uid_gid::$(id -u):$(id -g)"

  clone-and-install:
    needs: configure
    runs-on: ubuntu-latest
    container:
      image: mcr.microsoft.com/vscode/devcontainers/base:ubuntu
      options: --user ${{ needs.configure.outputs.uid_gid }}
    steps:
      - uses: actions/checkout@v2
Related