diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..9f8d6a0 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,56 @@ +name: Publish Docker image + +on: + workflow_dispatch: + release: + types: [published] + repository_dispatch: + types: [trigger-docker-image] + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Set timezone to Shanghai + run: sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" | sudo tee /etc/timezone + + - name: Generate tag with Chinese date format + id: date + run: echo "::set-output name=date::$(date +'%y%m%d')" + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: buqian/99ai + tags: | + type=raw,value=latest + type=raw,value=${{ steps.date.outputs.date }} + type=ref,event=tag + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 0000000..18c37dc --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,43 @@ +name: Upstream Sync + +permissions: + contents: write + +on: + schedule: + - cron: '0 */3 * * *' # 每3小时执行一次 + workflow_dispatch: + +jobs: + sync_latest_from_upstream: + name: Sync latest commits from upstream repo + runs-on: ubuntu-latest + if: ${{ github.event.repository.fork }} + + steps: + - name: Checkout target repo + uses: actions/checkout@v3 + + - name: Sync upstream changes + id: sync + uses: aormsby/Fork-Sync-With-Upstream-action@v3.4 + with: + upstream_sync_repo: vastxie/99AI + upstream_sync_branch: main + target_sync_branch: main + target_repo_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Sync check + if: failure() + run: | + echo "Sync failed." + exit 1 + + - name: Trigger docker-image workflow + if: steps.sync.outputs.changes_detected == 'true' + run: | + curl -X POST \ + -H "Authorization: token ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/KenGrofork/NineAIQuickDeploy/dispatches \ + -d '{"event_type": "trigger-docker-image"}' diff --git a/.gitignore b/.gitignore index d1c9642..68361c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules pnpm-lock.yaml sql -data \ No newline at end of file +data +.idea diff --git a/Dockerfile b/Dockerfile index 055b2ac..5651e37 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ # 编译阶段 -FROM node:18-alpine AS build - +FROM node:18-alpine AS base +FROM base AS build WORKDIR /app -COPY . . +COPY package.json ./ # 使用腾讯源(国内服务器可取消下方注释以提升安装速度) # RUN npm config set registry https://mirrors.cloud.tencent.com/npm/ @@ -13,16 +13,21 @@ COPY . . # 如遇到提示网站证书无效,取消下方注释,禁止严格SS策略 # RUN npm config set strict-ssl false -# 使用 pnpm 安装项目依赖 -RUN npm install -g pnpm -RUN pnpm install +# 安装项目依赖 +RUN apk add --no-cache --virtual .build-deps git && \ + npm install --omit=dev && \ + apk del .build-deps + # 运行阶段 -FROM node:18-alpine +FROM base AS runner ENV TZ="Asia/Shanghai" WORKDIR /app -COPY --from=build /app . + +COPY --from=build /app/node_modules ./node_modules +COPY . . + EXPOSE 9520 CMD ["node", "./dist/main.js"]