0

I have a docker compose project. The code doesn't compile in docker and exits with code 2 but GitHub passes the job and marks as done.

Yml file:

name: Docker Build

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
      - name: Docker build staging
        run: |
          docker compose -f docker-compose.yml up --build -d
  deploy:
    runs-on: [self-hosted, Linux, X64, staging]
    needs: build
    steps:
      - name: Checkout the files
        uses: actions/checkout@v3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
      - run: |
          
          docker compose -f docker-compose.yml up --build -d

Output:

Failed to solve: executor failed running [/bin/sh -c npm run staging:start]: exit code: 2
#91 CANCELED
Torchizm
  • 54
  • 6

2 Answers2

0

If there is anyone who is having this issue, the issue is bash. Actions can't detect errors when you start docker compose in bash script. Instead of this you can type the commands in script directly to the run command.

Torchizm
  • 54
  • 6
0

You can pass de exit code from image to GitHub action throw the command

docker compose -f docker-compose.yml up --build --exit-code-from {image name}
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
  • I think that's not a proper solution. When you have many microservices that would mean many image names and command will be large at this point. – Torchizm Jan 03 '23 at 10:44