在AWS S3上存储CakePHP库以用于多个应用程序

问题描述 投票:2回答:2

我只是想到,不是包含CakePHP库以及我在AWS中运行的不同应用程序的应用程序源代码,是否可以将该核心库移动到AWS S3商店并在转换allow_url_include之后包含它PHP配置。在这里读到这个答案 - including a remote file in PHP,我听说这是一个不好的做法,但如果它与加载非敏感数据有关,那还能适用吗?

还有其他人做过这种安排吗?我问的唯一原因是我有大约5-6个CakePHP应用程序都在运行相同的库,并且发现每次我进行部署时上传它都很麻烦。实际的应用程序特定代码大约3-4 MB,但随着库增加到13MB,我需要每次上传。

任何其他可以达到相同结果的建议也将受到高度赞赏。

提前致谢!

amazon-web-services cakephp
2个回答
1
投票

使用Jenkins或CodePipeline自动化构建和部署。在构建时,包括所有代码依赖项并构建部署包,然后使用CodeDeploy部署包。每个应用程序都遵循相同的部署过程。

这是一种非常标准的方法,用于部署具有外部依赖性的Web应用程序。


0
投票

我想我最关心的是每次我对我的应用程序进行更改时都要继续上传我的软件包,知道库本身负责上传总大小的近80-90%包裹永远不会改变。这就是为什么我想知道是否有办法将这个库加载到我在云中的最终应用程序而不必实际上传它。

首先,我思考是否可以将库存储在S3中并从那里加载它。但正如@Dan Farrell指出的那样,这意味着应用程序必须在每次请求时加载库,这当然不是正确的方法。

最后在做了一些研究并与Composer合作后,我能够实现我想做的事情。如果该配置显示在正在上载的应用程序包的根文件夹中,AWS将使用composer自动加载依赖项。由于我可以将库作为依赖项添加到应用程序以及其他依赖项,并且AWS将在部署时运行依赖项下载,这意味着我的应用程序包很轻,只包含我的域特定代码。所以我的最终composer.json文件就像 -

{
    "require": {
        "cakephp/cakephp": "2.10.*",
        "aws/aws-sdk-php": "2.*",
        "stripe/stripe-php": "^5.8",
        "facebook/graph-sdk": "^5.6"
    },
    "config": {
        "vendor-dir": "./app/Vendor/"
    }
}

就我的应用程序代码而言,我唯一需要改变的是Cake Library的位置。由于我已将配置程序配置为将依赖项加载到app / Vendor文件夹中,因此我必须在app / webroot中的index.php文件中更改库的路径。

但令人惊讶的是,CakePHP的作者已经提供了这个。当库与app文件夹内联时,默认情况下会使用路径的初始声明。这只需要注释掉 - 见下文 -

/**
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
*
* Un-comment this line to specify a fixed path to CakePHP.
* This should point at the directory containing `Cake`.
*
* For ease of development CakePHP uses PHP's include_path. If you
* cannot modify your include_path set this value.
*
* Leaving this constant undefined will result in it being defined in Cake/bootstrap.php
*
* The following line differs from its sibling
* /lib/Cake/Console/Templates/skel/webroot/index.php
*/
//define('CAKE_CORE_INCLUDE_PATH', ROOT .DS. 'lib'); <-- Comment this line out

接下来的两行将把库路径设置为composer下载的路径 -

/**
* This auto-detects CakePHP as a composer installed library.
* You may remove this if you are not planning to use composer (not recommended, though).
*/
$vendorPath = ROOT . DS . APP_DIR . DS . 'Vendor' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib';
$dispatcher = 'Cake' . DS . 'Console' . DS . 'ShellDispatcher.php';
if (!defined('CAKE_CORE_INCLUDE_PATH') && file_exists($vendorPath . DS . $dispatcher)) {
    define('CAKE_CORE_INCLUDE_PATH', $vendorPath);
}

这就是我节省了每次上传7.2MB到2.6MB的原因,对于上传速度较慢的互联网连接而言,这意味着上传具有相同输出的新应用程序版本所需的时间有所改善。

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.