Files
photography/.gitea/workflows/deploy-frontend.yml
xujiang 00c97a3667 feat: 添加 Caddy 配置文件和部署文档
- 创建 Caddyfile 配置 photography.iriver.top 域名
- 配置静态文件服务指向 ~/www/photography/
- 添加性能优化:gzip 压缩、缓存控制
- 配置安全头和错误处理
- 添加详细的 Caddy 部署和配置文档

功能特性:
-  自动 HTTPS (Let's Encrypt)
-  静态资源缓存优化
-  Gzip 压缩
-  安全头配置
-  404 错误页面处理
-  访问日志记录

使用方法:
1. 复制 Caddyfile 到服务器 /etc/caddy/
2. 运行 sudo systemctl reload caddy
3. 访问 https://photography.iriver.top
2025-07-09 09:57:55 +08:00

78 lines
2.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Deploy Frontend
on:
push:
branches: [ main ]
paths: [ 'frontend/**' ]
pull_request:
branches: [ main ]
paths: [ 'frontend/**' ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: |
cd frontend
bun install
- name: Run type check
run: |
cd frontend
bun run type-check
- name: Run lint
run: |
cd frontend
bun run lint
- name: Build project
run: |
cd frontend
bun run build
- name: Deploy to VPS
run: |
# 安装 SSH 客户端、rsync 和 sshpass
sudo apt-get update && sudo apt-get install -y openssh-client rsync sshpass
# 设置 SSH 选项以禁用主机密钥检查(用于密码认证)
export SSHPASS=${{ secrets.ALIYUN_PWD }}
# 测试 SSH 连接
sshpass -e ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 ${{ secrets.ALIYUN_USER_NAME }}@${{ secrets.ALIYUN_IP }} "echo 'SSH 连接成功'"
# 在服务器上创建用户目录下的部署目录
sshpass -e ssh -o StrictHostKeyChecking=no ${{ secrets.ALIYUN_USER_NAME }}@${{ secrets.ALIYUN_IP }} "mkdir -p ~/www/photography"
# 上传构建文件到服务器用户目录(使用密码认证)
sshpass -e rsync -avz --delete --progress -e "ssh -o StrictHostKeyChecking=no" frontend/out/ ${{ secrets.ALIYUN_USER_NAME }}@${{ secrets.ALIYUN_IP }}:~/www/photography/
# 设置文件权限(用户目录无需 sudo
sshpass -e ssh -o StrictHostKeyChecking=no ${{ secrets.ALIYUN_USER_NAME }}@${{ secrets.ALIYUN_IP }} "chmod -R 755 ~/www/photography"
# 显示部署信息Caddy 配置需要手动配置指向新路径)
sshpass -e ssh -o StrictHostKeyChecking=no ${{ secrets.ALIYUN_USER_NAME }}@${{ secrets.ALIYUN_IP }} "echo '提示:请确保 Web 服务器配置指向 ~/www/photography/ 目录'"
echo "✅ 部署完成!"
echo "📁 部署路径:~/www/photography/"
echo "🌐 访问地址https://photography.iriver.top"
- name: Notify success
if: success()
run: |
echo "✅ 前端项目部署成功!"
- name: Notify failure
if: failure()
run: |
echo "❌ 前端项目部署失败!"