feat: add github docker pack

Signed-off-by: d0zingcat <iamtangli42@gmail.com>
This commit is contained in:
2026-01-12 15:08:31 +08:00
parent a2f9488b14
commit c0f383f281
7 changed files with 136 additions and 4 deletions

49
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,49 @@
name: Build and Push Docker Images
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Server image
uses: docker/build-push-action@v5
with:
context: .
file: apps/server/Dockerfile
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-server:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-server:${{ github.sha }}
- name: Build and push Web image
uses: docker/build-push-action@v5
with:
context: .
file: apps/web/Dockerfile
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-web:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-web:${{ github.sha }}

View File

@@ -67,6 +67,29 @@ cd apps/server && bun run db:push
bun run dev
```
### 3. Docker 部署
项目支持使用 Docker Compose 快速部署:
```bash
# 复制并填写环境变量
cp apps/server/.env.example .env
# 启动所有服务 (Postgres + Server + Web)
docker-compose up -d
```
---
## 🏗️ CI/CD
项目通过 GitHub Actions 实现了自动化流水线:
- **自动化构建**: 每次推送至 `main` 分支或提交 Pull Request 时,会自动触发 Docker 镜像构建。
- **镜像仓库**: 构建生成的镜像会同步推送到 GitHub Container Registry (GHCR)。
- **镜像路径**:
- `ghcr.io/${USER}/alert-message-center-server`
- `ghcr.io/${USER}/alert-message-center-web`
---
## 📡 Webhook 使用指南

15
apps/server/Dockerfile Normal file
View File

@@ -0,0 +1,15 @@
FROM oven/bun:1-alpine
WORKDIR /app
# Copy the entire project for monorepo context
COPY . .
# Install dependencies
RUN bun install --frozen-lockfile
WORKDIR /app/apps/server
EXPOSE 3000
CMD ["bun", "run", "start"]

21
apps/web/Dockerfile Normal file
View File

@@ -0,0 +1,21 @@
# Build stage
FROM oven/bun:1-alpine AS builder
WORKDIR /app
# Copy the entire project
COPY . .
# Install dependencies
RUN bun install --frozen-lockfile
# Build the web app
WORKDIR /app/apps/web
RUN bun run build
# Serve stage
FROM nginx:alpine
COPY --from=builder /app/apps/web/dist /usr/share/nginx/html
# Add a custom nginx config if needed to handle SPA routing, but for now default is okay
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View File

@@ -1,4 +1,27 @@
services:
server:
build:
context: .
dockerfile: apps/server/Dockerfile
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgres://postgres:password@postgres:5432/alert_message_center
- FEISHU_APP_ID=${FEISHU_APP_ID}
- FEISHU_APP_SECRET=${FEISHU_APP_SECRET}
# ... other envs
depends_on:
- postgres
web:
build:
context: .
dockerfile: apps/web/Dockerfile
ports:
- "80:80"
depends_on:
- server
postgres:
image: postgres:17-alpine
restart: always

View File

@@ -125,7 +125,7 @@ The database schema is defined in `apps/server/src/db/schema.ts`.
- [ ] **Message Preview**: Preview Feishu card JSON in the UI.
- [ ] **History/Logs**: Keep a log of sent alerts for auditing.
- [ ] **Retry Mechanism**: Handle Feishu API failures.
- [ ] **Deployment**: Dockerfile and deployment scripts.
- [x] **Deployment**: Dockerfile and deployment scripts.
## 7. Development Conventions
@@ -135,7 +135,8 @@ The database schema is defined in `apps/server/src/db/schema.ts`.
- **Type Safety**: strict TypeScript usage. Backend and Frontend share types via Hono RPC or shared interfaces.
- **Environment Variables**:
- `FEISHU_APP_ID`, `FEISHU_APP_SECRET`, `REDIRECT_URI`, `ADMIN_EMAILS`.
- **Administrators**:
- Configured via the `ADMIN_EMAILS` environment variable (comma-separated list of emails).
- **CI/CD**:
- GitHub Actions automates the build and push of Docker images to GitHub Container Registry (GHCR).
- Images are built for both `apps/server` (Bun) and `apps/web` (Nginx).

View File

@@ -21,5 +21,5 @@
- [x] **Admin Topic Management**: Approve, reject, and delete topics (with audit trail).
- [x] **Personal Inbox**: Direct alert delivery bypassing topics.
- [ ] **Retry Mechanism**: Handle Feishu API failures.
- [ ] **Deployment**: Dockerfile and deployment scripts.
- [x] **Deployment**: Dockerfile and CI/CD (GitHub Actions + GHCR).