From 49a72b7198e7fd21085fb5c8ae16c101a1960468 Mon Sep 17 00:00:00 2001 From: KenGrofork Date: Mon, 22 Apr 2024 13:55:54 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=95=9C=E5=83=8F?= =?UTF-8?q?=E4=BD=93=E7=A7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 缩小体积 --- .gitignore | 3 ++- Dockerfile | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) 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"] From cedcbbbb27219f7b654062354bb1282a8956f542 Mon Sep 17 00:00:00 2001 From: KenGrofork Date: Mon, 22 Apr 2024 13:56:41 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image.yml | 56 ++++++++++++++++++++++++++++++ .github/workflows/sync.yml | 43 +++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 .github/workflows/docker-image.yml create mode 100644 .github/workflows/sync.yml 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"}' From de4d6bd5cf270a7a158cc3836cc7e17f09e14228 Mon Sep 17 00:00:00 2001 From: KenGrofork Date: Mon, 22 Apr 2024 14:00:03 +0800 Subject: [PATCH 3/4] =?UTF-8?q?Revert=20"=E6=96=B0=E5=A2=9E=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8C=96=E6=B5=81=E7=A8=8B"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit cedcbbbb27219f7b654062354bb1282a8956f542. --- .github/workflows/docker-image.yml | 56 ------------------------------ .github/workflows/sync.yml | 43 ----------------------- 2 files changed, 99 deletions(-) delete mode 100644 .github/workflows/docker-image.yml delete mode 100644 .github/workflows/sync.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index 9f8d6a0..0000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,56 +0,0 @@ -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 deleted file mode 100644 index 18c37dc..0000000 --- a/.github/workflows/sync.yml +++ /dev/null @@ -1,43 +0,0 @@ -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"}' From 1ffedc9a87cd0e69fe4ba3ddbe8cfec779060e13 Mon Sep 17 00:00:00 2001 From: KenGrofork Date: Mon, 22 Apr 2024 14:17:25 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8C=96=E6=B5=81?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image.yml | 56 ++++++++++++++++++++++++++++++ .github/workflows/sync.yml | 43 +++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 .github/workflows/docker-image.yml create mode 100644 .github/workflows/sync.yml 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"}'