Reputation: 65
I am using laravel-deployer package for deployment my project on my server.
I have the following gitlab-ci
file:
stages:
- build
- test
- deploy
image: lorisleiva/laravel-docker:7.4
.init_ssh: &init_ssh |
eval $(ssh-agent -s)
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
mkdir -p ~/.ssh
chmod 700 ~/.ssh
ssh-keyscan yourdomain.com >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
.change_file_permissions: &change_file_permissions |
find . -type f -not -path "./vendor/*" -exec chmod 664 {} \;
find . -type d -not -path "./vendor/*" -exec chmod 775 {} \;
composer:
stage: build
script:
- composer install --prefer-dist --no-ansi --no-interaction --no-progress
- cp .env.production .env
- php artisan key:generate
artifacts:
expire_in: 1 month
paths:
- vendor/
- .env
cache:
key: ${CI_COMMIT_REF_SLUG}-composer
paths:
- vendor/
npm:
stage: build
cache:
key: ${CI_COMMIT_REF_SLUG}-npm
paths:
- node_modules/
script:
- npm install
- npm run production
artifacts:
expire_in: 1 month
paths:
- node_modules/
- public/css/
- public/js/
production:
stage: deploy
script:
- *init_ssh
- *change_file_permissions
- cp .env.production .env
- pwd
- hostname
- php artisan deploy yourdomain.com -s upload
- cd /var/www/yourdomain.com/current
- cp /var/www/yourdomain.com/current/.env.production /var/www/yourdomain.com/shared/.env
- npm install
- npm run production
environment:
name: production
url: http://yourdomain.com
when: manual
only:
- master
It basically deploy laravel website, removes the previous version, copies the new one and changes its permissions so its readable by Nginx. All the steps are executed correctly but it always fails after it finishes with the following error:
✔
➤ Executing task artisan:migrate
✔
➤ Executing task deploy:symlink
✔
➤ Executing task deploy:unlock
✔
➤ Executing task cleanup
✔
➤ Executing task fpm:reload
✔
🚀 Successfully deployed in 16.63s
$ cd /var/www/yourdomain.com/current
/bin/bash: line 127: cd: /var/www/yourdomain.com/current: No such file or directory
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1
Even though the pipeline works, its bugging me that I can't get a Passed report badge.
Upvotes: 0
Views: 3762
Reputation: 1014
Use
npm install /var/www/yourdomain.com/current --verbose
npm run production --prefix /var/www/yourdomain.com/current
to avoid that error. And remove "cd" command.
Upvotes: 1