简体   繁体   中英

How do I properly create buildspec.yml file for Laravel Application using AWS CodePipeline

I am using AWS CodePipeline for the first time and trying to figure out how to properly create my buildspec.yml file for my Laravel application. There are few resources on the inte.net.

I have the following in my buildspec.yml file currently:

version: 0.2
phases:
 install:
   commands:
     - curl -s https://getcomposer.org/installer | php
     - mv  composer.phar /usr/local/bin/composer
     - php --version


 build:
   commands:
     - echo Build started on `date`
     - echo Installing composer deps
     - composer install
     - cp extra/.env ./
     - php artisan cache:clear

 post_build:
   commands:
     - echo Build completed on `date`
artifacts:
  type: zip
  files:
    - '**/*'
  name: clyde-$(date +%Y-%m-%d) 

The CodeBuild is successful and this does deploy to Elastic Beanstalk. I did change the configuration in Elastic Beanstalk so the root is /public (for Laravel). However, when I go to the URL, the first line of code run presents an error like below:

View [inc\navbar] not found. (View: /var/app/current/resources/views/layouts/app.blade.php)

This leads me to believe something is not built properly.

To make it work, it will need to use a complete Pipeline: CodeCommit-->CodeBuild-->CodeDeploy

Inside your Artifact bucket there will be two objects generated in the process:

  • s3://codepipeline-us-east-1-<001122334455>/SourceArtif/
  • s3://codepipeline-us-east-1-<001122334455>/BuildArtif/

The first one is obtained in the initial phase of the pipeline from CodeCommit.

The second one is created by CodeBuild. The resultant zip file will be exactly the same as that one from CodeCommit. So it seems, the CodeBuild is only testing but not saving the Artifact with results from the instructions specified in buildspec.yml.

The third phase, CodeDeploy will obtain the code from the Artifact and it will need to Build again via scripts referred by appspec.yml.

version: 0.0
os: linux
files:
  - source: /
    destination: /web/project/html
hooks:
  BeforeInstall:
    - location: scripts/install_dependencies.sh
      timeout: 300
      runas: root
  AfterInstall:
    - location: scripts/build_again.sh
      timeout: 600
      runas: user
  ApplicationStart:
    - location: scripts/start_application.sh
      timeout: 300
      runas: root

The build_again.sh file will need to include same commands you are using in buildspec.yml (build section), then your Laravel project should be working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM