Skip to content

Commit

Permalink
🐞 fix: 修复 Docker 运行出错
Browse files Browse the repository at this point in the history
  • Loading branch information
imsyy committed Jun 6, 2024
1 parent d73ca11 commit d4a52a6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 13 deletions.
29 changes: 27 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,33 @@ 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
steps:
- 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:
Expand All @@ -36,11 +53,19 @@ 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: .
file: ./Dockerfile
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
14 changes: 10 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
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

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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/v2ex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/routes/weatheralarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d4a52a6

Please sign in to comment.