-
Notifications
You must be signed in to change notification settings - Fork 32
feat: add docker deploy support #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Git | ||
| .git | ||
| .gitignore | ||
| .gitattributes | ||
|
|
||
| # Build outputs | ||
| dist | ||
| build | ||
| .next | ||
| node_modules | ||
| out | ||
|
|
||
| # Development | ||
| .env.local | ||
| .env.*.local | ||
| .vscode | ||
| .idea | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # Testing | ||
| coverage | ||
| .nyc_output | ||
|
|
||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.log* | ||
| pnpm-debug.log* | ||
|
|
||
| # OS | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # CI/CD | ||
| .github | ||
| .gitlab-ci.yml | ||
|
|
||
| # Documentation | ||
| README.md | ||
| CHANGELOG.md | ||
| CLAUDE.md | ||
| .serena | ||
| docs |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| name: Build and Push Docker Images | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - 'v*' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| # 检查是否修改了drizzle的数据库配置, 修改了才需要更新migrate镜像 | ||
| detect-migrate-changes: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| should_build_migrate: ${{ steps.filter.outputs.migrate }} | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Detect migration-related changes | ||
| id: filter | ||
| uses: dorny/paths-filter@v3 | ||
| with: | ||
| filters: | | ||
| migrate: | ||
| - 'drizzle/**' | ||
| - 'scripts/migrate.mjs' | ||
| - 'Dockerfile.migrate' | ||
|
|
||
| build-app: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Log in to GitHub Container Registry | ||
| uses: docker/login-action@v4 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Get lowercase repository owner | ||
| id: lowercase | ||
| run: echo "owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Build and Push App Image | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| platforms: linux/amd64 | ||
| push: true | ||
| tags: | | ||
| ghcr.io/${{ steps.lowercase.outputs.owner }}/cliproxyapi-monitor:latest | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=min | ||
|
|
||
| build-migrate: | ||
| runs-on: ubuntu-latest | ||
| needs: detect-migrate-changes | ||
| if: github.event_name == 'workflow_dispatch' || needs.detect-migrate-changes.outputs.should_build_migrate == 'true' | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Log in to GitHub Container Registry | ||
| uses: docker/login-action@v4 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Get lowercase repository owner | ||
| id: lowercase | ||
| run: echo "owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Build and Push Migration Image | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile.migrate | ||
| platforms: linux/amd64 | ||
| push: true | ||
| tags: | | ||
| ghcr.io/${{ steps.lowercase.outputs.owner }}/cliproxyapi-monitor-migrate:latest | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=min | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,3 +12,5 @@ yarn-error.log* | |
| pnpm-debug.log* | ||
| bun.lockb | ||
| .drizzle | ||
| .serena | ||
| CLAUDE.md | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| FROM node:24-alpine AS base | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. node:24-alpine |
||
|
|
||
| WORKDIR /app | ||
|
|
||
| ENV PNPM_HOME="/pnpm" | ||
| ENV PATH="$PNPM_HOME:$PATH" | ||
| ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
|
||
| RUN corepack enable && corepack prepare pnpm@9 --activate | ||
|
|
||
| FROM base AS deps | ||
|
|
||
| COPY package.json pnpm-lock.yaml ./ | ||
| RUN pnpm install --frozen-lockfile | ||
|
|
||
| FROM base AS builder | ||
|
|
||
| COPY --from=deps /app/node_modules ./node_modules | ||
| COPY . . | ||
| RUN pnpm run build-only | ||
|
|
||
| FROM node:24-alpine AS runner | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| ENV NODE_ENV=production | ||
| ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
|
||
| RUN addgroup -S nodejs && adduser -S nextjs -G nodejs | ||
|
|
||
| COPY --from=builder /app/.next/standalone ./ | ||
| COPY --from=builder /app/.next/static ./.next/static | ||
|
|
||
| USER nextjs | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| CMD ["node", "server.js"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| FROM node:24-alpine | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| WORKDIR /app | ||
|
|
||
| ENV NODE_ENV=production | ||
|
|
||
| ARG DRIZZLE_ORM_VERSION=0.45.1 | ||
| ARG PG_VERSION=8.19.0 | ||
| ARG NEON_VERSION=1.0.2 | ||
| ARG WS_VERSION=8.19.0 | ||
|
|
||
| COPY scripts ./scripts | ||
| COPY drizzle ./drizzle | ||
|
|
||
| # Keep migration image dependencies minimal and separate from app image. | ||
| RUN npm install --omit=dev --no-package-lock \ | ||
| drizzle-orm@${DRIZZLE_ORM_VERSION} \ | ||
| pg@${PG_VERSION} \ | ||
| @neondatabase/serverless@${NEON_VERSION} \ | ||
| ws@${WS_VERSION} | ||
|
Comment on lines
+7
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 您好,在 为了在保持镜像体积小的同时提高可维护性,可以考虑创建一个专门用于迁移的
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个确实 |
||
|
|
||
| CMD ["node", "scripts/migrate.mjs"] | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||||||||||||||||||||||
| version: '3.8' | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| services: | ||||||||||||||||||||||||||
| migrate-DB: | ||||||||||||||||||||||||||
| image: ghcr.io/sxjeru/cliproxyapi-monitor-migrate:latest | ||||||||||||||||||||||||||
| container_name: cliproxyapi-monitor-migrate | ||||||||||||||||||||||||||
| environment: | ||||||||||||||||||||||||||
| DATABASE_URL: ${DATABASE_URL} | ||||||||||||||||||||||||||
| DATABASE_DRIVER: ${DATABASE_DRIVER:-pg} | ||||||||||||||||||||||||||
| # 针对neon/Supabase | ||||||||||||||||||||||||||
| POSTGRES_URL: # 池化连接(适合短连接、高并发函数) | ||||||||||||||||||||||||||
| POSTGRES_URL_NON_POOLING: # 直连连接(更适合迁移、长事务、某些管理操作) | ||||||||||||||||||||||||||
|
Comment on lines
+10
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): 直接给 以这种写法,Compose 会将
Suggested change
Original comment in Englishsuggestion (bug_risk): Bare In this form, Compose sets
Suggested change
|
||||||||||||||||||||||||||
| restart: "no" | ||||||||||||||||||||||||||
| profiles: | ||||||||||||||||||||||||||
| - migration | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| app: | ||||||||||||||||||||||||||
| image: ghcr.io/sxjeru/cliproxyapi-monitor:latest | ||||||||||||||||||||||||||
| container_name: cliproxyapi-monitor | ||||||||||||||||||||||||||
| ports: | ||||||||||||||||||||||||||
| - "3000:3000" | ||||||||||||||||||||||||||
| environment: | ||||||||||||||||||||||||||
| NODE_ENV: production | ||||||||||||||||||||||||||
| CLIPROXY_SECRET_KEY: ${CLIPROXY_SECRET_KEY} | ||||||||||||||||||||||||||
| CLIPROXY_API_BASE_URL: ${CLIPROXY_API_BASE_URL} | ||||||||||||||||||||||||||
| DATABASE_URL: ${DATABASE_URL} | ||||||||||||||||||||||||||
| DATABASE_DRIVER: ${DATABASE_DRIVER:-pg} | ||||||||||||||||||||||||||
| PASSWORD: ${PASSWORD} | ||||||||||||||||||||||||||
| # 以下是非必要的参数, 详见readme | ||||||||||||||||||||||||||
| DATABASE_CA: ${DATABASE_CA} | ||||||||||||||||||||||||||
| CRON_SECRET: ${CRON_SECRET} | ||||||||||||||||||||||||||
| TIMEZONE: ${TIMEZONE:-Asia/Shanghai} | ||||||||||||||||||||||||||
| DATABASE_POOL_MAX: ${DATABASE_POOL_MAX:-5} | ||||||||||||||||||||||||||
| DATABASE_POOL_IDLE_TIMEOUT_MS: ${DATABASE_POOL_IDLE_TIMEOUT_MS:-10000} | ||||||||||||||||||||||||||
| DATABASE_POOL_CONNECTION_TIMEOUT_MS: ${DATABASE_POOL_CONNECTION_TIMEOUT_MS:-5000} | ||||||||||||||||||||||||||
| DATABASE_POOL_MAX_USES: ${DATABASE_POOL_MAX_USES:-7500} | ||||||||||||||||||||||||||
| AUTH_FILES_INSERT_CHUNK_SIZE: ${AUTH_FILES_INSERT_CHUNK_SIZE:-500} | ||||||||||||||||||||||||||
| USAGE_INSERT_CHUNK_SIZE: ${USAGE_INSERT_CHUNK_SIZE:-1000} | ||||||||||||||||||||||||||
| restart: unless-stopped | ||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| /// <reference types="next" /> | ||
| /// <reference types="next/image-types/global" /> | ||
| import "./.next/dev/types/routes.d.ts"; | ||
| import "./.next/types/routes.d.ts"; | ||
|
|
||
| // NOTE: This file should not be edited | ||
| // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. |
Uh oh!
There was an error while loading. Please reload this page.