gitlab CI/CD部署laravel项目



我想通过ci/cd gitlab部署我的laravel项目,我有一个部署我的项目的问题。我正试图通过gitlab CI部署我的laravel项目到cpanel。我在这个项目中使用部署包,但是当我把我的提交推到gitlab和管道失败时。

当我把我的提交推到gitlab并在我的管道中得到这个错误时,我得到了这个错误错误图片

这是我的deploy.php代码

<?php
declare(strict_types=1);
return [
'default' => 'basic',
'strategies' => [
],
'hooks' => [
'start' => [
],
'build' => [
],
'ready' => [
'artisan:storage:link',
'artisan:view:clear',
'artisan:config:cache',
'artisan:migrate',
'artisan:horizon:terminate',
],
'done' => [
'fpm:reload',
],
'success' => [
],
'fail' => [
],
'rollback' => [
'fpm:reload',
],
],
'options' => [
'application' => env('APP_NAME', 'Laravel'),
'repository' => 'git@gitlab.com/mygroup/project.git',
'php_fpm_service' => 'php7.4-fpm',
],
'hosts' => [
'mywebsite.com' => [
'deploy_path' => '/home/sfd/public_html/nas',
'user' => 'deployer',
],
],
'localhost' => [
],

'include' => [
],
'custom_deployer_file' => false,
];

这是我的gitlab-ci。yml代码

image: edbizarro/gitlab-ci-pipeline-php:7.4
stages:
- preparation
- building
- deploy

composer:
stage: preparation
script:
- php -v
- composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts --no-suggest
- cp .env.example .env
- php artisan key:generate
artifacts:
paths:
- vendor/
- .env
expire_in: 1 days
when: always
cache:
paths:
- vendor/
yarn:
stage: preparation
script:
- yarn --version
- yarn install --pure-lockfile
artifacts:
paths:
- node_modules/
expire_in: 1 days
when: always

.build-production-assets:
stage: building
dependencies:
- composer
- yarn
script:
- cp .env.example .env
- echo "PUSHER_APP_ID=$PUSHER_LIVE_APP_ID" >> .env
- echo "PUSHER_APP_KEY=$PUSHER_LIVE_APP_KEY" >> .env
- echo "PUSHER_APP_SECRET=$PUSHER_LIVE_APP_SECRET" >> .env
- yarn --version
- yarn run production --progress false
artifacts:
paths:
- public/css/
- public/js/
- public/fonts/
- public/mix-manifest.json
expire_in: 1 days
when: always
only:
- dev
.init_ssh_live: &init_ssh_live |
mkdir -p ~/.ssh
echo -e "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
[[ -f /.dockerenv ]] && echo -e "Host *ntStrictHostKeyChecking nonn" > ~/.ssh/config

deploy:
stage: deploy
script:
- *init_ssh_live
- php artisan deploy my-website.com -s upload
environment:
name: live
url: https://my-website.com
only:
- dev

如本期所述

您收到的错误是由于部署器无法通过SSH连接到您的服务器。

你得到命令"rm -f /PATH/.dep/deploy.lock";失败了。因为这是部署过程在主机上执行的第一个命令。

所以仔细检查"使用SSH密钥与GitLab CI/cd"&;文档,查看是否缺少步骤,如:

  • 密码保护私钥(需要ssh-agent)
  • 一个丢失的ssh-key扫描,以确保远程主机被验证

在切换回你自己的项目之前,先试着让这个示例项目工作。

最新更新