fc
This commit is contained in:
parent
0015585819
commit
b778d91196
88 changed files with 84184 additions and 0 deletions
77
deployment-configs-appaibuiltest/.forgejo/workflows/cicd.yml
Normal file
77
deployment-configs-appaibuiltest/.forgejo/workflows/cicd.yml
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
name: AppAIBuildTest-cicd
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
workflow_dispatch: {}
|
||||
|
||||
jobs:
|
||||
build_test_deploy_test:
|
||||
runs-on: docker
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: "9.0.x"
|
||||
|
||||
- name: Test
|
||||
run: dotnet test -c Release
|
||||
|
||||
- name: Publish (self-contained linux-x64)
|
||||
run: dotnet publish -c Release -r linux-x64 --self-contained true -o out
|
||||
|
||||
- name: Install deploy tools
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y rsync openssh-client
|
||||
|
||||
- name: Deploy TEST
|
||||
env:
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
run: |
|
||||
set -e
|
||||
mkdir -p ~/.ssh
|
||||
chmod 700 ~/.ssh
|
||||
echo "$DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts
|
||||
|
||||
rsync -az --delete out/ "$DEPLOY_USER@$DEPLOY_HOST:/opt/appaibuiltest-test/app/"
|
||||
ssh "$DEPLOY_USER@$DEPLOY_HOST" "chmod +x /opt/appaibuiltest-test/app/AppAIBuildTest && sudo systemctl restart appaibuiltest-test"
|
||||
|
||||
deploy_prod_manual:
|
||||
if: ${{ github.event_name == 'workflow_dispatch' }}
|
||||
runs-on: docker
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: "9.0.x"
|
||||
|
||||
- name: Publish (self-contained linux-x64)
|
||||
run: dotnet publish -c Release -r linux-x64 --self-contained true -o out
|
||||
|
||||
- name: Install deploy tools
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y rsync openssh-client
|
||||
|
||||
- name: Deploy PROD
|
||||
env:
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
run: |
|
||||
set -e
|
||||
mkdir -p ~/.ssh
|
||||
chmod 700 ~/.ssh
|
||||
echo "$DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts
|
||||
|
||||
rsync -az --delete out/ "$DEPLOY_USER@$DEPLOY_HOST:/opt/appaibuiltest/app/"
|
||||
ssh "$DEPLOY_USER@$DEPLOY_HOST" "chmod +x /opt/appaibuiltest/app/AppAIBuildTest && sudo systemctl restart appaibuiltest"
|
||||
160
deployment-configs-appaibuiltest/README.md
Normal file
160
deployment-configs-appaibuiltest/README.md
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
# AppAIBuildTest - Deployment Configuration
|
||||
|
||||
**Generated:** 2026-01-30
|
||||
|
||||
## Overview
|
||||
|
||||
This folder contains all configuration files needed to deploy **AppAIBuildTest** to your infrastructure:
|
||||
|
||||
- **Server:** 192.168.1.43 (Ubuntu 24.04)
|
||||
- **Forgejo:** 192.168.1.63:3000
|
||||
- **.NET Version:** 9.0.x
|
||||
|
||||
## Environments
|
||||
|
||||
### TEST Environment
|
||||
- **Port:** 5100
|
||||
- **Domain:** http://test-appaibuiltest.jarjarbinks
|
||||
- **Folder:** /opt/appaibuiltest-test/app
|
||||
- **Service:** appaibuiltest-test
|
||||
- **Deploy:** Automatic on `git push` to main
|
||||
|
||||
### PROD Environment
|
||||
- **Port:** 5200
|
||||
- **Domain:** http://appaibuiltest.jarjarbinks
|
||||
- **Folder:** /opt/appaibuiltest/app
|
||||
- **Service:** appaibuiltest
|
||||
- **Deploy:** Manual via workflow_dispatch
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
### 1. Configure Forgejo Secrets
|
||||
|
||||
Go to your repository in Forgejo → Settings → Actions → Secrets
|
||||
|
||||
Required secrets (should already exist):
|
||||
- `DEPLOY_HOST` = `192.168.1.43`
|
||||
- `DEPLOY_USER` = `deploy`
|
||||
- `DEPLOY_SSH_KEY` = SSH private key for deploy user
|
||||
|
||||
### 2. Copy Workflow to Repository
|
||||
|
||||
```bash
|
||||
# In your repository
|
||||
mkdir -p .forgejo/workflows
|
||||
cp .forgejo/workflows/cicd.yml YOUR_REPO/.forgejo/workflows/
|
||||
cd YOUR_REPO
|
||||
git add .forgejo/workflows/cicd.yml
|
||||
git commit -m "Add CI/CD workflow"
|
||||
git push
|
||||
```
|
||||
|
||||
### 3. Setup Server
|
||||
|
||||
```bash
|
||||
# Copy files to server (via MobaXterm SFTP or scp)
|
||||
# Upload: systemd, scripts folders to ~/appaibuiltest-setup/
|
||||
|
||||
# SSH to server
|
||||
ssh your-user@192.168.1.43
|
||||
|
||||
# Create dotnet-service user (if not exists)
|
||||
sudo useradd -r -s /bin/false dotnet-service
|
||||
|
||||
# Run setup script
|
||||
cd ~/appaibuiltest-setup
|
||||
chmod +x scripts/setup-server.sh
|
||||
sudo ./scripts/setup-server.sh
|
||||
|
||||
# Setup script will automatically:
|
||||
# - Install systemd services
|
||||
# - Create app directories
|
||||
# - Configure Caddy reverse proxy via API
|
||||
```
|
||||
|
||||
## Deployment
|
||||
|
||||
### Deploy to TEST
|
||||
|
||||
```bash
|
||||
git push origin main
|
||||
```
|
||||
|
||||
Check deployment:
|
||||
```bash
|
||||
# On server
|
||||
sudo systemctl status appaibuiltest-test
|
||||
sudo journalctl -u appaibuiltest-test -n 50
|
||||
|
||||
# Test locally
|
||||
curl http://127.0.0.1:5100
|
||||
|
||||
# Test via Caddy
|
||||
curl http://test-appaibuiltest.jarjarbinks
|
||||
```
|
||||
|
||||
### Deploy to PROD
|
||||
|
||||
1. Go to Forgejo → Repository → Actions
|
||||
2. Select the workflow
|
||||
3. Click **Run workflow**
|
||||
4. Confirm deployment
|
||||
|
||||
Check deployment:
|
||||
```bash
|
||||
# On server
|
||||
sudo systemctl status appaibuiltest
|
||||
sudo journalctl -u appaibuiltest -n 50
|
||||
|
||||
# Test locally
|
||||
curl http://127.0.0.1:5200
|
||||
|
||||
# Test via Caddy
|
||||
curl http://appaibuiltest.jarjarbinks
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Service Issues
|
||||
|
||||
```bash
|
||||
# TEST service
|
||||
sudo systemctl status appaibuiltest-test
|
||||
sudo journalctl -u appaibuiltest-test -n 100 -f
|
||||
|
||||
# PROD service
|
||||
sudo systemctl status appaibuiltest
|
||||
sudo journalctl -u appaibuiltest -n 100 -f
|
||||
```
|
||||
|
||||
### Check Ports
|
||||
|
||||
```bash
|
||||
ss -lntp | grep 5100
|
||||
ss -lntp | grep 5200
|
||||
```
|
||||
|
||||
### Restart Services
|
||||
|
||||
```bash
|
||||
sudo systemctl restart appaibuiltest-test
|
||||
sudo systemctl restart appaibuiltest
|
||||
sudo systemctl reload caddy
|
||||
```
|
||||
|
||||
## File Structure
|
||||
|
||||
```
|
||||
/opt/appaibuiltest-test/app/ # TEST deployment (owned by dotnet-service)
|
||||
/opt/appaibuiltest/app/ # PROD deployment (owned by dotnet-service)
|
||||
/etc/systemd/system/appaibuiltest-test.service
|
||||
/etc/systemd/system/appaibuiltest.service
|
||||
Caddy routes configured via API # No manual Caddyfile editing needed
|
||||
```
|
||||
|
||||
## Technical Details
|
||||
|
||||
- **Service User:** `dotnet-service` (restricted system user for running .NET apps)
|
||||
- **Caddy Configuration:** Via API (automatic, no manual file editing)
|
||||
- **Deployment Method:** rsync over SSH from Forgejo CI/CD
|
||||
- **Process Manager:** systemd with auto-restart
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# TEST Environment
|
||||
http://test-appaibuiltest.jarjarbinks {
|
||||
reverse_proxy 127.0.0.1:5100
|
||||
}
|
||||
|
||||
# PRODUCTION Environment
|
||||
http://appaibuiltest.jarjarbinks {
|
||||
reverse_proxy 127.0.0.1:5105
|
||||
}
|
||||
86
deployment-configs-appaibuiltest/scripts/setup-server.sh
Normal file
86
deployment-configs-appaibuiltest/scripts/setup-server.sh
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#!/bin/bash
|
||||
# Setup script for AppAIBuildTest deployment
|
||||
# Run this on the webserver (192.168.1.43)
|
||||
|
||||
set -e
|
||||
|
||||
echo "==================================="
|
||||
echo "Setting up AppAIBuildTest on server"
|
||||
echo "==================================="
|
||||
|
||||
# Create TEST directories
|
||||
echo "Creating TEST environment directories..."
|
||||
sudo mkdir -p /opt/appaibuiltest-test/app
|
||||
sudo chown -R dotnet-service:dotnet-service /opt/appaibuiltest-test
|
||||
|
||||
# Install TEST systemd service
|
||||
echo "Installing TEST systemd service..."
|
||||
sudo cp systemd/appaibuiltest-test.service /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable appaibuiltest-test
|
||||
echo "✓ TEST service installed: appaibuiltest-test"
|
||||
|
||||
# Create PROD directories
|
||||
echo "Creating PROD environment directories..."
|
||||
sudo mkdir -p /opt/appaibuiltest/app
|
||||
sudo chown -R dotnet-service:dotnet-service /opt/appaibuiltest
|
||||
|
||||
# Install PROD systemd service
|
||||
echo "Installing PROD systemd service..."
|
||||
sudo cp systemd/appaibuiltest.service /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable appaibuiltest
|
||||
echo "✓ PROD service installed: appaibuiltest"
|
||||
|
||||
# Configure Caddy via API
|
||||
echo ""
|
||||
echo "Configuring Caddy reverse proxy via API..."
|
||||
|
||||
# Function to add route via Caddy API
|
||||
add_caddy_route() {
|
||||
local domain=$1
|
||||
local port=$2
|
||||
local env_name=$3
|
||||
|
||||
# Check if route already exists
|
||||
if curl -s http://localhost:2019/config/apps/http/servers/srv0/routes | grep -q "$domain"; then
|
||||
echo "⚠ $env_name route ($domain) already exists - skipping"
|
||||
else
|
||||
echo "Adding $env_name route: $domain -> 127.0.0.1:$port"
|
||||
curl -X POST "http://localhost:2019/config/apps/http/servers/srv0/routes/0" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"@id\": \"${domain//./_}\",
|
||||
\"match\": [{\"host\": [\"$domain\"]}],
|
||||
\"handle\": [{
|
||||
\"handler\": \"reverse_proxy\",
|
||||
\"upstreams\": [{\"dial\": \"127.0.0.1:$port\"}]
|
||||
}]
|
||||
}" >/dev/null 2>&1
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "✓ $env_name route added successfully"
|
||||
else
|
||||
echo "✗ Failed to add $env_name route - add manually to Caddyfile"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Add TEST environment route
|
||||
add_caddy_route "test-appaibuiltest.jarjarbinks" "5100" "TEST"
|
||||
|
||||
# Add PROD environment route
|
||||
add_caddy_route "appaibuiltest.jarjarbinks" "5200" "PROD"
|
||||
|
||||
echo ""
|
||||
|
||||
echo "==================================="
|
||||
echo "Setup complete!"
|
||||
echo "==================================="
|
||||
echo "TEST service: appaibuiltest-test"
|
||||
echo "TEST folder: /opt/appaibuiltest-test/app"
|
||||
echo "TEST URL: http://test-appaibuiltest.jarjarbinks"
|
||||
echo "PROD service: appaibuiltest"
|
||||
echo "PROD folder: /opt/appaibuiltest/app"
|
||||
echo "PROD URL: http://appaibuiltest.jarjarbinks"
|
||||
echo "==================================="
|
||||
39
deployment-configs-appaibuiltest/secrets-checklist.md
Normal file
39
deployment-configs-appaibuiltest/secrets-checklist.md
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# Forgejo Secrets Checklist
|
||||
|
||||
Repository: **YOUR_REPO_NAME**
|
||||
|
||||
Go to: Forgejo → Repository → Settings → Actions → Secrets
|
||||
|
||||
## Required Secrets
|
||||
|
||||
| Secret Name | Value | Status |
|
||||
|-------------|-------|--------|
|
||||
| `DEPLOY_HOST` | `192.168.1.43` | ☐ |
|
||||
| `DEPLOY_USER` | `deploy` | ☐ |
|
||||
| `DEPLOY_SSH_KEY` | SSH private key (ED25519) | ☐ |
|
||||
|
||||
## Verify Secrets
|
||||
|
||||
These secrets should already exist from previous deployments. Verify they are configured:
|
||||
|
||||
```bash
|
||||
# Test SSH connection
|
||||
ssh deploy@192.168.1.43 "echo Connection successful"
|
||||
```
|
||||
|
||||
## If Secrets Missing
|
||||
|
||||
Generate SSH key pair:
|
||||
```bash
|
||||
ssh-keygen -t ed25519 -C "deploy@forgejo-ci"
|
||||
```
|
||||
|
||||
Add public key to server:
|
||||
```bash
|
||||
ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@192.168.1.43
|
||||
```
|
||||
|
||||
Add private key to Forgejo secrets:
|
||||
```bash
|
||||
cat ~/.ssh/id_ed25519
|
||||
# Copy output and paste in Forgejo secret
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
[Unit]
|
||||
Description=AppAIBuildTest TEST Environment
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
WorkingDirectory=/opt/appaibuiltest-test/app
|
||||
ExecStart=/opt/appaibuiltest-test/app/AppAIBuildTest
|
||||
Environment=ASPNETCORE_URLS=http://127.0.0.1:5100
|
||||
Environment=ASPNETCORE_ENVIRONMENT=Staging
|
||||
User=dotnet-service
|
||||
Group=dotnet-service
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
SyslogIdentifier=appaibuiltest-test
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
[Unit]
|
||||
Description=AppAIBuildTest PRODUCTION Environment
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
WorkingDirectory=/opt/appaibuiltest/app
|
||||
ExecStart=/opt/appaibuiltest/app/AppAIBuildTest
|
||||
Environment=ASPNETCORE_URLS=http://127.0.0.1:5105
|
||||
Environment=ASPNETCORE_ENVIRONMENT=Production
|
||||
User=dotnet-service
|
||||
Group=dotnet-service
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
SyslogIdentifier=appaibuiltest
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Loading…
Add table
Add a link
Reference in a new issue