承接 nlmenke/deploy-version 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

nlmenke/deploy-version

Composer 安装命令:

composer require nlmenke/deploy-version

包简介

Automatically update application versions by deploying.

README 文档

README

Automatically update application versions by deploying.

Total Downloads Latest Stable Version Latest Unstable Version License

This package works similar to migrations in that you will need to generate a deployment file for each feature. Then, you can deploy all new features at once.

Installation

This package can be installed through Composer:

composer require nlmenke/deploy-version

In Laravel 5.5 and above, the package will auto-register the service provider. In Laravel 5.4, you must install the service provider manually:

// config/app.php
'providers' => [
    ...
    NLMenke\DeployVersion\DeployVersionServiceProvider::class,
    ...
];

In Laravel 5.5 and above, the package will auto-register the facade. In Laravel 5.4, you must install the facade manually:

// config/app.php
'aliases' => [
    ...
    NLMenke\DeployVersion\DeployVersionFacade::class
    ...
];

Optionally, you can publish the config file of the package:

php artisan vendor:publish --provider="NLMenke\DeployVersion\DeployVersionServiceProvider"

The following config file will be published in config/deploy-version.php:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Starting Version
    |--------------------------------------------------------------------------
    |
    | This value determines the starting version of the application. If the
    | project is already version 3.0.0, set that here so we can continue
    | from there. This will only be used when doing the first deploy.
    |
    */

    'starting_version' => '0.0.0-dev',

    /*
    |--------------------------------------------------------------------------
    | Deployment Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the deployments that have already run for
    | your application. Using this information, we can determine which of
    | the deployments on disk haven't been run in the application yet.
    |
    */

    'table' => 'deployments',

    /*
    |--------------------------------------------------------------------------
    | Maintenance Mode
    |--------------------------------------------------------------------------
    |
    | This value determines whether your deployments should employ the artisan
    | down command (`php artisan down`). This value can either be a boolean
    | or a string. String values are used as the message for the command.
    |
    */

    'maintenance_mode' => 'We are currently down for maintenance and should be back shortly. We apologise for any inconvenience.',

    /*
    |--------------------------------------------------------------------------
    | Deployment Commands
    |--------------------------------------------------------------------------
    |
    | This array determines commands that should be performed during each
    | deployment cycle; after all deployment files have been executed.
    | Feature-specific commands should be added to that deployment.
    |
    */

    'commands' => [
        'git reset --hard HEAD',
        'git pull',
        'composer install',
        'yarn',
        'npm run ' . (config('env') === 'production' ? 'production' : 'development'),
    ],

];

Generating Deployments

To create a deployment, use the make:deployment command:

php artisan make:deployment initial_deployment

The new deployment will be placed in a new directory (deployments) in the project's base folder. Each deployment contains a timestamp which allows Laravel to determine the order of the deployments.

The --major, --minor, and --patch options may also be used to indicate what the release type will be. If no option is passed, it is assumed the deployment will be a patch. Only one release type may be used per deployment: a major release will override the minor and patch options, while a minor release will override a patch.

The --pre option will determine if the deployment is a pre-release (alpha, beta, rc, etc.):

php artisan make:deployment initial_deployment --major --pre=alpha.1

If the deployment should include migrations, add the --migration option. If multiple deployments include the migration option when deploying, the migration command will only be run once at the end of the deployment cycle.

Deployment Structure

A deployment class will contain a few variables and an optional deploy function. If no options are given for the make:deployment command, a basic deployment class will be created:

<?php

use NLMenke\DeployVersion\Deployments\Deployment;

class SomePatch extends Deployment
{
    /**
     * Patch versions include backwards-compatible bug fixes.
     *
     * Patch version Z (x.y.Z | x > 0) MUST be incremented if only backwards compatible bug fixes
     * are introduced. A bug fix is defined as an internal change that fixes incorrect behavior.
     *
     * A true value will result in the patch version being increased while major and minor versions
     * will remain unchanged (e.g.: 1.2.3 -> 1.2.4). We'll assume all deployments are a patch
     * unless stated otherwise.
     *
     * @var bool
     */
    protected $patch = true;

    /**
     * Release notes for the deployment.
     *
     * @var array
     */
    protected $releaseNotes = [
        // changelog
    ];

    /**
     * Additional deployment functionality.
     *
     * @return void
     */
    public function deploy()
    {
        // do other deployment stuff
    }
}

Notes

The patch var will always be included in the new deployment class and will default to true if removed. If your deployment will only be a pre-release update, set the value to false and include the $preRelease variable.

If any additional functionality is required during a single deployment, such as running a seeder or sending an email to your users letting them know about the update changes, add it to the deploy method; any commands that should be run at the end of all deployments should be added to the commands option in your config file.

Notes

Migrations will only run once during a deployment cycle and are run before the deploy method of the first pending deployment class, so if your deployment requires migrations to be run first, they should work as intended.

Config commands will be run after all deployments have completed.

For the most part, the release notes variable can be structured in any way you desire, so long as it remains, at it's core, an array. This variable will be JSON encoded before being inserted into your database. Data will be returned as a multi-dimensional array - any formatting thereafter will need to be handled by your application.

Running Deployments

To run all of your outstanding deployments, execute the deploy Artisan command:

php artisan deploy

Notes

composer install must be run prior to your first deployment due to this being a Composer package.

If you are using the maintenance_mode functionality (which calls the down Artisan command), you may include the --message option to change the default maintenance message:

php artisan deploy --message="Patience! For the Jedi it is time to eat as well."

Notes

In order to display this message, you will need to update (or create, if it does not already exist) resources/views/errors/503.blade.php and include $exception->getMessage() wherever you want the message to be displayed.

Forcing Deployments to Run in Production

Deployments only go one-way - they do not have a rollback option. In order to protect you from running a deployment against your production application, you will be prompted for confirmation before the command is executed. To force the command to run without a prompt, use the --force (-f) flag.

php artisan deploy --force

Retrieving Current Version

To get the latest version, you will need to use the DeployVersion facade:

DeployVersion::version();

// 2.1.0-dev

They can be returned as different lengths by either passing the length parameter or by calling the methods manually (version calls the release method by default):

DeployVersion::release();

// 2.1.0-dev

DeployVersion::version('short');
DeployVersion::short();

// v2.1.0-alpha+8752f75

DeployVersion::version('long');
DeployVersion::long();

// Version 2.1.0-dev <span>(build 8752f75)</span>

Release Notes

Pulling release notes will also use the DeployVersion facade. This method will return an array with the release's version as the key:

DeployVersion::releaseNotes();

// [ '1.0.0 <span>(August 25, 2018)</span>' => [ /* notes for this release */ ], '1.0.0-beta <span>(August 23, 2018)</span>' => [ /* notes for this beta release */ ] ]

You can also pass major as the first parameter to only return notes for the latest major release; minor will return notes for the latest minor release; single will only return notes for the latest release. Any parameter passed will result in a similar array returned.

Release Date

The latest release's date/time can be accessed by calling the date function. This will return a Carbon object, so you may manipulate it how you wish (See Carbon for details):

DeployVersion::date()->format('Ymd');

// 20180821

Todo

  • testing suite

nlmenke/deploy-version 适用场景与选型建议

nlmenke/deploy-version 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 56 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 08 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「deploy」 「version」 「versioning」 「laravel」 「deployment」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 nlmenke/deploy-version 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 56
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-14