How to Deploy Your Files Using rsync with GitHub Actions

Nov 16, 2023 | Programming

Are you tired of the tedious manual process of deploying your files to a remote server? Look no further! This guide will walk you through the seamless deployment of your files using rsync with GitHub Actions. With just a few lines of code, you’ll be able to set up automated deployments that are fast, efficient, and hassle-free.

What is rsync?

rsync is a powerful tool that helps you synchronize files and directories between two locations. It’s particularly useful in deployment scenarios since it only transfers the changes, making it faster and conserving bandwidth.

Setting Up Your GitHub Action

To deploy files from your GITHUB_WORKSPACE to a remote folder, you’ll employ the power of GitHub Actions. Follow these steps to set it up:

1. Define Your Inputs

  • switches – Initial required rsync flags, such as -avzr --delete.
  • remote_host* – The remote host to which you are deploying.
  • remote_user* – Your SSH username on the remote host.
  • remote_key* – Your SSH private key.
  • remote_path* – The deployment target path.
  • legacy_allow_rsa_hostkeys – Support for legacy RSA host keys (true/false).

* = Required fields

2. Example of a Simple YAML Configuration

Here’s a basic example of a YAML file that defines your deployment process:

name: DEPLOY
on:
  push:
    branches:
      - master
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: rsync deployments
        uses: burnett01/rsync-deployments@7.0.1
        with:
          switches: -avzr --delete
          path: src
          remote_path: /var/www/html
          remote_host: example.com
          remote_user: debian
          remote_key: ${{ secrets.DEPLOY_KEY }}

Understanding the YAML Configuration

Think of the YAML configuration like a recipe in a cookbook. Each ingredient is like an input you need to specify for your deployment to be successful:

  • **The name** – Represents the title of your recipe (in this case, the deployment).
  • **The on section** – When triggers are listed, it’s like defining when you want to bake the dish (i.e., on a push to the master branch).
  • **The jobs section** – The series of steps you’ll follow to achieve your delicious end result.
  • **Using the ‘rsync’ action** – This is the method you use to mix your ingredients correctly (in our case, deploying files).

3. Advanced Configuration

For more complex deployments where you may want to include or exclude certain files, your configuration might look like this:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: rsync deployments
        uses: burnett01/rsync-deployments@7.0.1
        with:
          switches: -avzr --delete --exclude= --include= --filter=
          path: src
          remote_path: /var/www/html
          remote_host: example.com
          remote_port: 5555
          remote_user: debian
          remote_key: ${{ secrets.DEPLOY_KEY }}

Troubleshooting Your Deployment

If you encounter any issues during your rsync deployment, consider these troubleshooting tips:

  • Ensure that your SSH keys are correctly configured. The public key should be in the authorized_keys file on the remote server.
  • Check that you are using the correct ports and usernames.
  • Review the switches you are using; misconfigured options can lead to connection problems.
  • If your remote OpenSSH server uses RSA host keys, enable legacy support by setting legacy_allow_rsa_hostkeys: true.
  • Don’t forget to validate that your GitHub secrets are correctly set up and referenced.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Final Thoughts

Automating your deployments using rsync and GitHub Actions can significantly streamline your workflow and reduce errors associated with manual processes. With a few adjustments, you can tailor the script to fit your project needs.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox