侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

使用Laravel Airdrop加速您的CI构建

Laravel  /  管理员 发布于 1个月前   133

Laravel Airdrop是一个存储你构建的静态资产的工具。当您进行 CI 运行时,Airdrop 会检查您的静态资产是否已更改。

如果资产没有更改,Airdrop 会从存储中下载它们并放置在正确的位置 - 允许您跳过构建资产。

如果它们发生了变化,那么您可以像往常一样使用 Node 来构建您的静态资产。

这对于节省 CI 和部署时间非常有用。

https://laravel-news.com/airdrop
https://hammerstone.dev/airdrop/docs/main/installation

以下是如何使用Airdrop。


安装

安装Airdrop很简单:

composer require hammerstone/airdrop
 
# Add config/airdrop.php to your project
php artisan airdrop:install

配置Airdrop

在 Airdrop 中只需要配置一些东西 - 其中一些可以保留为默认值。


触发器

您可以告诉 Airdrop 何时决定重新构建静态资产。

触发器特定于环境( APP_ENV) - 每个环境都有自己的文件集。这称为配置触发器。

另一个触发器是FileTrigger. 如果文件已更改,这将跟踪配置的文件并重建资产。


将FileTrigger检查:

resources(CSS、JS 等)中的文件

如果 Webpack/Vite 配置文件发生变化

我还添加了package-lock.jsonNPM 生成的文件。

<?php
 
use Hammerstone\Airdrop\Drivers\FilesystemDriver;
use Hammerstone\Airdrop\Drivers\GithubActionsDriver;
use Hammerstone\Airdrop\Triggers\ConfigTrigger;
use Hammerstone\Airdrop\Triggers\FileTrigger;
 
return [
    'driver' => env('AIRDROP_DRIVER', 'default'),
    'drivers' => [
        'default' => [...],
        'github' => [...],
    ],
    'triggers' => [
        ConfigTrigger::class => [
            'env' => env('APP_ENV')
    ],
        FileTrigger::class => [
            'include' => [
                resource_path(), // default
                base_path('webpack.mix.js'), // mix default
                base_path('vite.config.js'), // vite default
                base_path('package-lock.json'), // my addition here
            ],
        ],
    ],
    'outputs' => [...],
];

驱动程序

您可以决定 Airdrop 将静态资产存储在哪里。通常你只使用FilesystemDriver这里,并使用 Laravel 的Storage机制来告诉 Airdrop 将文件放在哪里。

disk与使用的 Laravel “磁盘”存储相关的设置。建议使用一些远程存储,例如s3。

GitHub Actions 驱动程序可让您将文件保存到 GH Actions 缓存,这非常方便!

return [
    // The driver you wish to use to stash and restore your files.
    'driver' => env('AIRDROP_DRIVER', 'default'),
 
    'drivers' => [
        'default' => [
            // The class responsible for implementing the stash and restore
            // logic. Must extend BaseDriver.
            'class' => FilesystemDriver::class,
 
            // The disk on which to store the built files.
            'disk' => env('AIRDROP_REMOTE_DISK', 's3'),
 
            // The folder (if any) where you'd like your stashed assets to reside.
            'remote_directory' => env('AIRDROP_REMOTE_DIR', 'airdrop'),
 
            // A writeable directory on the machine that builds the assets.
            // Used to build up the ZIP file before stashing it.
            'local_tmp_directory' => env('AIRDROP_LOCAL_TMP_DIR', storage_path('framework')),
 
            // The skip file is an empty file that will be created to
            // indicate that asset building can be skipped.
            'skip_file' => env('AIRDROP_SKIP_FILE', base_path('.airdrop_skip')),
        ],
        ],
        // ...
];

输出

输出是 Airdrop 将为您存储和检索的文件。您通过触发器“观看”的文件不一定是您为您保存/存储的相同文件!

Airdrop 的默认设置非常好,当然您可以根据需要配置这些。

return [
    // ...
    'outputs' => [
        /*
         * Files or folders that should be included.
         */
        'include' => [
            // Mix/Webpack
            public_path('mix-manifest.json'),
            public_path('css'),
            public_path('js'),
 
            // Vite
            public_path('build/manifest.json'),
            public_path('build/assets'),
        ],
 
                // ...
    ],
];

注意:

在使用 Airdrop 时,您可能不想将静态资产提交到您的存储库。

为避免这种情况并完成 Airdrop 配置,请将以下内容添加到您的.gitignore文件中:

/.airdrop_skip
 
# Mix/Webpack
public/css/*
public/js/**
 
# Vite
public/build/*


整合Airdrop

当您在 CI 或部署脚本中构建应用程序 Airdrop 时(这对于 Forge 快速部署非常有用!),

您可以运行以下命令:

# Download files, only if needed
php artisan airdrop:download
 
# Airdrop creates .airdrop_skip if
# it downloaded files
if [ ! -f ".airdrop_skip" ]; then
    npm ci --no-audit
    npm run dev
fi
 
# Upload the files if needed
php artisan airdrop:upload

  • 上一条:
    go语言中日期时间戳比较功能示例代码
    下一条:
    go语言中查找最长不含有重复字符的字符串算法示例代码
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Laravel 9.24版本发布(0个评论)
    • Laravel collect集合中获取二维数组中键值功能示例代码(0个评论)
    • lumen中验证类的实现及使用流程步骤(0个评论)
    • 构建你自己的Laravel扩展包的流程步骤(0个评论)
    • Laravel 9.23版本发布(0个评论)
    • 近期文章
    • GnuPG(GPG)生成用于替代SSH密钥的子密钥:签名、加密、鉴权及SSH验证(0个评论)
    • GnuPG(GPG)密钥创建的流程步骤(0个评论)
    • Laravel 9.24版本发布(0个评论)
    • windows系统phpstudy环境中安装amqp拓展流程步骤(0个评论)
    • windows10+docker desktop使用docker compose编排多容器构建dnmp环境(0个评论)
    • windows10+docker desktop运行laravel项目报错:could not find driver...(0个评论)
    • windows10+docker desktop报错:docker: Error response from daemon: user declined directory sharing(0个评论)
    • go语言中Pat多路复用器路由功能示例代码(0个评论)
    • go语言中HttpRouter多路复用器路由功能示例代码(0个评论)
    • js中使用Push.js通知库将通知推送到浏览器(0个评论)
    • 近期评论
    • nkt 在

      阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 用了三分钟就被禁了,直接阿里云服务器22端口都禁了..
    • 熊丽 在

      安装docker + locust + boomer压测环境实现对接口的压测中评论 试试水..
    • 博主 在

      阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 @test  也可能是国内大环境所至,也是好事,督促你该研究学习新技术..
    • test 在

      阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 打了一次网页,然后再也打不开了。。是阿里云的缘故吗?..
    • 博主 在

      centos7中Meili Search搜索引擎安装流程步骤中评论 @鹿   执行以下命令看看你的2.27版本是否存在strin..
    • 2016-10
    • 2016-11
    • 2017-07
    • 2017-08
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-08
    • 2020-09
    • 2020-10
    • 2020-11
    • 2021-01
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-04
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客