DEV Community

Cover image for How to implement Laravel CI/CD with Bitbucket and AWS
Shpëtim Islami ⚡
Shpëtim Islami ⚡

Posted on

5 5

How to implement Laravel CI/CD with Bitbucket and AWS

If you never did CI/CD implementation of your Laravel project before, then start with Bitbucket pipelines because its easy.

If you did CI/CD implementation of Laravel before then use Bitbucket pipelines because it has a lot of free build time.

Now lets get into it..

image: atlassian/default-image:2
pipelines:
branches:
master:
- parallel:
- step:
name: "Zip the web code"
script:
- zip -r your-application.zip . -x "vendor/*"
artifacts:
- /your-application.zip
- step:
name: "Zip the queue worker code"
script:
- zip -r your-application-queue.zip . -x "vendor/*"
artifacts:
- your-application-queue.zip
- parallel:
- step:
name: "Deploy to production web"
deployment: production
script:
- pipe: atlassian/aws-elasticbeanstalk-deploy:0.5.2
variables:
AWS_ACCESS_KEY_ID: 'your aws access key ID'
AWS_SECRET_ACCESS_KEY: 'your aws secret access key'
AWS_DEFAULT_REGION: 'the region you created the application'
APPLICATION_NAME: 'your-application-name'
ENVIRONMENT_NAME: 'production-web'
ZIP_FILE: 'your-application.zip'
S3_BUCKET: 'your-application-elasticbeanstalk-deployment'
VERSION_LABEL: your-application-web_${BITBUCKET_COMMIT:0:8}
- step:
name: "Deploy to production queue server"
script:
- pipe: atlassian/aws-elasticbeanstalk-deploy:0.5.2
variables:
AWS_ACCESS_KEY_ID: 'your aws access key ID'
AWS_SECRET_ACCESS_KEY: 'your aws secret access key'
AWS_DEFAULT_REGION: 'the region you created the application'
APPLICATION_NAME: 'your-application-name'
ENVIRONMENT_NAME: 'production-worker'
ZIP_FILE: 'your-application-queue.zip'
S3_BUCKET: 'your-application-elasticbeanstalk-deployment'
VERSION_LABEL: your-application-queue_${BITBUCKET_COMMIT:0:8}

Here in line 5 under branches we say when commit is pushed to master branch to run the following:

Create 2 zip files excluding the vendor folder, and they both run in parallel defined by the parallel tag on line 6.

Then again in line 19 we define 2 processes to run in parallel, they deploy to 2 different beanstalk environments. 1 is for web serving instance/s and the other is for the queue instance/s.

To use this you will need to:

  • Create 1 application in AWS Beanstalk with 2 environments (web and queue worker).
  • Create an S3 bucket
  • Obtain your AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_DEFAULT_REGION

replace them with the placeholders and add this file called bitbucket-pipelines.yml into the root of your projects git repository.

If you followed this how to guide, when you push something to master this is how it looks like in Bitbucket:

Alt Text

The next step would be that you run unit tests before the deployment steps.

Have a happy deployment, cheers.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (1)

Collapse
 
somtee99 profile image
Somtoo Okafor

Really helpful, thanks a lot

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay