Deployment Automation

Deployment Automation banner


Deployment Automation


Introduction  

    if you are a web developer you must have deployed application on the server. deployment requires some repetitive tasks like login, removing previous code, adding new code, restarting it, etc. its a very boring task if we are able to automate this process it will save or time to have some coffee.


What exactly is deployment?

Any software goes through one lifecycle called SDLC (software development life cycle ). It includes lots of phases such as planning, development, testing, etc.among this there is a phase called the deployment in which software that is not accessible to the outer world becomes available to the outer world.


What is deployment automation?

Developers develop applications or websites on local machines because of its easy and convenient way so far. Which helps them to check every change they are making in coding immediately. But after development completed and testing also done now its time to deploy the application if we take the example of a website that needs a hosting server to deploy the application to make our product accessible all across the world this is also called the production environment. Nowadays most of the web application requires cloud hosting cloud is nothing but a machine which is same as our personal computer but on a remote location. To deploy our code which is on a local machine to a remote machine requires some steps to follow. Now here at this point, we have options either we can follow that steps manually or we can simply use automation deployment techniques. 

Automation deployment is always the better choice because those are repetitive steps and in the production environment we need to follow those steps so many times after changes, bug fixes, etc. that’s the reason why we need to make this process automatic to save our time and reduce chases of errors.


What are the expected benefits of deployment automation?

  • Deployment automation helps to reduce manual errors such as sometimes wrong command execution may cause difficulties in production to avoid such scenarios we can use it.
  • To save our time


Deployment automation

There are so many third-party software available most of them charge for their service if you want to reduce your extra overhead and ready to pay you can go for it. but here we are discussing free alternatives.

Using shell script we can achieve automation results let’s see how but you need to be careful while using it because any wrong command might affect your other work.

Step 1

Create a GitHub repository and upload your project in that repository. Github is important to keep you code backup as well as we can easily clone it wherever we want.

Step 2

Create a “run.sh” file outside of your project directory(don’t upload this file to GitHub because we are going to use confidential in it). 

.sh is an extension for shell files known as shell script its the same thing as we run command in terminal.but in terminal or shell we can run one command while using shell script we can write multiple commands.it follows a synchronous way due to that command is run command one by one.

Step 3:

  • Log in to a cloud server. 
  • Check deployment directory exist or not if not create one
  • Clone you Github repository
  • Now make installations of packages you want to install for your project (e.g npm install )
  • Start the project by the process manager


Step 4:

  SSH_KEY_PATH="pem_key_path"
SERVER="user@remote_server"
DEST_FOLDER="automationDeployment"
PM2_SERVICE_NAME="app"
GIT_USERNAME="your username"
GIT_PASSWORD="your password"
GIT_ADDRESS="https://"$GIT_USERNAME":"$GIT_PASSWORD"@github.com/your_git_rep0.git"
ssh -i $SSH_KEY_PATH $SERVER 'bash -i'  <<- -r="" automationdeployment="" cd="" clone="" deployautomation="" ecosystem.config.js="" endssh="" exit="" git="" install="" list="" npm="" pm2="" pre="" rm="" save="" start="" stop="" sudo="">
if you are using 
Note: I have written this script as per my server configurations please verify commands for your server.


Conclusion

We studied about how to automate the process of deployment to reduce repetitive tasks. using less setup and no cost.

Post a Comment

0 Comments