feat(CI/CD Deployer): init, tests & config

This commit is contained in:
2025-11-05 11:10:40 +01:00
parent fa0c288e07
commit 94a5794bab
4 changed files with 194 additions and 1 deletions

View File

@@ -8,6 +8,7 @@
"require": {
"php": "^8.3",
"andreia/filament-nord-theme": "^2.0",
"deployer/deployer": "^7.5",
"filament/filament": "^4.0",
"inertiajs/inertia-laravel": "^2.0",
"laravel/fortify": "^1.31",

56
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "2dad60120da5595265fa9bae98361025",
"content-hash": "8575e8552839730222fc96c1b3864d9f",
"packages": [
{
"name": "andreia/filament-nord-theme",
@@ -799,6 +799,60 @@
},
"time": "2025-09-16T12:23:56+00:00"
},
{
"name": "deployer/deployer",
"version": "v7.5.12",
"source": {
"type": "git",
"url": "https://github.com/deployphp/deployer.git",
"reference": "efc71dac9ccc86b3f9946e75d50cb106b775aae2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/deployphp/deployer/zipball/efc71dac9ccc86b3f9946e75d50cb106b775aae2",
"reference": "efc71dac9ccc86b3f9946e75d50cb106b775aae2",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": "^8.0|^7.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.64",
"pestphp/pest": "^3.3",
"phpstan/phpstan": "^1.4",
"phpunit/php-code-coverage": "^11.0",
"phpunit/phpunit": "^11.4"
},
"bin": [
"bin/dep"
],
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Anton Medvedev",
"email": "anton@medv.io"
}
],
"description": "Deployment Tool",
"homepage": "https://deployer.org",
"support": {
"docs": "https://deployer.org/docs",
"issues": "https://github.com/deployphp/deployer/issues",
"source": "https://github.com/deployphp/deployer"
},
"funding": [
{
"url": "https://github.com/sponsors/antonmedv",
"type": "github"
}
],
"time": "2025-02-19T16:45:27+00:00"
},
{
"name": "dflydev/dot-access-data",
"version": "v3.0.3",

71
deploy.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
namespace Deployer;
require 'recipe/laravel.php';
require 'contrib/rsync.php';
// Environment
$env = $_SERVER['CI_COMMIT_REF_NAME'] === 'master' ? 'PROD' : 'STAGING';
$envConfig = [
'host' => $_SERVER[$env . '_SSH_HOST'],
'port' => $_SERVER[$env . '_SSH_PORT'] ?? 22,
'user' => $_SERVER[$env . '_SSH_USER'],
'path' => $_SERVER[$env . '_SSH_PATH'],
'repository' => $_SERVER['CI_REPOSITORY_URL'],
];
// GLOBAL
set('repository', $envConfig['repository']);
set('keep_releases', 3);
set('bin/php', '/usr/bin/php8.3');
set('bin/composer', '{{bin/php}} /usr/local/bin/composer');
set('composer_options', '--no-dev --optimize-autoloader --no-interaction --prefer-dist');
set('rsync_src', __DIR__);
set('rsync_dest', '{{release_path}}');
set('rsync', [
'exclude' => [
'.git',
'node_modules',
'vendor',
'.env',
'.gitlab-ci.yml',
'deploy.php',
],
'flags' => 'rz',
'options' => ['delete'],
]);
// HOSTS
host($envConfig['host'])
->setPort($envConfig['port'])
->set('remote_user', $envConfig['user'])
->set('deploy_path', $envConfig['path']);
// TASKS
task('deploy:vendors', function () {
run('cd {{release_path}} && {{bin/composer}} install {{composer_options}}');
});
task('build:assets', function () {
run('cd {{release_path}} && npm ci && npm run build');
});
task('artisan:storage:link', artisan('storage:link'));
task('artisan:cache:clear', artisan('cache:clear'));
task('artisan:config:clear', artisan('config:clear'));
task('artisan:migrate', artisan('migrate --force'));
task('deploy', [
'deploy:prepare',
'deploy:vendors',
'build:assets',
'artisan:storage:link',
'artisan:config:clear',
'artisan:cache:clear',
'artisan:migrate',
'deploy:publish',
'deploy:publish',
]);
after('deploy:failed', 'deploy:unlock');

67
gitlab-ci.yml Normal file
View File

@@ -0,0 +1,67 @@
image: node:22-bullseye
stages:
- preparation
- build
- test
- deploy
variables:
DEPLOY_PATH: /var/www/myapp
GIT_SUBMODULE_STRATEGY: recursive
NODE_ENV: production
# Dependencies installation
prepare:
stage: preparation
before_script:
- apt-get update -y
- apt-get install -y php8.3 php8.3-cli php8.3-mbstring php8.3-xml php8.3-bcmath php8.3-curl unzip git curl mariadb-client
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
script:
- php -v
- composer -V
- node -v
- npm ci
- composer install --no-dev --no-interaction --prefer-dist
artifacts:
paths:
- vendor/
- node_modules/
expire_in: 1h
# Front compilation with vite
build:
stage: build
script:
- npm run build
artifacts:
paths:
- public/build/
- public/assets/
- public/css/
- public/js/
- public/images/
expire_in: 1h
# Tests Laravel
test:
stage: test
script:
- php artisan test --without-tty
# Deploy
deploy:
stage: deploy
rules:
- if: '$CI_COMMIT_REF_NAME == "release" || $CI_COMMIT_REF_NAME == "master"'
before_script:
- apt-get update -y && apt-get install -y ssh
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
script:
- composer global require deployer/deployer
- ~/.composer/vendor/bin/dep deploy -vvv
# Laravel pint ?