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:
The next step would be that you run unit tests before the deployment steps.
Have a happy deployment, cheers.
Top comments (1)
Really helpful, thanks a lot