簡體   English   中英

如何配置 AWS CodePipeline、CodeBuild 和 Elastic Beanstalk 以正確部署 Laravel 8 應用程序?

[英]How do I configure AWS CodePipeline, CodeBuild, and Elastic Beanstalk to deploy a Laravel 8 application correctly?

我似乎無法在這 3 項服務中找出正確的設置來完成這項工作。 我有一個 Laravel 8 應用程序,它從 Github 推送觸發 AWS CodePipeline,它使用 CodePipeline 構建應用程序並將其部署到 Elastic Beanstalk。

一切都成功構建和部署,但是當我在瀏覽器中訪問應用程序端點時(調試開啟),我得到:

UnexpectedValueException 在“/codebuild/output/src078727356/src/storage/logs”沒有現有目錄,無法創建:權限被拒絕

我的buildspec構建規范是:

version: 0.2
phases:
   install:
     runtime-versions:
         php: 7.4
         nodejs: 12.x
     commands:
         - apt-get update -y
         - apt-get install -y libpq-dev libzip-dev
         - apt-get install -y php-pgsql
         - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
         - chown -R www-data:www-data $CODEBUILD_SRC_DIR/storage
         - chmod -R 755 $CODEBUILD_SRC_DIR/storage
   pre_build:
     commands:
         - cp .env.staging .env
         - composer install
         - npm install
   build:
     commands:
         - pwd
         - ls -l
         - ls -l ./storage
         - ls -l ./storage/logs
         - npm run production
         - php artisan migrate --force
         - php artisan db:seed
         - php artisan route:clear
         - php artisan config:clear
         - php artisan cache:clear
   post_build:
     commands:
         - printenv
artifacts:
   files:
         - '**/*'
   name: $(date +%Y-%m-%dT%H:%M:%S).zip
proxy:
   upload-artifacts: yes
   logs: yes

您可以看到build部分中有一些調試命令,這些命令確認確實存在一個目錄,但錯誤提示它們不是:

[Container] 2021/09/27 22:54:11 Running command ls -l
727 total 688
728 -rw-rw-r--   1 root     root        174 Sep 27 22:34 README.md
729 drwxr-xr-x   7 root     root       4096 Sep 27 22:53 app
730 -rwxrwxr-x   1 root     root       1686 Sep 27 22:34 artisan
731 drwxr-xr-x   3 root     root       4096 Sep 27 22:53 bootstrap
732 -rw-rw-r--   1 root     root       1735 Sep 27 22:34 composer.json
733 -rw-r--r--   1 root     root     285508 Sep 27 22:53 composer.lock
734 drwxr-xr-x   2 root     root       4096 Sep 27 22:53 config
735 drwxr-xr-x   5 root     root       4096 Sep 27 22:53 database
736 drwxr-xr-x 529 root     root      20480 Sep 27 22:54 node_modules
737 -rw-r--r--   1 root     root     323761 Sep 27 22:54 package-lock.json
738 -rw-rw-r--   1 root     root        473 Sep 27 22:34 package.json
739 -rw-rw-r--   1 root     root       1202 Sep 27 22:34 phpunit.xml
740 drwxr-xr-x   2 root     root       4096 Sep 27 22:53 public
741 drwxr-xr-x   6 root     root       4096 Sep 27 22:53 resources
742 drwxr-xr-x   2 root     root       4096 Sep 27 22:53 routes
743 -rw-rw-r--   1 root     root        563 Sep 27 22:34 server.php
744 drwxr-xr-x   5 www-data www-data   4096 Sep 27 22:53 storage
745 drwxr-xr-x   4 root     root       4096 Sep 27 22:53 tests
746 drwxr-xr-x  44 root     root       4096 Sep 27 22:53 vendor
747 -rw-rw-r--   1 root     root        559 Sep 27 22:34 webpack.mix.js
748 
749 [Container] 2021/09/27 22:54:11 Running command ls -l ./storage
750 total 12
751 drwxr-xr-x 3 www-data www-data 4096 Sep 27 22:53 app
752 drwxr-xr-x 6 www-data www-data 4096 Sep 27 22:53 framework
753 drwxrwxrwx 2 www-data www-data 4096 Sep 27 22:53 logs
754 
755 [Container] 2021/09/27 22:54:11 Running command ls -l ./storage/logs
756 total 0

您甚至可以在該日志片段中看到logs/目錄是777可寫的(根據buildspec將其改回755 )。

更新

根據第一條評論,我查看了 EB 實例以進一步調查,它看起來像是使用 CodeBuild 路徑進行日志記錄和存儲(以及基本上所有其他內容),即使應用程序用完了/var/app/current在 EB 實例中。 我要么需要告訴 Laravel 它所在的位置,要么在同一/var/app/current目錄中的 CodeBuild 中構建它,或者其他什么?

好吧,經過更多的嘗試和錯誤,我想通了。 正如評論和更新所說,我意識到構建的工件正在按原樣部署到 beantalk,它已將 CodeBuild 環境嵌入到代碼中。 為了解決這個問題,我必須配置 beantalk 環境以獨立獲取其環境變量,因為我錯誤地認為在 CodeBuild 中設置的環境變量會繼續存在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM