From c0f383f281778a58bc69dbc4d3477d0b39280866 Mon Sep 17 00:00:00 2001 From: d0zingcat Date: Mon, 12 Jan 2026 15:08:31 +0800 Subject: [PATCH] feat: add github docker pack Signed-off-by: d0zingcat --- .github/workflows/ci.yml | 49 ++++++++++++++++++++++++++++++++++++++++ README.md | 23 +++++++++++++++++++ apps/server/Dockerfile | 15 ++++++++++++ apps/web/Dockerfile | 21 +++++++++++++++++ docker-compose.yml | 23 +++++++++++++++++++ docs/copilot-context.md | 7 +++--- todo.md | 2 +- 7 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 apps/server/Dockerfile create mode 100644 apps/web/Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c9c3d29 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 }} diff --git a/README.md b/README.md index 100e977..3d8cd31 100644 --- a/README.md +++ b/README.md @@ -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 使用指南 diff --git a/apps/server/Dockerfile b/apps/server/Dockerfile new file mode 100644 index 0000000..fe00aa7 --- /dev/null +++ b/apps/server/Dockerfile @@ -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"] diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile new file mode 100644 index 0000000..301c8bf --- /dev/null +++ b/apps/web/Dockerfile @@ -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;"] diff --git a/docker-compose.yml b/docker-compose.yml index b24ad5b..0a2801a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/docs/copilot-context.md b/docs/copilot-context.md index acb91b8..345ffd6 100644 --- a/docs/copilot-context.md +++ b/docs/copilot-context.md @@ -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). diff --git a/todo.md b/todo.md index 9d6bbf5..353b022 100644 --- a/todo.md +++ b/todo.md @@ -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).