How to checkout repo inside the docker in GitHub action

Viewed 1366

Scenario:

I have built an image and uploaded into ECR.

Now in GitHub action, I would need to pull that image and run some command against the git repo.

However, it seems like actions/checkout is not able to be executed inside docker due to write permission error.

Wonder if there’s a way to solve this problem.

1 Answers

Checking out a repository using actions/checkout@v2 works for me, but only if I switch to a user with sufficient privileges for the default directory, for example root or 1001 (the user used by GitHub Actions):

jobs:
  my-job-name:
    runs-on: ubuntu-latest
    container:
      image: ghcr.io/<whatever>
      options: --user root
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

This seems to originate from my custom container image and not from the action.

If you don't want to run as root, there is a related issue, stating that you can also first get ownership of the directory before checking-out the repository.

Related