Skip to content

Deployment from GitHub, Bitbucket, GitLab

Basic Steps to Deploy from a Remote Git Repository

When deploying projects from GitHub, Bitbucket, GitLab, or a custom Git server, you need to follow three steps:

  1. Clone the remote Git repository to your server.
  2. Start the app/service from the cloned repository on the server (using Docker or systemd in our case).
  3. Update the proxy server configuration (Caddy in our case) to link a domain to the app/service and enable automated HTTPS.

These steps can be done manually or automated entirely—where the server redeploys your project after you push changes to the remote Git repository or approve a pull request (this is called GitOps or push-to-deploy). In this chapter, we’ll cover how to implement both options. The best part is that we’ll do it without using any additional third-party CI/CD services. It may sound surprising, but you don’t need any external CI/CD services, and your deployment speed will likely be faster. For example, redeploying a mid-complexity Node.js project, or similar runtimes that don’t require building, can take just 5-15 seconds. This is much faster compared to many third-party services, where deployments can easily take minutes.

Deploy from GitHub, Bitbucket, and GitLab Manually

Prerequisites

  • A GitHub, Bitbucket, or GitLab repository

Steps

Note: All commands below should be run on the server after SSHing into it, not on your local machine.

  • SSH into your server and generate an SSH key with default options. This will be used as an access key for your remote Git repository. An access key is an SSH key, usually with read-only permission, that allows you to clone repositories.
ssh root@ip_address_of_server
ssh-keygen -t ed25519 -C "your_email@example.com"

For more details on generating SSH keys, see the GitHub guide.

  • Copy the public SSH key you just created. Run the command below to print your new public key, then copy the contents of the id_ed25519.pub file to your clipboard.
cat ~/.ssh/id_ed25519.pub
  • Add the SSH key to your repository:

    • For GitHub (see the full guide here):

      • In the upper-right corner of any page on GitHub, click your profile photo, then click Settings.
      • In the "Access" section of the sidebar, click SSH and GPG keys.
      • Click New SSH key or Add SSH key.
      • In the "Key" field, paste your public key.
    • For Bitbucket (see the full guide here):

      • In Bitbucket, go to the Settings tab for the project or repository.
      • Click Access keys and then Add key.
      • Paste the key into the text box.
      • Choose the Read permission.
    • For GitLab (see the full guide here):

      • On the left sidebar, select Search or go to and find your project.
      • Select Settings > Repository.
      • Expand Deploy keys.
      • Select Add new key.
      • Complete the fields.
  • Clone the repository from GitHub, Bitbucket, or GitLab. Use the repository URL with https for public repositories and git@ for private ones.

git clone repository_url
  • Start the app/service:

If you use Dockerfile (replace ~/demo_app with your project folder name, and 4004 with your app’s port):

sudo docker build ~/demo_app -t demo_app_image
sudo docker container rm demo_app_container --force
sudo docker run -it -d --restart unless-stopped --name demo_app_container -p 4004:4004 demo_app_image

If you use systemd, ensure that you can start your app/service with the start script created in the "Prepare Project" chapter. If the command sh ~/demo_app/start.sh works without errors, follow these steps to create a systemd service file and start your app/service:

sudo echo -e "[Unit]\nDescription=DemoApp Agent\nWants=basic.target network-online.target nss-lookup.target time-sync.target\nAfter=basic.target network.target network-online.target" >> /etc/systemd/system/demo_app.service

sudo echo -e "[Service]\nSyslogIdentifier=demo_app\nExecStart=$HOME/demo_app/start.sh\nRestart=always" >> /etc/systemd/system/demo_app.service

sudo echo -e "[Install]\nWantedBy=multi-user.target" >> /etc/systemd/system/demo_app.service

sudo systemctl enable demo_app.service
sudo systemctl start demo_app.service
  • Set up a proxy server to link your domain (e.g., demo.turbocloud.dev) to your app/service running on port 4004:
sudo echo -e "demo.turbocloud.dev {\nreverse_proxy * localhost:4004\n}" >> /etc/caddy/Caddyfile
caddy reload -c /etc/caddy/Caddyfile
  • Test your app/service:
    Wait 30-60 seconds, then try accessing your app/service in a browser at https://demo.turbocloud.dev. If everything went well, your app/service should now be live.

If the deployed project doesn’t work, review the steps again. Still not working? Contact us at hey@turbocloud.dev with details on what you're trying to achieve, the steps you've taken, and any errors you’ve encountered. The more details you provide, the faster we can assist.