'error in gitlab pipeline for Laravel project

I want to create a ci cd gitlab pipeline for Laravel project and steps of deployment contain some commands like below:

-composer install;

-PHP artisan migrate;

-PHP artisan optimize :clear;

this is my pipe line code

image:
  name: composer:latest
before_script:
  - echo "Before script"
services:
  - mysql:latest
  - redis:latest
building:
  stage: build
  script:
    - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
    - php artisan migrate --force
    - php artisan optimize:clear
testing:
  stage: test
  script:
    - php ./vendor/bin/phpunit
deploying:
  stage: deploy
  script:
    - echo "Deployed"

the first command execute very well but in second command I get this error and i do not know what happen in third command!! :

78 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
$ php artisan migrate --force
   Illuminate\Database\QueryException 
  could not find driver (SQL: select * from information_schema.tables where table_schema = forge and table_name = migrations and table_type = 'BASE TABLE')
  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:742
    738▕         // If an exception occurs when attempting to run a query, we'll format the error
    739▕         // message to include the bindings with SQL, which will make this exception a
    740▕         // lot more helpful to the developer instead of just the database's errors.
    741▕         catch (Exception $e) {
  ➜ 742▕             throw new QueryException(
    743▕                 $query, $this->prepareBindings($bindings), $e
    744▕             );
    745▕         }
    746▕     }
      +33 vendor frames 
  34  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Cleaning up project directory and file based variables
00:02
ERROR: Job failed: exit code 1


Solution 1:[1]

docker image composer:latest without MySQL driver.

you need to own your GitLab runner environment. like:

Test and deploy Laravel applications with GitLab CI/CD and Envoy | GitLab

# Set the base image for subsequent instructions
FROM php:7.4

# Update packages
RUN apt-get update

# Install PHP and composer dependencies
RUN apt-get install -qq git curl libmcrypt-dev libjpeg-dev libpng-dev libfreetype6-dev libbz2-dev

# Clear out the local repository of retrieved package files
RUN apt-get clean

# Install needed extensions
# Here you can install any other extension that you need during the test and deployment process
RUN docker-php-ext-install mcrypt pdo_mysql zip

# Install Composer
RUN curl --silent --show-error "https://getcomposer.org/installer" | php -- --install-dir=/usr/local/bin --filename=composer

# Install Laravel Envoy
RUN composer global require "laravel/envoy=~1.0"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mouson Chen