Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 2

Job Fails When Using Custom Container Image

Solved! Go to Solution.

Following this advice I configured a custom container image for my build job. After doing so, the workflow fails at a step that works fine when no custom container is defined. I'm not sure what the problem is but my guess is possibly something to do with the workspace directory mount inside the container?

 

The step named "Init Submodules & Checkout Branches" works fine with this config:

 

name: CI
on: [push]
env:
  REPO: ${{ github.event.repository.name }}

jobs:
  #=========#
  # 1. Lint #
  #=========#
  lint:
    if: "! contains(toJSON(github.event.commits.*.msg), '[skip-ci]')"
    runs-on: ubuntu-18.04
    strategy:
      matrix:
        lang: ['php:7.4.1', 'php:5.6.40', 'php:5.2.17', 'js:12.14.0']

    steps:
      #======================#
      # 1.1 Initialize Repos #
      #======================#
      - name: Maybe Change REPO Environment Variable
        if: contains(github.event.repository.name, 'submodule')
        shell: bash
        run: echo "::set-env name=REPO::Divi"

      - name: Checkout Meta Repo
        uses: actions/checkout@v2
        with:
          repository: elegantthemes/meta
          ref: master
          path: workspace/meta
          token: ${{ secrets.ETSTAGING_TOKEN }}

      - name: Init Submodules & Checkout Branches
        working-directory: workspace/meta
        shell: bash
        run: |
          git config --global http.extraheader "$(git config --get http.https://github.com/.extraheader)"
          git config --global protocol.version 2
          git submodule update --init --force --depth=1 --remote core-products
          cd core-products
          git submodule update --init --force --depth=1 --remote --recursive ${REPO}
          cd "${REPO}"
          git checkout "${GITHUB_REF}" || true
          git submodule foreach --recursive "git -c \"http.extraheader=$auth\" -c protocol.version=2 checkout \"${GITHUB_REF}\" || true"

 

It fails when I define a container though:

 

name: CI
on: [push]
env:
  REPO: ${{ github.event.repository.name }}

jobs:
  #=========#
  # 1. Lint #
  #=========#
  lint:
    if: "! contains(toJSON(github.event.commits.*.msg), '[skip-ci]')"
    runs-on: ubuntu-18.04
    strategy:
      matrix:
        lang: ['php:7.4.1', 'php:5.6.40', 'php:5.2.17', 'js:12.14.0']

    container: elegantthemes/gh-action-lint-${{ matrix.lang }}
    steps:
      #======================#
      # 1.1 Initialize Repos #
      #======================#
      - name: Maybe Change REPO Environment Variable
        if: contains(github.event.repository.name, 'submodule')
        shell: bash
        run: echo "::set-env name=REPO::Divi"

      - name: Checkout Meta Repo
        uses: actions/checkout@v2
        with:
          repository: elegantthemes/meta
          ref: master
          path: workspace/meta
          token: ${{ secrets.ETSTAGING_TOKEN }}

      - name: Init Submodules & Checkout Branches
        working-directory: workspace/meta
        shell: bash
        run: |
          git config --global http.extraheader "$(git config --get http.https://github.com/.extraheader)"
          git config --global protocol.version 2
          git submodule update --init --force --depth=1 --remote core-products
          cd core-products
          git submodule update --init --force --depth=1 --remote --recursive ${REPO}
          cd "${REPO}"
          git checkout "${GITHUB_REF}" || true
          git submodule foreach --recursive "git -c \"http.extraheader=$auth\" -c protocol.version=2 checkout \"${GITHUB_REF}\" || true"

 

Here are the logs from the failed workflow run. Any idea what the problem is?

 

Update: 

It looks like the only environment variables applied to the container are GITHUB_ACTIONS and HOME.  AFAICT, GITHUB_WORKSPACE is not applied when the runner starts the container. Not sure if this is even related to the issue though.

 

Update 2:

My image has git 2.17.1 but it looks like the checkout action requires git 2.18+. Rebuilding my images with latest git  now to see if that resolves the issue.

1 Reply
Solution
GitHub Partner
Message 2 of 2

Re: Job Fails When Using Custom Container Image

As your mentioned, you setup Git 2.17.1 in your Docker image, not Git 2.18 or higher. When executing checkout step, if Git 2.18 or higher is not in the PATH, the checkout action will fallback to use the GitHub REST API to download the files. The API only can download the files as a ZIP with specified commit version and then extract the ZIP, it will not create a local branch. So when executing git command in the directory where the downloaded files are located, it will return the error “not a git repository”.

There are 2 workarounds as references:

  1. Directly execute the git command to checkout the repository and it submodules. Reference here: https://git-scm.com/book/en/v2/Git-Tools-Submodules
  2. Setup Git 2.18 or higher in the Docker image, and also need to set Git to the container's PATH.