Search code examples
pythondocker-composegithub-actionsbuildx

Github actions docker-compose with buildx error (list index out of range)


I'm trying to use buildx to build a compose file in a github actions file and I'm having the next error:

[104392] Failed to execute script docker-compose
Traceback (most recent call last):
  File "docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 81, in main
  File "compose/cli/main.py", line 203, in perform_command
  File "compose/metrics/decorator.py", line 18, in wrapper
  File "compose/cli/main.py", line 380, in build
  File "compose/project.py", line 519, in build
  File "compose/project.py", line 501, in build_service
  File "compose/service.py", line 1133, in build
  File "compose/service.py", line 1950, in build
IndexError: list index out of range
Error: Process completed with exit code 255.

Before the error appears all Dockerfile steps are done correctly in the build stack step and after this the image exporting should start.

I don't have any error when I try to run the same command in the github runner I deployed in one of my nodes under the _work directory.

When I remove the setup buildx step from the github actions yaml file the error is not showing up.

Here is integration.yaml (github actions):

name: Continuous Integration

on:
  pull_request:
    branches: '*'


jobs:
  integration:
    name: Setup Docker
    runs-on: self-hosted
    steps:

      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup Buildx
        uses: docker/setup-buildx-action@v1
        with:
          install: true
          driver-opts: >-
            image=moby/buildkit:master

      - name: Cache main image layers
        uses: actions/cache@v2
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-  

      - name: Prepare environment
        run: |
          cp .npmrc.example .npmrc
          cp .env.example .env
      
      - name: Build stack
        run: |
          DOCKER_BUILDKIT=1 ./devops ci build --no-cache --build-arg USER_UID=$(id -u) --build-arg USER_GID=$(id -g) app

The devops script is basically executing the next command:

docker-compose -f docker-compose.yml -f .docker/overrides/docker-compose.ci.yml build --build-arg USER_UID=$(id -u) --build-arg USER_GID=$(id -g) app

Could this be related with some labels I'm defining in the docker-compose file?

I would appreciate any answer because I didn't find any other issue related to this.

Thank you :)


Solution

  • We faced the same issue today and found two solutions.

    First, the correct solution (at least for our case): Use docker compose (with the space) command instead of docker-compose (with the hyphen) command. A little more on the difference between the two here.

    In our case we ran apt upgrade and docker compose got updated without us realizing it. We now had both docker-compose and docker compose installed but were still running the old docker-compose command.

    If that doesn't work: @leehambley describes the issue in more detail here and here. In the first link he mentions that setting COMPOSE_DOCKER_CLI_BUILD=0 fixes the issue although that disables the docker buildkit, which may have some consequences so be more careful.

    You can do this by running COMPOSE_DOCKER_CLI_BUILD=0 docker-compose build ....