Can't connect to mysql #1004
-
Good night!
Nothing seems to work. Am I just stupid? name: CI
on:
pull_request:
branches: [ "main", "develop" ]
jobs:
laravel-tests:
runs-on: ubuntu-22.04
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test
ports:
- 3306/tcp # -> here i also tried using 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: bcmatch, curl, dom, fileinfo, gd, imagick, intl, mbstring, openssl, pdo_mysql, soap, xml, zip # -> here I also tried a set of combination, who knows what might work that this stage
coverage: none
- name: Setup Node.js 22
uses: actions/[email protected]
with:
node-version: '22.x'
- name: Setup FFmpeg
uses: federicocarboni/[email protected]
# I was having problems with other workflows, or with this one, I don't really remember anymore at this point
- name: Remove possible conflicting env files
run: rm -f .env.example .env.testing .env.testing.example
- name: Copy .env
run: cp .env.ci .env
# I also tried removing this and the Cache composer dependencies step
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Install python and pip
run: sudo apt-get update --allow-releaseinfo-change && sudo apt-get install -y python3 python3-pip
- name: Install pdfmerge
run: pip install pdfmerge
- name: Install headless chrome required libs
run: |
sudo apt-get install -y \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libatspi2.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libdrm2 \
libexpat1 \
libgbm1 \
libglib2.0-0 \
libnspr4 \
libnss3 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libudev1 \
libuuid1 \
libx11-6 \
libx11-xcb1 \
libxcb-dri3-0 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxkbcommon0 \
libxrandr2 \
libxrender1 \
libxshmfence1 \
libxss1 \
libxtst6
- name: Install Node dependencies
run: npm ci
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Clear Config
run: php artisan config:clear
# This step is new, but I just get the errors here now, nothing changes
- name: Run Migration
run: php artisan migrate -v
- name: Execute Larastan
run: vendor/bin/phpstan analyse
- name: Execute Laravel Pint
run: vendor/bin/pint --test
- name: Execute tests via Pest
run: php artisan test --parallel My APP_NAME=Laravel
APP_ENV=testing
APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=America/Sao_Paulo
APP_URL=http://localhost
APP_LOCALE=pt_BR
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=pt_BR
APP_MAINTENANCE_DRIVER=file
# APP_MAINTENANCE_STORE=database
BCRYPT_ROUNDS=12
LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1 # this was the last attempt
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=root
SESSION_DRIVER=array
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null
BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database
CACHE_STORE=array
CACHE_PREFIX=
MEMCACHED_HOST=127.0.0.1
REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=127.0.0.1
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"
SMS_ZENVIA_URL=
SMS_ZENVIA_TOKEN=
SMS_ZENVIA_SENDER_ID=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}" |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
First make sure mysql service starts correctly in the second step (Initialize containers) In your env But, when you specify port on a service like this ports:
- 3306/tcp it maps port 3306 on the service container to a random free port on the host container. Then you cannot hard code a DB_PORT in your env. You have to access it using ${{ job.services.mysql.ports['3306'] }} in this case. Please try changing these steps - name: Run Migration
run: php artisan migrate -v
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }} and - name: Execute tests via Pest
run: php artisan test --parallel
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }} On a side note, there is a typo in your workflow |
Beta Was this translation helpful? Give feedback.
@filipescaglia
First make sure mysql service starts correctly in the second step (Initialize containers)
In your env
DB_HOST=127.0.0.1
is correct.But, when you specify port on a service like this
it maps port 3306 on the service container to a random free port on the host container. Then you cannot hard code a DB_PORT in your env. You have to access it using ${{ job.services.mysql.ports['3306'] }} in this case.
Please try changing these steps
and