How to deploy your code from sourceLair to DigitalOcean

This is a brief guide about deploying your code from SourceLair to DigitalOcean. It requires you to have already a project on SourceLair.

Preparing your Digital Ocean server

  1. Create a new Droplet at Digital Ocean following this guide. We'll use Ubuntu, but your favorite OS will be fine.
  2. Make sure your Droplet is up to date by running

    sudo apt-get update && sudo apt-get upgrade -y
  3. Install apache2 and git
    • If you're using Ubuntu, just type:

      sudo apt-get update && sudo apt-get install -y git apache2
    • If you're using another OS, choose the package manager of your choice
  4. You're ready to go!


1. Put SourceLair public keys to DigitalOcean

The first step is to install your SourceLair public key to your DigitalOcean server. To do that, log into your DigitalOcean server and then run the following command curl | bash Don't forget to replace username with your username at SourceLair.

2. Create git and site directories on your server

In order to get our code working on our DigitalOcean server, we will need one directory to keep our files and one to keep our git data. Assuming that we're deploying a simple site to apache, we'll navigate to our home directory (cd ~) and then create our directory there (mkdir site.git). We'll keep our files in /var/www/html .

3. Initialize empty git repository

We will initialize an empty git repository in the site.git directory, by running git init --bare site.git

4. Add a post-receive hook

Now we have to add a post receive hook, in order to deploy the latest pushed code to our DigitalOcean server. We will do this in two steps:

i. Create the hook file
echo -e "#! /bin/sh\n\
git --work-tree=/var/www/html/ --git-dir=$HOME/site.git checkout -f" > site.git/hooks/post-receive
ii. Make the hook file executable
chmod u+x site.git/hooks/post-receive

5. Add DigitalOcean remote

Next, you have to add a new Git remote in order to be able to push your code to your DigitalOcean server.

6. Push to DigitalOcean from SourceLair

You have to push your code to your DigitalOcean server. To do that invoke the Push to remote command from Command Palette and then select the DigitalOcean remote that you created above.

7. Navigate to your newly deployed site

Last, just navigate to your droplet's IP address in your browser and enjoy your new website.