Skip to content

Commit

Permalink
chore: 修改docker编译配置
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Aug 26, 2024
1 parent 69ef288 commit 12e38ab
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 386 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
adapter/local/node_modules
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:20
WORKDIR /app
COPY adapter/local /app/adapter/local/
COPY src /app/src
WORKDIR /app/adapter/local
RUN npm install
EXPOSE 8787
CMD ["npm", "run", "run:local"]
7 changes: 7 additions & 0 deletions adapter/local/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dist
node_modules
cache.json
config.json
README.md
yarn.lock
.gitignore
8 changes: 0 additions & 8 deletions adapter/local/Dockerfile

This file was deleted.

20 changes: 12 additions & 8 deletions adapter/local/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Local or Docker

## Configure

### 1. server config

```json5
{
"database": {
Expand All @@ -9,37 +12,38 @@
},
"server": { // server configuration for webhook mode
"hostname": "0.0.0.0",
"port": 3000,
"port": 3000, // must 8787 when using docker
"baseURL": "https://example.com"
},
'proxy': 'http://127.0.0.1:7890', // proxy for telegram api
"mode": "webhook", // webhook, polling
}
```

## Run on local
### 2. toml config
the toml is compatible with the cloudflare workers config file

### 1. Build cjs
```shell
yarn run build
```

### 2. Run

```shell
node dist/index.cjs
```
You can run `index.cjs` anywhere without npm


## Run on docker

Go to the root directory of the project

### 1. Build image

```bash
yarn && yarn run docker
docker build -t chatgpt-telegram-bot:latest .
```

### 2. Run container

```bash
docker run -v $(pwd)/config.json:/app/config.json -p 8787:8787 chatgpt-telegram-bot:latest --name chatgpt-telegram-bot
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
```
2 changes: 1 addition & 1 deletion adapter/local/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'node:fs';
import * as fs from 'node:fs';
import {createCache, initEnv, startServerV2, defaultRequestBuilder} from 'cloudflare-worker-adapter';
import {ENV, createRouter, createTelegramBotAPI, handleUpdate} from '../../src';
import {TelegramBotAPI} from "../../src/telegram/api";
Expand Down
11 changes: 4 additions & 7 deletions adapter/local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
"license": "MIT",
"main": "index.ts",
"scripts": {
"start": "CONFIG_PATH=./config.json TOML_PATH=../../wrangler.toml tsx index.ts",
"build": "vite build",
"docker": "npm run build && docker build -t chatgpt-telegram-bot:latest ."
"run:dist": "node dist/index.js",
"run:local": "tsx index.ts",
"run:debug": "CONFIG_PATH=./config.json TOML_PATH=../../wrangler.toml tsx index.ts"
},
"dependencies": {
"cloudflare-worker-adapter": "^1.2.3"
},
"devDependencies": {
"esbuild": "^0.23.1",
"rollup-plugin-node-externals": "^7.1.3",
"tsx": "^4.18.0",
"vite": "^5.4.2"
"tsx": "^4.18.0"
}
}
31 changes: 0 additions & 31 deletions adapter/local/vite.config.ts

This file was deleted.

Loading

0 comments on commit 12e38ab

Please sign in to comment.