Git is a very popular version control system used to implement development workflows.
The Cloudways Platform allows you to deploy code to your application from your git repositories. Your git repository must support git over SSH for this to work.
Deploy Code to Your Application Using Git
Step 1: Go to Application Management
Log into the Cloudways Platform with your credentials. Click on Applications in the top menu bar and select your target application from the list.
Step 2: Generating and Downloading SSH Keys
We will use these keys to allow access from your Cloudways server to your git repository.
Click on the Deployment via Git section in the Application Management area.
Now click on the Generate SSH Keys button to generate the keys.
Now, click on View SSH Key to download the SSH Public Key that we will use in the next step.
Step 3: Upload the SSH Public Key to Your Git Repository
We are using a Github account to exemplify the next two steps. If you are using another git service, you will have to find the equivalent way of completing them.
Log into Github and select your desired repository. Once done, go to Settings.
Here you will find the Deploy keys option.
Click on the Add Deploy Key button to add the SSH key we downloaded in step 3. Simply open the file we downloaded (git_ssh_key.txt), copy the content, and paste it into the Key field on Github. You can give a name to this key too in the title field (e.g. Demo).
Click on the Add Key button to save the SSH key. (for details, visit this Github doc.)
Step 4: Copy the Repository SSH Address
Copy the repository address as shown in the image below. Make sure to copy the SSH address as other formats (like HTTPS) are not supported.
Step 5: Deploy Code from Your Repository
Back on Cloudways console, paste the SSH address you got in Step 4 into the Git Remote Address field and click on the Authenticate. This will ensure that there are no blockers in the communication between Cloudways and Git service (which is Github in our example).
Then choose the branch of your repository (master will be selected as default) you want to deploy from.
Next, type the deployment path (i.e. the folder in your server where the code will be deployed). Make sure to end it with a /. If you leave this field empty, the code will be deployed to public_html/.
Finally, click on the Start Deployment button to deploy your code to the selected path.
Step 6: Repository Successfully Cloned
You will get a notification once the deployment process has been completed.
You have further options to delete the repository from the server (no files will be deleted, see FAQ below), pull the latest changes from the remote, or change the branch.
Step 7: Check Deployment Logs
If you want to analyze your git deployment history (e.g. when and who did a deployment) and other deployment details, just click on the View Deployment Logs button.
That’s it! We hope this tutorial was helpful. If you need any help, then feel free to search your query on Cloudways Support Center or contact us via chat (Need a Hand > Send us a Message). Alternatively, you can also create a support ticket.
1) I want to make sure certain files are not overwritten on the Cloudways server (e.g. configuration files) as they are specific to my development environment.
Unfortunately, this is not a recommended Git practice, and thus we do not provide this feature. The scenario implies that you have tracked files in your Git repository that should not be tracked in the first place. Since these files are included in the .gitignore file (a practice that is not recommended by Git best practices), you have to untrack these files.
2) What happens to the existing files in the deployment folder when I run a deployment?
Deployment does not delete any existing files present on the deployment folder but not on the source repository.
For example, you have these files in the deployment folder: a.php, b.php, image.jpg, and git pull brings changes to a.php and b.php. Both a.php and b.php will be updated, but image.jpeg will remain unchanged.
3) Can I deploy to a specific folder within public_html?
Yes, you can specify the folder within public_html that you want to deploy to. For example, as an application developer, you may have a repository with just a theme, and you can deploy that repository to the theme folder under public_html and instead of the public_html root.
4) Can I still use SFTP to update my application files and folders?
You can do it, but there can be undesired side effects. Any file that you modify via SFTP, will be overwritten with the file in the repository the next time you pull it (if the same change was not done in the repository file).
5) How does the restore process affect the git integration?
Any restore activity overwrites the whole website and reverts it to the point in time you chose to restore from. Running a git pull after the restore will simply update the restored files to the latest version available in the repository.
6) What happens if I remove the git integration through the Cloudways console?
Removing the git integration will just delete the git configuration files related to the particular application you are removing it from. It will NOT remove any application-specific files or folders from the application nor change in any way the source repository.
7) Can I automate the git deployments to Cloudways servers?
We are working on git hooks to automate deployments to Cloudways servers/applications. Meanwhile, we have created a couple of blog posts explaining how to build fully automated deployment workflows using some third-party tools: DeployHQ and Dploy.io.