没有不值得去解决的问题,也没有不值得去学习的技术!

Analysis and Fix for Docker Deployment Upgrade Failure After Adding /vendor to the Git Repository

Search for .git in the /vendor directory; no such directory exists. Previously, when executing the command: composer install, it did not run successfully. Searching for .git in the /vendor directory at that time showed that the corresponding directory existed.

1. Edit .gitignore to add /vendor to the Git repository, as shown in Figure 1

Edit .gitignore to add /vendor to the Git repository
Figure 1
Plaintext
# composer vendor dir
# /vendor

2. The build failed in Jenkins. Check the Console Output, as shown in Figure 2

The build failed in Jenkins. Check the Console Output.
Figure 2
Plaintext
[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. For Docker deployment, remove composer install. Edit the Dockerfile, as shown in Figure 3

For Docker deployment, remove composer install. Edit the Dockerfile.
Figure 3
Dockerfile
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

Dockerfile
RUN chown -R nginx:nginx /mcloud/www/ && \
    rm -rf /etc/nginx/conf.d/status.conf

4. The build succeeds in Jenkins, as shown in Figure 4

The build succeeds in Jenkins.
Figure 4

5. Startup fails in Rancher. Check the logs, as shown in Figure 5

Startup fails in Rancher. Check the logs.
Figure 5
Plaintext
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. Edit build/c_files/config/init/console_init.sh. Remove the commands related to $PCS_API_CFG_MIGRATE == “true”, as shown in Figure 6

Edit build/c_files/config/init/console_init.sh. Remove the commands related to $PCS_API_CFG_MIGRATE == "true".
Figure 6

7. Startup succeeds in Rancher. Check the logs, as shown in Figure 7

Startup succeeds in Rancher. Check the logs.
Figure 7
Plaintext
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. Enter the container and manually execute the commands related to $PCS_API_CFG_MIGRATE == “true”. It did not run successfully because there was no corresponding output, as shown in Figure 8

Enter the container and manually execute the commands related to $PCS_API_CFG_MIGRATE == "true". It did not run successfully because there was no corresponding output.
Figure 8

9. Enter the container from before adding /vendor to the Git repository. Manually execute the commands related to $PCS_API_CFG_MIGRATE == “true”. It ran successfully because there was corresponding output, as shown in Figure 9

Enter the container from before adding /vendor to the Git repository. Manually execute the commands related to $PCS_API_CFG_MIGRATE == "true". It ran successfully because there was corresponding output.
Figure 9

10. Perform a fresh deployment in the local environment and manually execute the commands related to $PCS_API_CFG_MIGRATE == “true”. It did not run successfully and threw an error, as shown in Figure 10

Perform a fresh deployment in the local environment and manually execute the commands related to $PCS_API_CFG_MIGRATE == "true". It did not run successfully and threw an error.
Figure 10
Plaintext
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. The file E:\wwwroot\pcs-api-develop\vendor\composer/../codeception/verify/src/Codeception/function.php does not exist, as shown in Figure 11

The file E:\wwwroot\pcs-api-develop\vendor\composer/../codeception/verify/src/Codeception/function.php does not exist
Figure 11

12. Enter the container from before adding /vendor to the Git repository. The file \vendor\composer/../codeception/verify/src/Codeception/function.php exists, as shown in Figure 12

Enter the container from before adding /vendor to the Git repository. The file \vendor\composer/../codeception/verify/src/Codeception/function.php exists.
Figure 12

13. Check E:\wwwroot\pcs-api\vendor\codeception\verify; the corresponding files exist in its directory, and Git shows they have already been committed to the repository, as shown in Figure 13

Check E:\wwwroot\pcs-api\vendor\codeception\verify; the corresponding files exist in its directory, and Git shows they have already been committed to the repository.
Figure 13

14. Enter the local environment from before adding /vendor to the Git repository. I found that \vendor\codeception\verify already exists in Git, but on the master branch, as shown in Figure 14

Enter the local environment from before adding /vendor to the Git repository. I found that \vendor\codeception\verify already exists in Git, but on the master branch.
Figure 14

15. I finally decided to switch to the master branch, merge the code from the develop branch, and then push to the remote master branch. In the remote repository, the file \vendor\composer/../codeception/verify/src/Codeception/function.php still does not exist, as shown in Figure 15

I finally decided to switch to the master branch, merge the code from the develop branch, and then push to the remote master branch. In the remote repository, the file \vendor\composer/../codeception/verify/src/Codeception/function.php still does not exist.
Figure 15

16. Delete the directory E:\wwwroot\pcs-api\vendor\codeception\verify\.git, and add the files that were not shown as committed to the repository to the repository, as shown in Figures 16 and 17

Delete the directory E:\wwwroot\pcs-api\vendor\codeception\verify\.git, and add the files that were not shown as committed to the repository to the repository.
Figure 16

 

Delete the directory E:\wwwroot\pcs-api\vendor\codeception\verify\.git, and add the files that were not shown as committed to the repository to the repository.
Figure 17

17. Perform a fresh deployment in the local environment and manually execute the commands related to $PCS_API_CFG_MIGRATE == “true”. It did not run successfully and threw an error, but the error related to /codeception/verify has been resolved. Apply the same approach as in step 16. Similar errors that occur during subsequent command executions can all be handled this way.

Plaintext
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. Perform a fresh deployment in the local environment and manually execute the commands related to $PCS_API_CFG_MIGRATE == “true”. It ran successfully, as shown in Figure 18

Perform a fresh deployment in the local environment and manually execute the commands related to $PCS_API_CFG_MIGRATE == "true". It ran successfully.
Figure 18

19. Enter the local environment from before adding /vendor to the Git repository. Execute the command: composer install. It ran successfully, as shown in Figure 19

Enter the local environment from before adding /vendor to the Git repository. Execute the command: composer install. It ran successfully.
Figure 19
Plaintext
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. Perform a fresh deployment in the local environment and execute the command: composer install. It did not run successfully, as shown in Figure 20

Perform a fresh deployment in the local environment and execute the command: composer install. It did not run successfully.
Figure 20
Plaintext
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] [--] []...


21. Actually, steps 16 and 17 can be resolved by executing the command: composer require codeception/verify myclabs/deep-copy, without necessarily committing these 2 packages to the Git repository. However, even with this approach, the problem in step 20 would still exist. Moreover, it would change other files in /vendor/composer. This approach is not advisable, as shown in Figure 21

Actually, steps 16 and 17 can be resolved by executing the command: composer require codeception/verify myclabs/deep-copy, without necessarily committing these 2 packages to the Git repository. However, even with this approach, the problem in step 20 would still exist. Moreover, it would change other files in /vendor/composer. This approach is not advisable.
Figure 21

22. I finally decided to first delete /vendor, commit to the Git repository, and execute the command: composer install –no-dev. –no-dev: skips the packages listed in the require-dev field. Then commit /vendor to the Git repository again. This is because it has been confirmed that –dev: installs the packages listed in the require-dev field (this is a default value). Committing to the Git repository can only commit empty directories, as shown in Figure 22

I finally decided to first delete /vendor, commit to the Git repository, and execute the command: composer install --no-dev. --no-dev: skips the packages listed in the require-dev field. Then commit /vendor to the Git repository again. This is because it has been confirmed that --dev: installs the packages listed in the require-dev field (this is a default value). Committing to the Git repository can only commit empty directories.
Figure 22

23. Execute the command: composer install. Install the packages listed in the require-dev field. Then commit /vendor to the Git repository, as shown in Figure 23

Execute the command: composer install. Install the packages listed in the require-dev field. Then commit /vendor to the Git repository.
Figure 23

24. Perform a fresh deployment in the local environment and manually execute the commands related to $PCS_API_CFG_MIGRATE == “true”. It ran successfully, which was unexpected, as shown in Figure 24

Perform a fresh deployment in the local environment and manually execute the commands related to $PCS_API_CFG_MIGRATE == "true". It ran successfully, which was unexpected.
Figure 24

25. Check the freshly deployed files; the directories \codeception\verify and \vendor\myclabs\deep-copy both exist, as shown in Figure 25

Check the freshly deployed files; the directories \codeception\verify and \vendor\myclabs\deep-copy both exist.
Figure 25

26. Search for .git in the /vendor directory; no such directory exists. Previously, when executing the command: composer install, it did not run successfully. Searching for .git in the /vendor directory at that time showed that the corresponding directory existed, as shown in Figure 26

Search for .git in the /vendor directory; no such directory exists. Previously, when executing the command: composer install, it did not run successfully. Searching for .git in the /vendor directory at that time showed that the corresponding directory existed.
Figure 26

27. Edit build/c_files/config/init/console_init.sh. Restore the commands related to $PCS_API_CFG_MIGRATE == “true”. Startup succeeds in Rancher. Check the logs, as shown in Figure 27

Edit build/c_files/config/init/console_init.sh. Restore the commands related to $PCS_API_CFG_MIGRATE == "true". Startup succeeds in Rancher. Check the logs.
Figure 27

28. In another product, search for .git in the /vendor directory; the corresponding directory exists, as shown in Figure 28

In another product, search for .git in the /vendor directory; the corresponding directory exists.
Figure 28

29. Startup fails in Rancher. Check the logs, as shown in Figure 29

Startup fails in Rancher. Check the logs.
Figure 29
Plaintext
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. Since there is only one directory: .git, I decided to use the approach from steps 16 and 17. Startup succeeds in Rancher. Check the logs, as shown in Figure 30

Since there is only one directory: .git, I decided to use the approach from steps 16 and 17. Startup succeeds in Rancher. Check the logs.
Figure 30

31. The Jenkins build times before and after are 13 minutes and 43 seconds, respectively, as shown in Figure 31

The Jenkins build times before and after are 13 minutes and 43 seconds, respectively.
Figure 31

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系