Continuous Delivery/ Deployment from Git Repository to CPanel/ FTP Server
These days a lot of developers and DevOps engineers implement CI/CD (Continuous Integration/ Continuous Delivery) to make the deployment in the cloud easy and fast. Yes of course... There are so many tutorials to teach you to implement CI/CD to deploy apps, that are developed by using latest front-end and back-end frameworks, on firebase, aws servers, google cloud platform, etc. But this tutorial is to deploy a simple website or a web-app on a shared hosting. There are still many of us, who host their sites and apps in shared hosting, because the app is simple and the cost is low as well. Lets start to learn how to deploy your code to shared hosting via FTP (File Transfer Protocol) whenever something new is pushed to Bitbucket repository.
- Enable bitbucket pipeline
- Configure initializing yml file for FTP deployment
- Setting up environment variables
- Triggering a build
Enable Bitbucket Pipeline
This is the first thing you have to do. Go to the project you need to implement CI/CD pipeline. Then go to the left column and click on the "Settings" section.
Then you will see another menu. There's a section called "Pipeline" and under that section, you will see another tab called "Settings". Click on it.
Then enable pipelines.
Then click on the "create bitbucket-pipelines.yml" button. This will create a new file in the root of your repository called bitbucket-pipelines.yml. This file controls:
- The Docker image that should be used to run your tests in
- For which branches the CI/ CD should be triggered
- What steps it should go through (which commands should be run).
Configure Initializing yml File for FTP Deployment
After clicking the “create bitbucket-pipelines.yml” button, BitBucket will automatically open up the editor. Now you have to copy below configurations and paste it on the editor and commit the changes.Warning - Keep spacing as it is. Otherwise it will give errors. You can learn how to write a yml file from the beginning through https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
Setting Up Environment Variable
As you see... $FTP_USERNAME, $FTP_PASSWORD, $FTP_URL are environment variable and we have to set up them. First of all, you have to create FTP username and password from your CPanel dashboard. Log into your CPanel dashboard and go to "FTP Accounts" section. There you can add a new FTP account.Remember your 'Log In' and 'Password'. And keep the 'Directory' field empty. Now go to your Bitbucket repository > Settings > Pipelines > Repository variables.
- FTP_USERNAME = ravindu
- FTP_PASSWORD = *********
- FTP_URL = ftp://ftp.sixthflow.com/public_html
Note - Your FTP_URL should be ftp://ftp.your_domain/public_html
Triggering an Init and Push Changes to Server.
Now you have to go to "Pipelines" section of your repo and click on "Run Pipeline" button. Then you will get a successful pipeline initialization.
If it gives a "Failed" or "Error" message, you have done something wrong. Just follow up the tutorial again carefully and fix the issues.
Note - The initialization pipeline will run successfully only once. After that you have to change the bitbucket-pipelines.yml file to run a pipeline again and get a success message.
After you run the first successful pipeline, then you have to change the bitbucket-pipelines.yml file as follows to automatically run a pipeline whenever you push something new to the repository.
You can view all your pipeline activities in the "Pipelines" section and view how that pipeline ran by clicking on any pipeline.That's all. Now whenever you push new commits to your repo, they will be automatically deployed to your shared hosting space. Just try it out. If you need to limit this CI/CD pipeline to a specific branch in the repo, you can click here to learn how to write the bitbucket-pipelines.yml file to do so and change your yml file. You can do so many different new things if you know how to write your own yml file. Hope you learnt something new and very useful.
Do not hesitate to comment here if you stuck in any step or if you have any other problem related to this topic. Thanks!
6 Comments
There's another method we can use with the cpanel's git clone feature. I used it, because i can make deployments manually.
ReplyDeleteYeah. It is a good in-build CPanel feature. But we can fully automate building, testing, code formatting and deploying by using pipelines. Thanks for your comment :)
DeleteIf you know how to link with jenkins, please let me know. Really appreciate the help.
ReplyDeleteI have never used Jenkins but I have experiences with Travis. I think both work in the same way. Let me try Jenkins next time and tell you. You also can try Travis and hope it will help you.
DeleteGood Post, Thanks for sharing!
ReplyDeleteDevOps Training
DevOps Online Training
Your Blog is very nice.. Thanks for sharing your information
ReplyDeleteLearn Devops Online
Devops Online Training in Hyderabad
Post a Comment