feat(ci): add migration rollback and remove duplicate chown in Jenkinsfile
- Save pre-deploy SHA before git pull for automatic rollback - On migrate failure: git reset + migrate:rollback + reinstall deps + restart - Remove duplicate chown from Restart Services stage (already in Fix Permissions) - Clean up .deploy_prev_sha after deploy completes
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
.env
|
.env
|
||||||
deploy.sh
|
deploy.sh
|
||||||
|
.deploy_prev_sha
|
||||||
/node_modules
|
/node_modules
|
||||||
/vendor
|
/vendor
|
||||||
/sourcefiles
|
/sourcefiles
|
||||||
|
|||||||
Vendored
+25
-1
@@ -39,6 +39,7 @@ pipeline {
|
|||||||
steps {
|
steps {
|
||||||
dir("${APP_DIR}") {
|
dir("${APP_DIR}") {
|
||||||
sh 'git config --global --add safe.directory ${APP_DIR}'
|
sh 'git config --global --add safe.directory ${APP_DIR}'
|
||||||
|
sh 'DEPLOY_PREV_SHA=$(git rev-parse HEAD) && echo $DEPLOY_PREV_SHA > .deploy_prev_sha'
|
||||||
sh 'git reset --hard'
|
sh 'git reset --hard'
|
||||||
sh 'git pull origin master'
|
sh 'git pull origin master'
|
||||||
}
|
}
|
||||||
@@ -59,6 +60,26 @@ pipeline {
|
|||||||
sh 'docker exec ntspi-php php artisan migrate --force'
|
sh 'docker exec ntspi-php php artisan migrate --force'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
post {
|
||||||
|
failure {
|
||||||
|
dir("${APP_DIR}") {
|
||||||
|
sh '''
|
||||||
|
PREV_SHA=$(cat .deploy_prev_sha 2>/dev/null || echo "")
|
||||||
|
if [ -n "$PREV_SHA" ]; then
|
||||||
|
echo "Rolling back to $PREV_SHA"
|
||||||
|
git reset --hard $PREV_SHA
|
||||||
|
docker exec ntspi-php php artisan migrate:rollback --force || true
|
||||||
|
docker exec ntspi-php composer install --no-dev --no-interaction --prefer-dist --no-cache
|
||||||
|
docker exec ntspi-php php artisan cache:clear
|
||||||
|
docker exec ntspi-php php artisan config:clear
|
||||||
|
docker exec ntspi-php php artisan route:clear
|
||||||
|
docker exec ntspi-php php artisan view:clear
|
||||||
|
docker restart ntspi-nginx ntspi-php ntspi-php-queue
|
||||||
|
fi
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build Frontend') {
|
stage('Build Frontend') {
|
||||||
@@ -103,7 +124,6 @@ pipeline {
|
|||||||
stage('Restart Services') {
|
stage('Restart Services') {
|
||||||
steps {
|
steps {
|
||||||
dir("${APP_DIR}") {
|
dir("${APP_DIR}") {
|
||||||
sh 'docker exec -u root ntspi-php chown -R www-data:www-data storage bootstrap/cache'
|
|
||||||
sh 'docker restart ntspi-nginx ntspi-php ntspi-php-queue'
|
sh 'docker restart ntspi-nginx ntspi-php ntspi-php-queue'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,11 +158,15 @@ pipeline {
|
|||||||
post {
|
post {
|
||||||
success {
|
success {
|
||||||
echo "Deploy completed successfully"
|
echo "Deploy completed successfully"
|
||||||
|
dir("${APP_DIR}") {
|
||||||
|
sh 'rm -f .deploy_prev_sha'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
failure {
|
failure {
|
||||||
echo "Deploy failed. Check build logs in Jenkins."
|
echo "Deploy failed. Check build logs in Jenkins."
|
||||||
dir("${APP_DIR}") {
|
dir("${APP_DIR}") {
|
||||||
sh 'docker exec ntspi-php php artisan up || true'
|
sh 'docker exec ntspi-php php artisan up || true'
|
||||||
|
sh 'rm -f .deploy_prev_sha'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,6 @@
|
|||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fakerphp/faker": "^1.9.1",
|
"fakerphp/faker": "^1.9.1",
|
||||||
"laravel/breeze": "^1.25",
|
"laravel/breeze": "^1.25",
|
||||||
"laravel/pint": "^1.0",
|
|
||||||
"laravel/sail": "^1.18",
|
"laravel/sail": "^1.18",
|
||||||
"mockery/mockery": "^1.4.4",
|
"mockery/mockery": "^1.4.4",
|
||||||
"nunomaduro/collision": "^7.0",
|
"nunomaduro/collision": "^7.0",
|
||||||
|
|||||||
Generated
+1
-69
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "6cf6c43ee4ed42c7027f6bc6a208b519",
|
"content-hash": "6df5b3167c82bcd51f51f438281adf2b",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "alxdorosenco/porto-for-laravel",
|
"name": "alxdorosenco/porto-for-laravel",
|
||||||
@@ -11740,74 +11740,6 @@
|
|||||||
},
|
},
|
||||||
"time": "2024-03-04T14:35:21+00:00"
|
"time": "2024-03-04T14:35:21+00:00"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "laravel/pint",
|
|
||||||
"version": "v1.29.0",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/laravel/pint.git",
|
|
||||||
"reference": "bdec963f53172c5e36330f3a400604c69bf02d39"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/laravel/pint/zipball/bdec963f53172c5e36330f3a400604c69bf02d39",
|
|
||||||
"reference": "bdec963f53172c5e36330f3a400604c69bf02d39",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"ext-json": "*",
|
|
||||||
"ext-mbstring": "*",
|
|
||||||
"ext-tokenizer": "*",
|
|
||||||
"ext-xml": "*",
|
|
||||||
"php": "^8.2.0"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"friendsofphp/php-cs-fixer": "^3.94.2",
|
|
||||||
"illuminate/view": "^12.54.1",
|
|
||||||
"larastan/larastan": "^3.9.3",
|
|
||||||
"laravel-zero/framework": "^12.0.5",
|
|
||||||
"mockery/mockery": "^1.6.12",
|
|
||||||
"nunomaduro/termwind": "^2.4.0",
|
|
||||||
"pestphp/pest": "^3.8.6",
|
|
||||||
"shipfastlabs/agent-detector": "^1.1.0"
|
|
||||||
},
|
|
||||||
"bin": [
|
|
||||||
"builds/pint"
|
|
||||||
],
|
|
||||||
"type": "project",
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"App\\": "app/",
|
|
||||||
"Database\\Seeders\\": "database/seeders/",
|
|
||||||
"Database\\Factories\\": "database/factories/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Nuno Maduro",
|
|
||||||
"email": "enunomaduro@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "An opinionated code formatter for PHP.",
|
|
||||||
"homepage": "https://laravel.com",
|
|
||||||
"keywords": [
|
|
||||||
"dev",
|
|
||||||
"format",
|
|
||||||
"formatter",
|
|
||||||
"lint",
|
|
||||||
"linter",
|
|
||||||
"php"
|
|
||||||
],
|
|
||||||
"support": {
|
|
||||||
"issues": "https://github.com/laravel/pint/issues",
|
|
||||||
"source": "https://github.com/laravel/pint"
|
|
||||||
},
|
|
||||||
"time": "2026-03-12T15:51:39+00:00"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "laravel/sail",
|
"name": "laravel/sail",
|
||||||
"version": "v1.54.0",
|
"version": "v1.54.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user