1

I Want to deploy my laravel project through ci/cd gitlab, I have a problem with deploying my project. i am trying to deploy my laravel project to cpanel through gitlab CI. I am using deployer package in this project but when i push my commit to gitlab and pipeline got failed.

I got this error when I push my commit to gitlab and got this error in my pipeline error image

here is my deploy.php code

<?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,

];

this is my gitlab-ci.yml code

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 *\n\tStrictHostKeyChecking no\n\n" > ~/.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

1 Answers1

1

As note in this issue

the error you're receiving is because Deployer cannot connect to your server via SSH.

You get The command "rm -f /PATH/.dep/deploy.lock" failed. because that's the first command being executed on your hosts from the deployment process.

So double-check the "Using SSH keys with GitLab CI/CD" documentation, to see if there are steps missing like:

  • a passphrase-protected private key (needing an ssh-agent)
  • a missing ssh-keyscan to make sure the remote host is verified

Try and make this example project work first, before switching back to your own.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250