|
| 1 | +# Zero downtime deployment |
| 2 | + |
| 3 | +## Overview |
| 4 | +This GitHub Action helps you deploy your project to a remote server with zero downtime, ensuring that your application remains available during deployments. |
| 5 | + |
| 6 | +## Features |
| 7 | +- **Zero Downtime Deployment**: Ensure uninterrupted service during deployments. |
| 8 | +- **Multi-Technology Support**: Currently supporting Laravel, with more technologies being added. |
| 9 | +- **Easy Integration**: Simple setup and integration into your existing workflow. |
| 10 | +- **Flexible Deployment**: Suitable for projects of all sizes, from personal projects to enterprise applications. |
| 11 | +- **Custom Scripts**: Run custom scripts before and after key deployment steps. |
| 12 | +- **Secure**: Uses GitHub Secrets for sensitive data like server credentials and GitHub tokens. |
| 13 | +- **Environment File Sync**: Sync environment variables with the remote server. |
| 14 | + |
| 15 | +## Example Usage |
| 16 | + |
| 17 | +Here's an example workflow configuration that uses the `DeployRepository/zero-downtime-deployment@v1.0.0` action: |
| 18 | + |
| 19 | +> [!IMPORTANT] |
| 20 | +> You need to add the following secrets to your repository: |
| 21 | +
|
| 22 | +- **GH_TOKEN**: You'll need to provide the action with a **Personal Access Token (PAT)**, Permission we need is `repo` |
| 23 | + [How To create](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic) |
| 24 | +- **REMOTE_HOST**: the host of the server |
| 25 | +- **REMOTE_USER**: the username of the server |
| 26 | +- **REMOTE_PASSWORD**: the password of the server |
| 27 | +- **REMOTE_PORT**: the port of the server |
| 28 | +- **ENV_FILE**: the content of the environment file to sync with `.env` |
| 29 | + |
| 30 | +### Notes |
| 31 | +- The `target` input should be the path to the directory where the project will be deployed on the server (ex: /home/www/test.com). |
| 32 | +- The `target/current/public` directory should be the root of the domain. |
| 33 | +- Use the `${{ github.sha }}` variable to pass the commit SHA to the `sha` input. |
| 34 | + |
| 35 | +### Start Use with Laravel |
| 36 | +To use this action in your workflow, you need to add the following step in your GitHub Actions workflow file (`.github/workflows/your-workflow.yml`): |
| 37 | + |
| 38 | +```yaml |
| 39 | +name: deploy to server |
| 40 | + |
| 41 | +concurrency: |
| 42 | + group: production |
| 43 | + cancel-in-progress: true |
| 44 | + |
| 45 | +on: |
| 46 | + release: |
| 47 | + types: [released] |
| 48 | + |
| 49 | +jobs: |
| 50 | + deployment: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + environment: production |
| 53 | + |
| 54 | + steps: |
| 55 | + - name: Deploy Laravel project |
| 56 | + uses: DeployRepository/zero-downtime-deployment@v1.0.0 |
| 57 | + with: |
| 58 | + host: ${{ secrets.REMOTE_HOST }} |
| 59 | + username: ${{ secrets.REMOTE_USER }} |
| 60 | + password: ${{ secrets.REMOTE_PASSWORD }} |
| 61 | + port: ${{ secrets.REMOTE_PORT }} |
| 62 | + target: '/home/www/test.com' # Path to the directory where the project will be deployed |
| 63 | + sha: ${{ github.sha }} |
| 64 | + github_token: ${{ secrets.GH_TOKEN }} |
| 65 | + env_file: ${{ secrets.ENV_FILE }} |
| 66 | + # run_script_before_check_folders: ls -la |
| 67 | + # run_script_after_check_folders: ls -la |
| 68 | + # run_script_before_download: ls -la |
| 69 | + run_script_after_download: | |
| 70 | + cd $THIS_RELEASE_PATH |
| 71 | + composer install --prefer-dist |
| 72 | + php artisan migrate --force |
| 73 | + php artisan storage:link |
| 74 | + # run_script_before_activate: ls -la |
| 75 | + run_script_after_activate: | |
| 76 | + cd $ACTIVE_RELEASE_PATH |
| 77 | + php artisan optimize |
| 78 | +``` |
| 79 | +For test, go and create your first release, you can see process of deploy in tab of actions in your repo |
| 80 | +
|
| 81 | +## Support |
| 82 | +If you need help or have any questions, feel free to reach out to me at [Discussion](https://github.com/DeployRepository/zero-downtime-deployment/discussions). |
| 83 | +
|
| 84 | +## This GitHub Action Is Sponsorware 💰💰💰 |
| 85 | +Originally, this github action was only available to my sponsors on GitHub Sponsors until I reached 100 sponsors. |
| 86 | +
|
| 87 | +<!-- Now that we've reached the goal, the github action is fully open source. --> |
| 88 | +
|
| 89 | +Enjoy, and thanks for the support! ❤️ [Become a sponsor](https://github.com/sponsors/DeployRepository) |
| 90 | +
|
| 91 | +Learn more about Sponsorware at github.com/sponsorware/docs 💰. |
| 92 | +
|
| 93 | +## Custom Scripts |
| 94 | +You can provide custom scripts to run at various stages of the deployment. Below are the supported stages where you can run your scripts: |
| 95 | +
|
| 96 | +- **Before Checking Folders**: `run_script_before_check_folders` |
| 97 | +- **After Checking Folders**: `run_script_after_check_folders` |
| 98 | +- **Before Downloading Release**: `run_script_before_download` |
| 99 | +- **After Downloading Release**: `run_script_after_download` |
| 100 | +- **Before Activating Release**: `run_script_before_activate` |
| 101 | +- **After Activating Release**: `run_script_after_activate` |
| 102 | + |
| 103 | +## Troubleshooting |
| 104 | +If you encounter issues, check the GitHub Actions logs for detailed error messages. Ensure that: |
| 105 | +- SSH credentials are correct. |
| 106 | +- The target directory on the remote server has the necessary permissions. |
| 107 | +- The specified Git commit SHA exists in your repository. |
| 108 | + |
| 109 | +## Inputs |
| 110 | + |
| 111 | +| Name | Description | Required | Default | |
| 112 | +|------------------------------|------------------------------------------------|----------|---------| |
| 113 | +| `host` | Remote server host | Yes | | |
| 114 | +| `username` | Remote server username | Yes | | |
| 115 | +| `password` | Remote server password | Yes | | |
| 116 | +| `port` | Remote server port | Yes | `22` | |
| 117 | +| `target` | Remote server target path | Yes | | |
| 118 | +| `sha` | Git commit SHA to deploy (use `${{ github.sha }}`) | Yes | | |
| 119 | +| `github_token` | GitHub token | Yes | | |
| 120 | +| `env_file` | Content of the environment file to sync with `.env` | No | | |
| 121 | +| `run_script_before_check_folders` | Script to run before checking folders | No | `false` | |
| 122 | +| `run_script_after_check_folders` | Script to run after checking folders | No | `false` | |
| 123 | +| `run_script_before_download` | Script to run before downloading release | No | `false` | |
| 124 | +| `run_script_after_download` | Script to run after downloading release | No | `false` | |
| 125 | +| `run_script_before_activate` | Script to run before activating release | No | `false` | |
| 126 | +| `run_script_after_activate` | Script to run after activating release | No | `false` | |
| 127 | + |
| 128 | +## Security |
| 129 | +Ensure that sensitive data such as server credentials and GitHub tokens are stored securely using GitHub Secrets. |
| 130 | + |
| 131 | +## License |
| 132 | + |
| 133 | +This repository and the code within are proprietary. Access is granted to sponsors only. Please see the [LICENSE](LICENSE.md) file for more information. |
| 134 | + |
| 135 | +## Contribution and Issues |
| 136 | +If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request on the [GitHub repository](https://github.com/DeployRepository/zero-downtime-deployment). |
| 137 | + |
| 138 | +This documentation should provide a clear and comprehensive guide for users to get started with your GitHub Action. |
0 commit comments