From f850e1ce1e1fbb768d32604634b36f117d45351c Mon Sep 17 00:00:00 2001 From: Luis Bauza Date: Wed, 24 Dec 2025 20:51:28 -0500 Subject: [PATCH] feat: add .env file generation to deployment workflow and update Dockerfile for production dependencies --- .gitea/workflows/deploy-nas.yml | 15 +++++-- Dockerfile | 2 +- GITEA-DEPLOY.md | 79 --------------------------------- 3 files changed, 13 insertions(+), 83 deletions(-) delete mode 100644 GITEA-DEPLOY.md diff --git a/.gitea/workflows/deploy-nas.yml b/.gitea/workflows/deploy-nas.yml index 2035315..7a9a249 100644 --- a/.gitea/workflows/deploy-nas.yml +++ b/.gitea/workflows/deploy-nas.yml @@ -35,6 +35,15 @@ jobs: sudo apt-get update sudo apt-get install -y sshpass + - name: Generate .env file + run: | + cat > .env << EOF + DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} + CLIENT_ID=${{ secrets.DISCORD_CLIENT_ID }} + NANOGPT_API_KEY=${{ secrets.NANOGPT_API_KEY }} + NODE_ENV=production + EOF + - name: Deploy to NAS env: SSH_PASSWORD: ${{ secrets.NAS_SSH_PASSWORD }} @@ -42,9 +51,9 @@ jobs: # 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/ + # Copy Docker files (without .env, it's generated separately) + sshpass -p "$SSH_PASSWORD" scp -o StrictHostKeyChecking=no docker-compose.yml Dockerfile kekbot.tar hllywluis@luis-nas.lan:/mnt/kCloud/Home/hllywluis/kekbot/ + sshpass -p "$SSH_PASSWORD" scp -o StrictHostKeyChecking=no .env 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' diff --git a/Dockerfile b/Dockerfile index b82e677..e106432 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ WORKDIR /app COPY package*.json ./ # Install dependencies -RUN npm ci --only=production +RUN npm ci --omit=dev # Copy application files COPY . . diff --git a/GITEA-DEPLOY.md b/GITEA-DEPLOY.md deleted file mode 100644 index 36c5364..0000000 --- a/GITEA-DEPLOY.md +++ /dev/null @@ -1,79 +0,0 @@ -# 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