Laravel 项目的 gitlab 管道错误

error in gitlab pipeline for Laravel project

我想为 Laravel 项目创建一个 ci cd gitlab 管道,部署步骤包含如下命令:

-作曲家安装;

-PHP artisan 迁移;

-PHP artisan 优化 :clear;

这是我的流水线代码

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"

第一个命令执行得很好,但在第二个命令中出现此错误,我不知道第三个命令中发生了什么!! :

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

docker 图像 composer:latest 没有 MySQL 驱动程序。

您需要拥有自己的 GitLab 运行器环境。喜欢:

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"