From d4a52a6b2456fd902e321e1e39e3563ecd710a71 Mon Sep 17 00:00:00 2001 From: imsyy Date: Thu, 6 Jun 2024 16:27:01 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D=20Dock?= =?UTF-8?q?er=20=E8=BF=90=E8=A1=8C=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker.yml | 29 +++++++++++++++++++++++++++-- Dockerfile | 14 ++++++++++---- package.json | 4 ++-- src/index.ts | 4 ++-- src/routes/v2ex.ts | 2 +- src/routes/weatheralarm.ts | 2 -- 6 files changed, 42 insertions(+), 13 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 28511b2..094399f 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -5,9 +5,12 @@ on: types: [published] jobs: - push_to_registry: + build-docker: name: Push Docker image to multiple registries runs-on: ubuntu-latest + strategy: + matrix: + platform: [linux/amd64, linux/arm/v7, linux/arm64] permissions: packages: write contents: read @@ -15,6 +18,20 @@ jobs: - name: Check out the repo uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Cache Docker layers + uses: actions/cache@v4 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Log in to Docker Hub uses: docker/login-action@v3 with: @@ -36,7 +53,7 @@ jobs: imsyy/dailyhot-api ghcr.io/${{ github.repository }} - - name: Build and push Docker image + - name: Build and push uses: docker/build-push-action@v5 with: context: . @@ -44,3 +61,11 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + platforms: ${{ matrix.platform }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/Dockerfile b/Dockerfile index 4472f48..71300e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,14 @@ FROM node:20-alpine AS base +# 安装 Puppeteer 所需的依赖库 +RUN apk add --no-cache chromium nss freetype harfbuzz ca-certificates libc6-compat + +# 配置 Chromium +ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true +ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser + FROM base AS builder -RUN apk add --no-cache libc6-compat RUN npm install -g pnpm WORKDIR /app @@ -10,9 +16,9 @@ COPY package*json tsconfig.json pnpm-lock.yaml .env ./ COPY src ./src COPY public ./public -RUN pnpm install && \ - pnpm build && \ - pnpm prune --production +RUN pnpm install +RUN pnpm build +RUN pnpm prune --production FROM base AS runner WORKDIR /app diff --git a/package.json b/package.json index 8b692c0..764f576 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dailyhot-api", - "version": "2.0.0-rc.4", + "version": "2.0.0-rc.5", "description": "An Api on Today's Hot list", "keywords": [ "API", @@ -17,7 +17,7 @@ "license": "MIT", "author": "imsyy", "main": "dist/index.js", - "types": "dist/types.js", + "types": "src/types.d.ts", "declaration": true, "declarationMap": true, "sourceMap": true, diff --git a/src/index.ts b/src/index.ts index 62e2d8b..e58a9e9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,8 +10,8 @@ const serveHotApi = (port: number = config.PORT) => { fetch: app.fetch, port, }); - logger.info(`🔥 DailyHot API 成功在端口 ${config.PORT} 上运行`); - logger.info(`🔗 Local: 👉 http://localhost:${config.PORT}`); + logger.info(`🔥 DailyHot API 成功在端口 ${port} 上运行`); + logger.info(`🔗 Local: 👉 http://localhost:${port}`); return apiServer; } catch (error) { logger.error(error); diff --git a/src/routes/v2ex.ts b/src/routes/v2ex.ts index 1ede996..e8a66d4 100644 --- a/src/routes/v2ex.ts +++ b/src/routes/v2ex.ts @@ -31,7 +31,7 @@ const getList = async (options: Options, noCache: boolean) => { const { type } = options; const url = `https://www.v2ex.com/api/topics/${type}.json`; const result = await get({ url, noCache }); - const list = result.data.data.list; + const list = result.data; return { fromCache: result.fromCache, updateTime: result.updateTime, diff --git a/src/routes/weatheralarm.ts b/src/routes/weatheralarm.ts index 3fce061..0bf43f3 100644 --- a/src/routes/weatheralarm.ts +++ b/src/routes/weatheralarm.ts @@ -30,8 +30,6 @@ const getList = async (options: Options, noCache: boolean) => { const url = `http://www.nmc.cn/rest/findAlarm?pageNo=1&pageSize=20&signaltype=&signallevel=&province=${encodeURIComponent(province)}`; const result = await get({ url, noCache }); const list = result.data.data.page.list; - console.log(list); - return { fromCache: result.fromCache, updateTime: result.updateTime,