Continuous Deployment to Amazon S3 using Bitbucket pipeline

Please visit my website and subscribe to my youtube channel for more articles

https://devops4solutions.com/

In this blog, we will setup the Continuous Deployment to Amazon S3 using Bitbucket pipeline

CI/CD Flow:

  1. Docker image ( We are using docker customized image which has all the software which is required to run the application)
  2. We are using caches feature of bitbucket pipeline. We are doing custom caching for node_modules folder
  3. 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.
  4. Run the npm install command
  5. After build is successful, store the artifacts to S3 bucket with versions
  6. For deployment to production — make the trigger as manual.

Prerequisite:

  1. S3 bucket on AWS
  2. bitbucket-pipeline.yaml file
  3. AWS Secret Keys
  4. Environment Variables

How to setup a Continuous Deployment to Amazon S3 using Bitbucket pipeline

  1. Create a bitbucket-pipeline.yaml file at the root of your project
  2. For the specific bitbucket repository -> Go to Settings -> Add Repository variables
AWS_SECRET_ACCESS_KEY
AWS_ACCESS_KEY_ID
AWS_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.# Only use spaces to indent your .yml configuration.# -----# You can specify a custom docker image from Docker Hub as your build environment.image:  nikhilnidhi/inventory_basepipelines:branches:master:- step:caches:- node-admin- node-webname: Build and Generate Artifactsscript:- 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-webname: Deploy to stagingdeployment: stagingtrigger: manualscript:- cd deploy- ./deploy_staging.shdefinitions:     
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.

Written by

Devops Automation Enginneer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store