Skip to content

Commit

Permalink
feat: update dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Dec 24, 2023
1 parent c0f382b commit 29efd47
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 115 deletions.
31 changes: 31 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
app/node_modules
app/src-tauri
app/.idea
app/.vscode
app/dist
app/dev-dist
app/dist-ssr
app/target
app/tauri.conf.json
app/tauri.js

.vscode
.idea
config.yaml
config.dev.yaml

addition/generation/data/*
!addition/generation/data/.gitkeep

addition/article/data/*
!addition/article/data/.gitkeep
sdk
logs

chat
chat.exe

# for reverse engine
reverse
access.json
access/*.json
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
app/node_modules
.vscode
.idea
config.yaml
Expand Down
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# ref nodejs v18 and golang v1.20

FROM node:18-alpine as builder
FROM golang:1.20-alpine as builder-go

FROM alpine:3.15

# Install nginx
RUN apk add --no-cache nginx && \
mkdir -p /run/nginx \
mkdir -p /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf

# Install nodejs
COPY --from=builder /usr/local/bin/node /usr/local/bin/node
COPY --from=builder /usr/local/include/node /usr/local/include/node
COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=builder /usr/local/share/doc/node /usr/local/share/doc/node

# Install golang
COPY --from=builder-go /usr/local/go /usr/local/go
ENV GOOS=linux GOARCH=amd64

WORKDIR /

# Copy source code
COPY . .

# Build backend
RUN go build -o chatnio

# Build frontend
RUN cd /app && \
npm install -g pnpm && \
pnpm install && \
pnpm run build && \
rm -rf node_modules

# Copy frontend
RUN ls -la /app
COPY --from=0 /app/dist /usr/share/nginx/html

# Expose port
EXPOSE 80

# Start nginx
CMD ["nginx", "-g", "daemon off;"]

# Start backend
CMD ["chatnio"]
101 changes: 39 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,79 +93,56 @@


## 📦 部署 | Deploy
**当前安装需要额外安装 Deeptrain 统一账户管理,all in one功能正在开发中**
```shell
git clone https://github.com/Deeptrain-Community/chatnio.git
cd chatnio

go build -o chatnio
cd app
npm install
npm run build
```

1. 编译安装 (自定义性强)
```shell
git clone https://github.com/Deeptrain-Community/chatnio.git
cd chatnio # project directory
go build -o chatnio # build backend
nohup ./chatnio > output.log & # run backend

cd app # frontend directory (~/app)
npm install -g pnpm # install pnpm
pnpm install # install frontend dependencies
pnpm build # build frontend

# run frontend
# a common way is to use nginx/apache to serve the static files
```

## 🔨 配置 | Config
~/**config.yaml**
```yaml
debug: true
server:
port: 8094
mysql:
db: chatnio
host: localhost
password: chatnio123456
port: 3306
user: root
redis:
host: localhost
port: 6379
mysql:
host: "localhost"
port: 3306
user: root
password: ...
secret: SbitdyN5ZH39cNxSrG3kMNZ1GfiyyQ43
db: "chatnio"

secret: ... # jwt secret
auth:
access: ...
salt: ...
sign: ...

openai:
gpt3:
endpoint: https://api.openai.com
apikey: sk-...|sk-...

gpt4:
endpoint: https://api.openai.com
apikey: sk-...|sk-...

slack:
bot_id: ...
token: ...
channel: ...

claude:
apikey: ...
endpoint: ...

sparkdesk:
app_id: ...
api_secret: ...
api_key: ...
model: generalv2
endpoint: wss://spark-api.xf-yun.com/v2.1/chat

palm2:
endpoint: ...
apikey: ...

bing:
# learn more at https://github.com/Deeptrain-Community/chatnio-bing-service
endpoint: ...
secret: ...

zhipuai:
endpoint: https://open.bigmodel.cn
apikey: ...
use_deeptrain: false
server:
port: 8094
system:
general:
backend: ""
mail:
host: ""
port: 465
username: ""
password: ""
from: ""
search:
endpoint: https://duckduckgo-api.vercel.app
query: 5
```

## 📚 开发文档 | Docs
Expand Down
73 changes: 22 additions & 51 deletions config.example.yaml
Original file line number Diff line number Diff line change
@@ -1,59 +1,30 @@
debug: true
server:
port: 8094
mysql:
db: chatnio
host: localhost
password: chatnio123456
port: 3306
user: root

redis:
host: localhost
port: 6379

mysql:
host: "localhost"
port: 3306
user: root
password: ...

db: "chatnio"
secret: SbitdyN5ZH39cNxSrG3kMNZ1GfiyyQ43

secret: ... # jwt secret
auth:
access: ...
salt: ...
sign: ...
use_deeptrain: false

openai:
gpt3:
endpoint: https://api.openai.com
apikey: sk-...|sk-...

gpt4:
endpoint: https://api.openai.com
apikey: sk-...|sk-...

slack:
bot_id: ...
token: ...
channel: ...

claude:
apikey: ...
endpoint: ...

sparkdesk:
app_id: ...
api_secret: ...
api_key: ...
model: generalv2
endpoint: wss://spark-api.xf-yun.com/v2.1/chat

palm2:
endpoint: ...
apikey: ...

bing:
# learn more at https://github.com/Deeptrain-Community/chatnio-bing-service
endpoint: ...
secret: ...

zhipuai:
endpoint: https://open.bigmodel.cn
apikey: ...
server:
port: 8094
system:
general:
backend: ""
mail:
host: ""
port: 465
username: ""
password: ""
from: ""
search:
endpoint: https://duckduckgo-api.vercel.app
query: 5
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.20

require (
github.com/bincooo/claude-api v1.0.2
github.com/chai2010/webp v1.1.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gin-gonic/gin v1.9.1
github.com/go-redis/redis/v8 v8.11.5
Expand All @@ -29,7 +30,6 @@ require (
github.com/bytedance/sonic v1.10.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chai2010/webp v1.1.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/cloudwego/hertz/cmd/hz v0.7.0 // indirect
Expand Down
35 changes: 35 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
worker_processes 1;

events {
worker_connections 8192;
multi_accept on;
use epoll;
}

http {
server {
listen 80;

location /api/ {
proxy_pass http://127.0.0.1:8094/;
proxy_set_header Host 127.0.0.1:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Host $host:$server_port;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 30s;
proxy_read_timeout 86400s;
proxy_send_timeout 30s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
error_page 404 =200 /index.html;
}
}
}
1 change: 1 addition & 0 deletions utils/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package utils

0 comments on commit 29efd47

Please sign in to comment.