From 33ae95a9e31ff94822904aa2ae94237b819124d8 Mon Sep 17 00:00:00 2001 From: tbxark Date: Tue, 27 Aug 2024 11:22:47 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E8=B0=83=E6=95=B4=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E9=93=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 18 ------------------ Dockerfile | 6 ++++-- doc/en/LOCAL.md | 2 +- docker-compose.yaml | 4 +--- package.json | 2 +- src/{entry => adapter}/local.ts | 0 vite.config.ts | 6 +++--- 7 files changed, 10 insertions(+), 28 deletions(-) delete mode 100644 .dockerignore rename src/{entry => adapter}/local.ts (100%) diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 5a5ea1b5..00000000 --- a/.dockerignore +++ /dev/null @@ -1,18 +0,0 @@ -.wrangler -adapter -dist -doc -node_modules -plugins -.gitattributes -.gitignore -config.json -docker-compose.yaml -Dockerfile -eslint.config.js -LICENSE -README.md -README_CN.md -wrangler.toml -wrangler-example.toml -yarn.lock \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0c74bf33..684e28e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20 as DEV +FROM node:alpine as DEV WORKDIR /app COPY package.json vite.config.ts tsconfig.json ./ @@ -6,10 +6,12 @@ COPY src ./src CMD ["/bin/bash"] RUN npm install && npm run build:local -FROM node:20 as PROD +FROM node:alpine as PROD WORKDIR /app COPY --from=DEV /app/dist /app/dist COPY --from=DEV /app/package.json /app/ RUN npm install --only=production --omit=dev +RUN apk add --no-cache sqlite +EXPOSE 8787 CMD ["npm", "run", "start:dist"] diff --git a/doc/en/LOCAL.md b/doc/en/LOCAL.md index 7c7d24f8..610f79fe 100644 --- a/doc/en/LOCAL.md +++ b/doc/en/LOCAL.md @@ -52,7 +52,7 @@ docker build -t chatgpt-telegram-bot:latest . ### 2. Run container ```bash -docker run -v $(pwd)/config.json:/app/config.json $(pwd)/config.toml:/app/config.toml -p 8787:8787 chatgpt-telegram-bot:latest --name chatgpt-telegram-bot +docker run -d -p 8787:8787 -v $(pwd)/config.json:/app/config.json:ro -v $(pwd)/wrangler.toml:/app/config.toml:ro chatgpt-telegram-worker:latest ``` diff --git a/docker-compose.yaml b/docker-compose.yaml index 276e7244..cc1b86bd 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,9 +1,7 @@ -version: '3.8' -name: chatgpt-telegram-bot +name: chatgpt-telegram-worker services: chatgpt-telegram-worker: build: . - container_name: chatgpt-telegram-worker ports: - "8787:8787" volumes: diff --git a/package.json b/package.json index 1cfa33ac..46f2b0f5 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "deploy:dist": "wrangler deploy", "deploy:build": "npm run build && wrangler deploy", "start:dist": "node dist/index.js", - "start:local": "CONFIG_PATH=./config.json TOML_PATH=./wrangler.toml tsx index.ts", + "start:local": "CONFIG_PATH=./config.json TOML_PATH=./wrangler.toml tsx src/adapter/local.ts", "start:debug": "wrangler dev --local" }, "dependencies": { diff --git a/src/entry/local.ts b/src/adapter/local.ts similarity index 100% rename from src/entry/local.ts rename to src/adapter/local.ts diff --git a/vite.config.ts b/vite.config.ts index 36ec8cfa..4e4d0338 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -7,9 +7,9 @@ import { nodeResolve } from '@rollup/plugin-node-resolve'; import cleanup from 'rollup-plugin-cleanup'; import checker from 'vite-plugin-checker'; import dts from 'vite-plugin-dts'; +// eslint-disable-next-line ts/ban-ts-comment // @ts-ignore -import nodeExternals from 'rollup-plugin-node-externals' - +import nodeExternals from 'rollup-plugin-node-externals'; const { BUILD_MODE } = process.env; @@ -30,7 +30,7 @@ const plugins: Plugin[] = [ nodeExternals(), ]; const define: Record = {}; -const entry = path.resolve(__dirname, BUILD_MODE === 'local' ? 'src/entry/local.ts' : 'src/index.ts'); +const entry = path.resolve(__dirname, BUILD_MODE === 'local' ? 'src/adapter/local.ts' : 'src/index.ts'); if (BUILD_MODE !== 'local') { const TIMESTAMP_FILE = './dist/timestamp';