Taldorr
Taldorr

Reputation: 195

docker-compose MySQL container for automated testing with GithubActions

I have GitHub repo and I want to use GithubActions to automatically execute unit Tests with every pull request.

I already set up a workflow file:

   name: CI

on:
  pull_request:
    branches: [ master ]

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
      - name: Install
        run: npm ci
      - name: Linter
        run: npm run lint
      - name: Build
        run: npm run build
      - name: Docker
        run: docker-compose up -d
      - name: Wait / Sleep
        uses: jakejarvis/[email protected]
        with:
          time: '10s'
      - run: | 
          docker ps
          cat ./dumps/backup.sql | docker exec -i mysql-development_1 /usr/bin/mysql -u root --password=password        
      - name: Test
        run: npm test

As I need to insert the tables first, I want to insert a dump which does work on my machine with the exact same command used here.

However, the Action fails with this error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
read unix @->/var/run/docker.sock: read: connection reset by peer
cat: write error: Broken pipe
##[error]Process completed with exit code 1.

How can I access the database within GithubActions?

docker-compose.yml:

version: '3'

services:

  mysql-development:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: test_db
    ports:
      - "3308:3306"

Upvotes: 0

Views: 1130

Answers (1)

Taldorr
Taldorr

Reputation: 195

To anyone who might run into the same problem:

https://github.blog/changelog/2020-02-21-github-actions-breaking-change-ubuntu-virtual-environments-will-no-longer-start-the-mysql-service-automatically/

You just need to start the mysql-service manually and perhaps wait for a couple of seconds

Upvotes: 1

Related Questions