Deploy code to your application using gitMay 29, 2014

 

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.

Step 1: Go to Application Management

Tap on “Applications” on the top menu bar, then sSelect your target application from the list.

Cloudways Application Management

Step 2: Generating and downloading SSH keys

We will use these keys to allow access from your Cloudways server to your git repository.

  1. Select the “Deployment via Git” option in the menu.
  2. Now click on the “Generate SSH Keys” button to generate the keys.

Cloudways Git Deployment
Now, click on “Download SSH Keys” to download the SSH Public Key we will use in the next step.

SSH Keys

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.

For Github:

  • Log into Github and select your desired repository. Once done, go to Settings.
  • Here you will find the Deploy keys option.

 

Git Deploy SSH Keys

 

  1. Press “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 into the Key field on Github. You can give a name to this key too in the title field (e.g. Demo). 
  2. 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.

8

Step 5: Deploy code from your repository

  1. Back on Cloudways console, paste the SSH address you got in Step 4 into the “Git Remote Address” field.
  2. Then choose the branch of your repository you want to deploy from. In this example, we use the “master” branch. 
  3. 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, code will be deployed to public_html/.
  4. Finally, click on the “Start Deployment” button to deploy your code to the selected path

Cloudways Git Deployment

 

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 or change the branch you deploy from.

Cloning from Git Repo

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.

11

Git deployment FAQs:

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.

You can use .gitignore to specify a list of files to ignore when cloning / pulling data from the repository into the Cloudways server.

2) What happens to the existing files in the deployment folder when I run a deploy?

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 your are removing it from. It will NOT remove any application specific files or folders from the application root nor change in anyway 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.

 

2 Responses

  1. aryashree padhy says:

    Can we create a new git account inside cloudways. I dont want to pull the old repo to my cloudways. So how do i do that?

  2. Deborah Holtzendorff says:

    You forgot to tell me how to find the Github settings under my photo in the right. I had to get the answer from Github.

Leave a Reply

Still need help? Our support team is waiting to help you. Ask them now