Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Actions: How to run docker-compose in windows-latest and macos-latest?

I have a GitHub Action workflow for PRs which contains a job performing some NET Core dummy tests that require an instance of both PostgreSQL + SQL Serve.

The job definition:

run-test:
  needs: [lint-commit, lint-code]
  strategy:
    matrix:
      os: [ubuntu-latest]
      dotnet: [3.1.201]
    fail-fast: false
  runs-on: ${{ matrix.os }}
  steps:
    - uses: actions/checkout@v2
    - name: Build the docker-compose stack
      run: docker-compose --file "./MessingUp.Tests/docker-compose.yml" up --detach
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: ${{ matrix.dotnet }}
    - name: Run Tests
      run: dotnet test

and the docker compose file, ./MessingUp.Tests/docker-compose.yml:

version: "3.7"

services:

  sqlserver:
    image: mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04
    restart: unless-stopped
    environment:
      - MSSQL_PID=Express
      - ACCEPT_EULA=Y
      - SA_PASSWORD=MyPassword!
    ports:
      - 1433:1433

  postgres:
    image: postgres:12.3-alpine
    restart: unless-stopped
    environment:
      - POSTGRES_HOST_AUTH_METHOD=trust
      - POSTGRES_DB=postgres
      - POSTGRES_USER=root
      - POSTGRES_PASSWORD=root
    command:
      - postgres
      - -c
      - max_prepared_transactions=100
    ports:
      - 5432:5432
    # Needed because the postgres container does not provide a health check
    healthcheck:
      test: pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 40s

Long story short, the code above works, my only issue is that I'd like to know how to use docker-compose in case I'm not only using ubuntu-latest:

os: [windows-latest, macos-latest, ubuntu-latest]

Cause in non-ubuntu-latest OSs, it doesn't really work:

windows-latest:

 Build the docker-compose stack15s
##[error]Process completed with exit code 1.
Run docker-compose --file "./MessingUp.Tests/docker-compose.yml" up --detach
Creating network "messinguptests_default" with the default driver
Pulling sqlserver (mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04)...
2019-CU3-ubuntu-18.04: Pulling from mssql/server
image operating system "linux" cannot be used on this platform
##[error]Process completed with exit code 1.

macos-latest:

 Build the docker-compose stack0s
##[error]Process completed with exit code 127.
Run docker-compose --file "./MessingUp.Tests/docker-compose.yml" up --detach
/Users/runner/runners/2.169.1/work/_temp/ccb3e6a1-fc89-4099-9bf2-2f4ca4bb1fb8.sh: line 1: docker-compose: command not found
##[error]Process completed with exit code 127.

Output when using ubuntu-latest:

Build the docker-compose stack43s

Run docker-compose --file "./MessingUp.Tests/docker-compose.yml" up --detach
Creating network "messinguptests_default" with the default driver
Pulling sqlserver (mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04)...
2019-CU3-ubuntu-18.04: Pulling from mssql/server
Digest: sha256:e064843673f08f22192c044ffa6a594b0670a3eb3f9ff7568dd7a65a698fc4d6
Status: Downloaded newer image for mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04
Pulling postgres (postgres:12.3-alpine)...
12.3-alpine: Pulling from library/postgres
Digest: sha256:bd975ce4ddb0cf271a3c0132afaa16894ccdbadd0a1e81aa5d1b12727bb43779
Status: Downloaded newer image for postgres:12.3-alpine
Creating messinguptests_sqlserver_1 ... 
Creating messinguptests_postgres_1  ... 

Creating messinguptests_sqlserver_1 ... done

Creating messinguptests_postgres_1  ... done
like image 692
Natalie Perret Avatar asked Oct 26 '22 20:10

Natalie Perret


1 Answers

I see two distinct issues why docker-compose command fails on windows-latest and mac-os.

windows-latest runner uses Windows containers as a Docker backend engine and you are trying to use Linux based image (mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04) with Windows backend which is not compatible. This is why the error message appears:

Pulling sqlserver (mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04)...
2019-CU3-ubuntu-18.04: Pulling from mssql/server
image operating system "linux" cannot be used on this platform

If you visit the DockerHub page dedicated for the image used you can read:

Official images for Microsoft SQL Server on Linux for Docker Engine.

You should use a different image that is compatible with Windows containers backend in order to get the container running on windows-latest. Currently, there are two official images that are compatible with Windows containers backend:

  • microsoft/mssql-server-windows-developer
  • microsoft/mssql-server-windows-express

Both the above DockerHub pages mentions:

Microsoft SQL Server Express for Windows Containers.

Having that in mind you should use one of them on windows-latest runner to get the docker-compose command working.

You can read more about SQLServer in Docker here.

Speaking about macos-latest runner, the error message in this case is slightly different:

/Users/runner/runners/2.169.1/work/_temp/ccb3e6a1-fc89-4099-9bf2-2f4ca4bb1fb8.sh: line 1: docker-compose: command not found

There is no docker-compose binary installed so it cannot be found. If you see the GitHub Actions Virtual Environments page you can explore the software included on each runner. Both, ubuntu-latest and windows-latest have already the docker-compose command included but not the macos-latest. It does not contain it due to some licensing issues. You have to install the command by your own using brew:

[...]
runs-on: macOS-latest
steps:
  - name: Install docker
    run: |
      brew install docker docker-machine docker-compose
      sudo docker –version
[...]
like image 60
Marcin Kłopotek Avatar answered Jan 02 '23 21:01

Marcin Kłopotek