1、编辑 .gitignore,将 /vendor 加入至 Git 仓库,如图1
# composer vendor dir # /vendor
2、在 Jenkins 中构建失败,查看 Console Output。如图2
[0mThe command '/bin/sh -c chown -R nginx:nginx /mcloud/www/ && rm -rf /etc/nginx/conf.d/status.conf && chmod +x /usr/local/bin/composer && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ && cd /mcloud/www/pcs-api && composer install' returned a non-zero code: 1 Build step 'Docker Build and Publish' marked build as failure Finished: FAILURE
3、Docker 部署,删除 composer install。编辑 Dockerfile。如图3
RUN chown -R nginx:nginx /mcloud/www/ && / rm -rf /etc/nginx/conf.d/status.conf && / chmod +x /usr/local/bin/composer && / composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ && / cd /mcloud/www/pcs-api && / composer install
RUN chown -R nginx:nginx /mcloud/www/ && / rm -rf /etc/nginx/conf.d/status.conf
4、在 Jenkins 中构建成功。如图4
5、在 Rancher 中启动失败,查看日志。如图5
2020/5/8 下午2:48:45 2020/5/8 下午2:48:45 ... initialization completed. 2020/5/8 下午2:48:45 2020/5/8 下午2:48:45 PCS_API_CFG_MIGRATE=true
6、编辑 build/c_files/config/init/console_init.sh。删除 $PCS_API_CFG_MIGRATE == “true” 的相关命令。如图6
7、在 Rancher 中启动成功,查看日志。如图7
2020/5/8 下午2:48:45 2020/5/8 下午2:48:45 ... initialization completed. 2020/5/8 下午2:48:45 2020/5/8 下午2:48:45 PCS_API_CFG_MIGRATE=true
8、进入容器,手动执行 $PCS_API_CFG_MIGRATE == “true” 的相关命令。未成功运行,因为无相应输出。如图8
9、进入将 /vendor 加入至 Git 仓库前的容器。手动执行 $PCS_API_CFG_MIGRATE == “true” 的相关命令。成功运行,因为有相应输出。如图9
10、在本地环境中全新部署,手动执行 $PCS_API_CFG_MIGRATE == “true” 的相关命令。未成功运行,报错。如图10
PS E:/wwwroot/pcs-api-develop> ./yii migrate --migrationPath=@yii/log/migrations/ --interactive=0 PHP Warning: require(E:/wwwroot/pcs-api-develop/vendor/composer/../codeception/verify/src/Codeception/function.php): fa iled to open stream: No such file or directory in E:/wwwroot/pcs-api-develop/vendor/composer/autoload_real.php on line 6 6 Warning: require(E:/wwwroot/pcs-api-develop/vendor/composer/../codeception/verify/src/Codeception/function.php): failed to open stream: No such file or directory in E:/wwwroot/pcs-api-develop/vendor/composer/autoload_real.php on line 66 PHP Fatal error: require(): Failed opening required 'E:/wwwroot/pcs-api-develop/vendor/composer/../codeception/verify/s rc/Codeception/function.php' (include_path='.;C:/php/pear') in E:/wwwroot/pcs-api-develop/vendor/composer/autoload_real. php on line 66 Fatal error: require(): Failed opening required 'E:/wwwroot/pcs-api-develop/vendor/composer/../codeception/verify/src/Co deception/function.php' (include_path='.;C:/php/pear') in E:/wwwroot/pcs-api-develop/vendor/composer/autoload_real.php o n line 66
11、文件 E:/wwwroot/pcs-api-develop/vendor/composer/../codeception/verify/src/Codeception/function.php 不存在,如图11
12、进入将 /vendor 加入至 Git 仓库前的容器。文件 /vendor/composer/../codeception/verify/src/Codeception/function.php 存在。如图12
13、查看 E:/wwwroot/pcs-api/vendor/codeception/verify,其目录下存在相应的文件。且 Git 显示是已经提交至仓库。如图13
14、进入将 /vendor 加入至 Git 仓库前的本地环境。发现 /vendor/codeception/verify 已经存在于 Git 中。只不过是 master 分支。如图14
15、最终决定切换至 master 分支,合并 develop 分支的代码。再推送至远程的 master 分支。在远程仓库中文件:/vendor/composer/../codeception/verify/src/Codeception/function.php 仍然不存在。如图15
16、删除目录:E:/wwwroot/pcs-api/vendor/codeception/verify/.git,将未显示已经提交至仓库的文件,添加至仓库。如图16、17
17、在本地环境中全新部署,手动执行 $PCS_API_CFG_MIGRATE == “true” 的相关命令。未成功运行,报错,但是 /codeception/verify 相应的错误已经得到解决。参考步骤 16 同样处理。后续在运行命令的过程中报错的类似问题,皆可以如此处理。
PS E:/wwwroot/pcs-api-develop> ./yii migrate --migrationPath=@yii/log/migrations/ --interactive=0 PHP Warning: require(E:/wwwroot/pcs-api-develop/vendor/composer/../myclabs/deep-copy/src/DeepCopy/deep_copy.php): faile d to open stream: No such file or directory in E:/wwwroot/pcs-api-develop/vendor/composer/autoload_real.php on line 66 Warning: require(E:/wwwroot/pcs-api-develop/vendor/composer/../myclabs/deep-copy/src/DeepCopy/deep_copy.php): failed to open stream: No such file or directory in E:/wwwroot/pcs-api-develop/vendor/composer/autoload_real.php on line 66 PHP Fatal error: require(): Failed opening required 'E:/wwwroot/pcs-api-develop/vendor/composer/../myclabs/deep-copy/sr c/DeepCopy/deep_copy.php' (include_path='.;C:/php/pear') in E:/wwwroot/pcs-api-develop/vendor/composer/autoload_real.php on line 66 Fatal error: require(): Failed opening required 'E:/wwwroot/pcs-api-develop/vendor/composer/../myclabs/deep-copy/src/Dee pCopy/deep_copy.php' (include_path='.;C:/php/pear') in E:/wwwroot/pcs-api-develop/vendor/composer/autoload_real.php on l ine 66
18、在本地环境中全新部署,手动执行 $PCS_API_CFG_MIGRATE == “true” 的相关命令。成功运行。如图18
19、进入将 /vendor 加入至 Git 仓库前的本地环境。执行命令:composer install。成功运行。如图19
PS E:/wwwroot/pcs-api-feature-plan-tonglian> composer install Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Nothing to install or update Generating autoload files
20、在本地环境中全新部署,执行命令:composer install。未成功运行。如图20
PS E:/wwwroot/pcs-api-develop> composer install Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Nothing to install or update Generating autoload files [RuntimeException] Could not scan for classes inside "E:/wwwroot/pcs-api-develop/vendor/sebastian/object-enumerator/src/" which does n ot appear to be a file nor a folder install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--n o-scripts] [--no-progress] [--no-suggest] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--] [<packages>]...
21、实际上,第 16、17 步骤,可以通过执行命令:composer require codeception/verify myclabs/deep-copy 来解决,而无需一定要将这 2 个包提交至 Git 仓库中。不过,即使采用此方案,仍然会存在第 20 步骤中所存在的问题。而且还会改变 /vendor/composer 中的其他文件。此方案不太可取。如图21
22、最终决定,先删除掉 /vendor ,提交至 Git 仓库,执行命令:composer install –no-dev。–no-dev:跳过 require-dev 字段中列出的包。再将 /vendor 提交至 Git 仓库。因为,已经确定,–dev:安装 require-dev 字段中列出的包 ( 这是一个默认值 )。提交至 Git 仓库仅能够提交空目录。如图22
23、执行命令:composer install。安装 require-dev 字段中列出的包。再将 /vendor 提交至 Git 仓库。如图23
24、在本地环境中全新部署,手动执行 $PCS_API_CFG_MIGRATE == “true” 的相关命令。成功运行。不符合预期。如图24
25、查看全新部署的文件,目录:/codeception/verify、/vendor/myclabs/deep-copy 皆存在。如图25
26、在 /vendor 目录中搜索:.git,不存在相应的目录。而之前执行命令:composer install。未成功运行。在 /vendor 目录中搜索:.git,存在相应的目录。如图26
27、编辑 build/c_files/config/init/console_init.sh。恢复 $PCS_API_CFG_MIGRATE == “true” 的相关命令。在 Rancher 中启动成功,查看日志。如图27
28、在另一个产品中,在 /vendor 目录中搜索:.git,存在相应的目录。如图28
29、在 Rancher 中启动失败,查看日志。如图29
2020/5/9 下午7:01:07 PHP Fatal Error 'yii/base/ErrorException' with message 'Class 'wartron/yii2uuid/behaviors/UUIDBehavior' not found' 2020/5/9 下午7:01:07 2020/5/9 下午7:01:07 in /mcloud/www/channel-pub-api/common/behaviors/UUIDBehavior.php:7 2020/5/9 下午7:01:07 2020/5/9 下午7:01:07 Stack trace: 2020/5/9 下午7:01:07 #0 [internal function]: yii/base/ErrorHandler->handleFatalError() 2020/5/9 下午7:01:07 #1 {main}
30、由于仅有一个目录:.git,决定采用第 16、17 步骤的方案。在 Rancher 中启动成功,查看日志。如图30
31、在 Jenkins 中构建时间的前后对比,分别为:13分钟、43秒。如图31
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/webdev/181513.html