An open API service indexing awesome lists of open source software.

https://github.com/d3rhase/rsync-deploy-action

Deploy files to remote server via rsync
https://github.com/d3rhase/rsync-deploy-action

action deploy deployment github-actions rsync

Last synced: about 1 year ago
JSON representation

Deploy files to remote server via rsync

Awesome Lists containing this project

README

          

# What is this? / How to use?

![License](https://img.shields.io/badge/license-MIT-blue.svg)
![Latest Release](https://img.shields.io/github/v/release/D3rHase/rsync-deploy-action?style=flat-square)

This is a GitHub Action designed to deploy files to a remote server using `rsync`. It allows you to easily transfer files from your github repository to a remote server, making it ideal for deployment scenarios.

## Table of Contents

- [Features](#features)
- [Usage](#usage)
- [Action Example](#action-example)
- [Parameters](#parameters)
- [Secrets Configuration](#secrets-configuration)
- [Adding an SSH Key to your Server](#adding-an-ssh-key-to-your-server)
- [How to implement in your workflow Example](#how-to-implement-in-your-workflow)
- [License](#license)

## Features

- **Easy Setup**: Deploy files securely using SSH with minimal configuration.
- **Efficient**: Utilizes `rsync` for fast and incremental file transfers.
- **Customizable**: Allows you to specify paths, server configurations, and SSH keys.

## Usage

### Action example

Here's a action example of how to use this `rsync-action`.

```yaml
- name: Deploy files via rsync
uses: D3rHase/rsync-deploy-action@latest
with:
HOST: ${{ secrets.HOST }}
PORT: ${{ secrets.PORT }}
USER: ${{ secrets.USER }}
PRIVATE_SSH_KEY: ${{ secrets.PRIVATE_SSH_KEY }}
REPOSITORY_PATH: 'path/to/your/files/in/repository/*'
SERVER_PATH: '/path/on/your/server/'

```

### Parameters
You can use plain text instead of the secrets for these values directly in your action, but it is highly recommended to use GitHub Secrets for sensitive information to ensure privacy and security. See [Secrets Configuration](#secrets-configuration).

- `HOST`: The remote server address (IP or domain) - **Required**.
- `PORT`: The port to connect to on the remote server - *Default: 22*.
- `USER`: The username for SSH access - **Required**.
- `PRIVATE_SSH_KEY`: The private SSH key to authenticate with the remote server - **Required**.
- `REPOSITORY_PATH`: The path in your repository to the files/folders you wish to deploy - **Required**.
- `SERVER_PATH`: The destination path on the remote server where files will be deployed - **Required**.

## Secrets Configuration

To keep your credentials secure, store sensitive information like `HOST`, `PORT`, `USER`, and `PRIVATE_SSH_KEY` as [GitHub Secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets). You can add these secrets in your repository's settings under `Secrets and variables` > `Actions` > `Repository secrets`.

## Adding an SSH Key to Your Server

To use this action, you'll need to set up an SSH key on your server. Here's how to do it:

1. **Generate an SSH Key Pair** on your local machine (if you don't have one already):

```sh
ssh-keygen -t rsa -b 4096
```

This command creates a new SSH key using the RSA algorithm with a 4096-bit key length.

2. **Add the SSH Key to the Server**:

Copy the public key (`~/.ssh/id_rsa.pub`) to your server using the `ssh-copy-id` command:

```sh
ssh-copy-id user@your-server-ip
```

Replace `user` with your server's username and `your-server-ip` with the IP address of your server. This command adds your public key to the `~/.ssh/authorized_keys` file on the server.

3. **Test the SSH Connection**:

Verify that you can connect to your server using the SSH key:

```sh
ssh user@your-server-ip
```

4. **Store the SSH Key in GitHub Secrets**:

Go to your repository on GitHub, navigate to `Settings` in your repository > `Secrets and variables` > `Actions`, and add a new repository secret named `PRIVATE_SSH_KEY`. Paste the contents of your private key (`~/.ssh/id_rsa`) into this secret.

**Note**: Ensure your private key remains confidential. Do not share it publicly.

## How to implement in your workflow

This is an example of how you could use it in your GitHub workflow YAML file.

```yaml
name: Example workflow file

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Deploy files via rsync
uses: D3rHase/rsync-deploy-action@latest
with:
HOST: ${{ secrets.HOST }}
PORT: ${{ secrets.PORT }}
USER: ${{ secrets.USER }}
PRIVATE_SSH_KEY: ${{ secrets.PRIVATE_SSH_KEY }}
REPOSITORY_PATH: 'path/to/your/files/in/repository/*'
SERVER_PATH: '/path/on/your/server/'

- name: Notify Deployment Success
run: echo "Deployment to ${{ secrets.HOST }} completed successfully!"
```

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.