In this blog, we will setup the Continuous Deployment to Amazon S3 using Bitbucket pipeline
CI/CD Flow:
- Docker image ( We are using docker customized image which has all the software which is required to run the application)
- We are using caches feature of bitbucket pipeline. We are doing custom caching for node_modules folder
- Automate version using npm version patch of our nodejs application and committing the package.json automatically using pipeline only. To do the auto git commit set the SSH public key setup. Generate the public key of your repository and copy that public key to your account SSH keys.
- Run the npm install command
- After build is successful, store the artifacts to S3 bucket with versions
- For deployment to production — make the trigger as manual.
Prerequisite:
- S3 bucket on AWS
- bitbucket-pipeline.yaml file
- AWS Secret Keys
- Environment Variables
How to setup a Continuous Deployment to Amazon S3 using Bitbucket pipeline
- Create a bitbucket-pipeline.yaml file at the root of your project
- For the specific bitbucket repository -> Go to Settings -> Add Repository variables
AWS_SECRET_ACCESS_KEYAWS_ACCESS_KEY_IDAWS_REGION
All the above variables are required to connect to s3 bucket from bitbucket pipeline.
3. We are setting up a Continuous Deployment to Amazon S3 using Bitbucket pipeline for nodejs application
# This is a sample build configuration for JavaScript.
# Check our guides at https://confluence.atlassian.com/x/14UWN for more examples.
image: nikhilnidhi/inventory_base
pipelines:
branches:
master:
- step:
caches:
- node-admin
- node-web
name: Build and Generate Artifacts
script:
- git config --global user.email "test"
- git config --global user.name "build machine"
- node -v
- ruby -v
- VERSION=$(npm version patch -m "auto verison tick [skip CI]")
- VERSION=$(echo $VERSION | cut -c 2-)
- echo $VERSION
- npm install
- bower install --allow-root
- git add package.json
- grunt build
- aws s3 sync dist s3://m-test-files/admin/$VERSION
- aws s3 cp app/scripts/version.js s3://m-test-files/admin/$VERSION/scripts/version.js
- git commit -m "[skip CI]"
- git push
- step:
caches:
- node-admin
- node-web
name: Deploy to staging
deployment: staging
trigger: manual
script:
- cd deploy
- ./deploy_staging.sh
definitions:
caches:
node-admin: admin/node_modules
node-web: web/node_modules
Congratulations, we have successfully setup the Continuous Deployment to Amazon S3 using Bitbucket pipeline.