91 lines
4.1 KiB
Markdown
91 lines
4.1 KiB
Markdown
<p align="center"><img src="assets/logo.png" alt="Interweb" width="280"></p>
|
|
|
|
# Deploy on Interweb Mozambique VPS
|
|
|
|
<!-- badges:start -->
|
|
[](https://git.interweb.co.mz/interweb-mz/deploy-on-vps/releases) [](LICENSE)
|
|
<!-- badges:end -->
|
|
|
|
A GitHub Action that publishes your site on your Interweb Mozambique VPS. It asks the Interweb Mozambique API which server to use and what its IP is, checks that it is running, and copies the files with rsync over SSH.
|
|
|
|
[Português](README-pt.md)
|
|
|
|
## Before you start
|
|
|
|
1. **API key.** Create one in the [API Center](https://www.meu.interweb.co.mz/api-center.php) of Meu Interweb with the `vps:read` permission (add `vps:write` if you want the action to start a stopped server). Save it in your repository as the secret `INTERWEB_API_KEY`.
|
|
2. **SSH key.** Make a key pair just for deploys (`ssh-keygen -t ed25519 -f deploy_key -N ""`), add `deploy_key.pub` to `~/.ssh/authorized_keys` of the user on the VPS, and save the private key as the secret `VPS_SSH_KEY`.
|
|
3. **Host key (recommended).** Run `ssh-keyscan -p 22 YOUR_VPS_IP` and save the output as the secret `VPS_KNOWN_HOSTS`. Without it, the action trusts the key the server shows at deploy time.
|
|
|
|
## Example
|
|
|
|
`.github/workflows/deploy.yml`:
|
|
|
|
```yaml
|
|
name: Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
# Build your site here if needed, for example: npm ci && npm run build
|
|
|
|
- uses: interweb-mz/deploy-on-vps@v1
|
|
with:
|
|
api-key: ${{ secrets.INTERWEB_API_KEY }}
|
|
ssh-private-key: ${{ secrets.VPS_SSH_KEY }}
|
|
known-hosts: ${{ secrets.VPS_KNOWN_HOSTS }}
|
|
source: ./public
|
|
target: /var/www/html
|
|
delete: true
|
|
exclude: |
|
|
.env
|
|
uploads/
|
|
post-command: systemctl reload nginx
|
|
```
|
|
|
|
With a single active VPS on the account there is nothing else to say. With several, choose one with `server-id` (the id of its service) or `server-name` (its hostname or IP).
|
|
|
|
## Inputs
|
|
|
|
| Input | Default | What it does |
|
|
|---|---|---|
|
|
| `api-key` | | API key with `vps:read`. Empty uses the `INTERWEB_API_KEY` environment variable. |
|
|
| `server-id` / `server-name` | | Which VPS. Empty uses the only active VPS of the account. |
|
|
| `ssh-private-key` | | Private SSH key (required). |
|
|
| `ssh-user` | `root` | SSH user. |
|
|
| `ssh-port` | `22` | SSH port. |
|
|
| `known-hosts` | | Host key of the VPS, from `ssh-keyscan`. |
|
|
| `host` | | Connect to this address instead of the main IP, such as an additional IP. |
|
|
| `source` | `.` | Folder of the repository to publish. |
|
|
| `target` | | Folder on the VPS (required), such as `/var/www/html`. |
|
|
| `delete` | `false` | Delete files on the VPS that are not in `source`. |
|
|
| `exclude` | | Paths to leave out, one per line. `.git/` and `.github/` never go. |
|
|
| `rsync-options` | | Extra rsync options, such as `--chmod=D755,F644`. |
|
|
| `pre-command` / `post-command` | | Commands run on the VPS, inside `target`, before and after the copy. |
|
|
| `start-if-stopped` | `false` | Start the VPS through the API if it is stopped (needs `vps:write`). |
|
|
| `wait-timeout` | `600` | Seconds to wait for the VPS to be running. |
|
|
| `dry-run` | `false` | Show what would be copied, without copying. |
|
|
|
|
Outputs: `server-id`, `server-name`, `ip` and `power-state`.
|
|
|
|
## Good to know
|
|
|
|
- Runs on Linux and macOS runners (they have rsync, ssh and Python 3). Nothing is downloaded.
|
|
- A suspended VPS stops the deploy with a clear message. A VPS that is starting or restarting is waited for.
|
|
- With a `sandbox_` key the API calls are simulated: starting a stopped server does nothing. The copy itself is real, because it goes over SSH.
|
|
- If your key only accepts some IP addresses, remember that GitHub runners change IP. Use a self-hosted runner or leave the IP list empty for this key.
|
|
- The API docs for servers: https://docs.interweb.co.mz/servers/
|
|
|
|
## License
|
|
|
|
MIT. See [LICENSE](LICENSE).
|
|
|
|
---
|
|
|
|
Maintained by RLX Holdings.
|