定制 jtmcc/atomic-deployments 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jtmcc/atomic-deployments

Composer 安装命令:

composer require jtmcc/atomic-deployments

包简介

Local zero downtime deployments for Laravel applications

README 文档

README

run-tests StyleCI License: MIT

The purpose of this package is to introduce local zero-downtime deployments into a laravel application.

Requirements

  • Laravel >= 11.x+
  • PHP >= 8.3

Installation

composer require jtmcc/atomic-deployments

php artisan migrate

php artisan vendor:publish --tag=atm-config

Configuration

.env

There are three required environment variables:

  1. ATM_DEPLOYMENT_LINK: The symbolic link you will use with your web server, artisan schedules, ...etc
  2. ATM_BUILD: The project build folder where you will run composer, any build related logic, update your env
  3. ATM_DEPLOYMENTS: The root folder that builds will be deployed to and linked
ATM_DEPLOYMENT_LINK="/var/www/production-site"
ATM_BUILD="/var/www/build-project"
ATM_DEPLOYMENTS="/var/www/deployments"

config( ...)

return [

    /**
     * Symbolic link to the current deployed build
     * This path will be used for schedules and setting your web root.
     */
    'deployment-link' => env('ATM_DEPLOYMENT_LINK'),

    /**
     * The primary build folder
     * This folder is where all deployments ran and ultimately copied to a deployment directory.
     */
    'build-path' => env('ATM_BUILD'),

    /**
     * Production build directory
     * Builds are copied here and linked for deployment
     * Ensure this directory has the required permissions to allow php and your webserver to run your application here.
     */
    'deployments-path' => env('ATM_DEPLOYMENTS'),

    /**
     * Max number of build directories allowed
     * Once limit is hit, old deployments will be removed automatically after a successful build.
     */
    'build-limit' => 10,

    /**
     * Logic used when creating a deployment directory.
     *
     * Default => git - uses hash for current HEAD
     * Options: [ git, datetime, rand ]
     *
     * If your build does not use git, use rand.
     */
    'directory-naming' => 'git',

    /**
     * Deployment class used.
     *
     * Add custom deployments by implementing @see \JTMcC\AtomicDeployments\Interfaces\DeploymentInterface
     * and adding your class to this config property
     */
    'deployment-class' => \JTMcC\AtomicDeployments\Services\Deployment::class,

    /**
     * Migrate files|folders from the outgoing production build to your new release using a relative path and pattern.
     *
     * @see https://www.php.net/manual/en/function.glob.php
     */
    'migrate' => [
        //        'storage/framework/sessions/*',
    ],

];

By default, this package will restrict your project to 10 deployment builds. Once you hit the limit defined in the config, older deployments will be automatically deleted. Be aware of the size of your project and adjust to meet your needs.

You might find yourself in a situation where you need to migrate files that don't exist in your build project from your current deployment folder to your new deployment folder. These files/folders can be specified in the migrate config array, and they will be copied from the outgoing deployment into the new deployment when you run the deploy command.

Once you have configured your env and have deployed a build, you can update your webserver to start routing traffic to your 'deployment-link' location.

# nginx example
root /var/www/production-site/public;

#crontab logic example
php /var/www/production-site/artisan schedule:run

Commands

atomic-deployments:deploy

options

  • --hash= : Specify a previous deployments commit hash/deploy-dir to deploy
  • --directory= : Define your deploy folder name. Defaults to current HEAD hash
  • --dry-run : Test and log deployment steps

examples

Do a dry run to get some feedback on the steps that will be taken

php artisan atomic-deployments:deploy --dry-run

Deploy current build using the current branch git hash for deployment folder

php artisan atomic-deployments:deploy

Deploy current build using a custom directory name

php artisan atomic-deployments:deploy --directory=deployment_folder

Revert linked project back to a previous build

php artisan atomic-deployments:deploy ---hash=abc1234

atomic-deployments:list

Prints a table to the console of the currently available builds

examples

php artisan atomic-deployments:list

Events

  • DeploymentSuccessful
  • DeploymentFailed

Laravel Forge Example

Here is a basic configuration for use with Forge

Deploy Script

cd /home/forge/your-application.com
git pull origin main
$FORGE_COMPOSER install --no-interaction --prefer-dist --optimize-autoloader --no-dev --no-progress

( flock -w 10 9 || exit 1
    echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock

if [ -f artisan ]; then
    $FORGE_PHP artisan migrate --force
    $FORGE_PHP artisan optimize:clear
    $FORGE_PHP artisan atomic-deployments:deploy
fi

.env

Build project .env

ATM_DEPLOYMENT_LINK="/home/forge/your-application.com-link"
ATM_BUILD="/home/forge/your-application.com"
ATM_DEPLOYMENTS="/home/forge/deployments/your-application.com"

nginx config

root /home/forge/your-application.com-link/public;

schedule command

php8.0 /home/forge/your-application.com-link/artisan schedule:run

If your application is isolated, you must ensure that your deployments folder has the appropriate permissions to serve your application for that user.

License

MIT

jtmcc/atomic-deployments 适用场景与选型建议

jtmcc/atomic-deployments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.32k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2021 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 jtmcc/atomic-deployments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jtmcc/atomic-deployments 我们能提供哪些服务?
定制开发 / 二次开发

基于 jtmcc/atomic-deployments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 16.32k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-20