diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50d3e31..c43dc1b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,11 +7,25 @@ on: - dev jobs: - testing: runs-on: ubuntu-latest + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: techstart-fashion + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping -h localhost -uroot -proot" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + env: DATABASE_URL: mysql://root:root@localhost:3306/techstart-fashion + steps: - name: Checkout uses: actions/checkout@v3 @@ -19,22 +33,13 @@ jobs: - name: Install dependencies run: cd backend && npm install - - name: Start volume - run: docker volume create db - - - name: Start database - run: | - docker run -d \ - --name db \ - -e MYSQL_ROOT_PASSWORD=root \ - -e MYSQL_DATABASE=techstart-fashion \ - -p 3306:3306 \ - -v db:/var/lib/mysql \ - --restart always \ - mysql - - name: Wait for database - run: docker exec db mysqladmin --silent --wait=30 -uroot -proot ping || exit 1 + run: | + until nc -z localhost 3306; do + echo "Waiting for MySQL to be ready..." + sleep 2 + done + echo "MySQL is ready." - name: Test run: cd backend && npm run test