feat: add Gitea workflow for deploying Kekbot to NAS via SSH
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
name: Deploy to NAS
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: false
|
||||
load: true
|
||||
tags: kekbot:latest
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
- name: Save Docker image
|
||||
run: docker save kekbot:latest -o kekbot.tar
|
||||
|
||||
- name: Install SSH dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y sshpass
|
||||
|
||||
- name: Deploy to NAS
|
||||
env:
|
||||
SSH_PASSWORD: ${{ secrets.NAS_SSH_PASSWORD }}
|
||||
run: |
|
||||
# Create app directory on NAS
|
||||
sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no hllywluis@luis-nas.lan "mkdir -p /mnt/kCloud/Home/hllywluis/kekbot"
|
||||
|
||||
# Copy Docker files
|
||||
sshpass -p "$SSH_PASSWORD" scp -o StrictHostKeyChecking=no docker-compose.yml Dockerfile .env hllywluis@luis-nas.lan:/mnt/kCloud/Home/hllywluis/kekbot/
|
||||
sshpass -p "$SSH_PASSWORD" scp -o StrictHostKeyChecking=no kekbot.tar hllywluis@luis-nas.lan:/mnt/kCloud/Home/hllywluis/kekbot/
|
||||
|
||||
# Load Docker image and deploy
|
||||
sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no hllywluis@luis-nas.lan << 'EOF'
|
||||
cd /mnt/kCloud/Home/hllywluis/kekbot
|
||||
docker load -i kekbot.tar
|
||||
docker-compose down || true
|
||||
docker-compose up -d
|
||||
EOF
|
||||
@@ -0,0 +1,79 @@
|
||||
# Gitea Workflow Deployment to NAS
|
||||
|
||||
This guide explains how to set up the Gitea workflow to deploy Kekbot to your NAS via SSH.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. **Docker and Docker Compose** must be installed on your NAS
|
||||
2. **SSH access** enabled on your NAS with password authentication
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
### 1. Add SSH Password Secret to Gitea
|
||||
|
||||
1. Go to your Gitea repository
|
||||
2. Navigate to **Settings** → **Secrets** (or **Actions** → **Secrets**)
|
||||
3. Add a new secret named `NAS_SSH_PASSWORD`
|
||||
4. Set the value to your NAS user password (hllywluis)
|
||||
|
||||
### 2. Verify NAS Configuration
|
||||
|
||||
Ensure your NAS has:
|
||||
|
||||
- Docker installed
|
||||
- Docker Compose installed
|
||||
- SSH server running on port 22
|
||||
- Password authentication enabled for SSH
|
||||
|
||||
### 3. Test SSH Access (Optional)
|
||||
|
||||
Before running the workflow, you can test SSH access:
|
||||
|
||||
```bash
|
||||
ssh hllywluis@luis-nas.lan
|
||||
```
|
||||
|
||||
## Workflow Configuration
|
||||
|
||||
The workflow file is located at [`.gitea/workflows/deploy-nas.yml`](.gitea/workflows/deploy-nas.yml)
|
||||
|
||||
### How It Works
|
||||
|
||||
1. **Build**: Builds the Docker image locally using Docker Buildx
|
||||
2. **Save**: Saves the Docker image as a tar archive
|
||||
3. **Transfer**: Uses `sshpass` to SSH into your NAS and copy files
|
||||
4. **Deploy**: Loads the Docker image and runs `docker-compose up -d`
|
||||
|
||||
### Manual Trigger
|
||||
|
||||
You can manually trigger the deployment by:
|
||||
|
||||
1. Going to your Gitea repository
|
||||
2. Navigating to **Actions**
|
||||
3. Selecting the **Deploy to NAS** workflow
|
||||
4. Clicking **Run workflow**
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### SSH Connection Failed
|
||||
|
||||
If the workflow fails with SSH connection issues:
|
||||
|
||||
- Verify `NAS_SSH_PASSWORD` secret is set correctly
|
||||
- Check that the NAS is reachable at `luis-nas.lan`
|
||||
- Ensure SSH password authentication is enabled on the NAS
|
||||
|
||||
### Docker Errors
|
||||
|
||||
If Docker fails on the NAS:
|
||||
|
||||
- Verify Docker is running: `docker ps`
|
||||
- Check Docker Compose: `docker-compose --version`
|
||||
- Review logs: `docker-compose logs`
|
||||
|
||||
### Permission Issues
|
||||
|
||||
The workflow uses the `hllywluis` user. If you need a different user:
|
||||
|
||||
1. Update the `hllywluis@luis-nas.lan` in the workflow file
|
||||
2. Adjust the `/mnt/kCloud/Home/hllywluis/kekbot` directory permissions accordingly
|
||||
Reference in New Issue
Block a user