Skip to content

Commit 875b713

Browse files
committed
Merge branch 'dev'
2 parents 9f62997 + 01e9af2 commit 875b713

File tree

104 files changed

+2463
-1819
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+2463
-1819
lines changed

.github/workflows/build-container.yml

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
branches:
55
- main
66
- dev
7+
- feature/**
78
paths:
89
- 'src/BE/**'
910
- 'src/FE/**'
@@ -51,6 +52,35 @@ jobs:
5152
name: chats-fe
5253
path: ./src/FE/out
5354

55+
upload-fe-to-minio:
56+
strategy:
57+
matrix:
58+
include:
59+
- asset: chats-fe
60+
needs: build-fe
61+
runs-on: ubuntu-latest
62+
steps:
63+
- name: Download build artifacts
64+
uses: actions/download-artifact@v4
65+
with:
66+
name: ${{ matrix.asset }}
67+
path: ${{ matrix.asset }}
68+
69+
- name: Compress artifacts into ZIP
70+
run: |
71+
zip -r ${{ matrix.asset }}.zip ${{ matrix.asset }}
72+
shell: bash
73+
74+
- name: Configure MINIO Credentials
75+
run: |
76+
echo "AWS_ACCESS_KEY_ID=${{ secrets.MINIO_KEY }}" >> $GITHUB_ENV
77+
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.MINIO_SECRET }}" >> $GITHUB_ENV
78+
echo "AWS_DEFAULT_REGION=us-east-1" >> $GITHUB_ENV
79+
80+
- name: Upload to Minio
81+
run: |
82+
aws --endpoint-url ${{ vars.MINIO_URL }} s3 cp ${{ matrix.asset }}.zip s3://chats/r${{ github.run_number }}/${{ matrix.asset }}.zip
83+
5484
build-primary-container:
5585
needs: build-fe
5686
runs-on: ubuntu-latest
@@ -201,13 +231,27 @@ jobs:
201231
- name: build binary
202232
run: |
203233
dotnet publish ./src/BE/Chats.BE.csproj -c Release -o ./Publish ${{ matrix.args }} /p:DeleteExistingFiles=True
204-
234+
205235
- name: Upload artifacts
206236
uses: actions/upload-artifact@v4
207237
with:
208238
name: ${{ matrix.id }}
209239
path: ./Publish
210240

241+
- name: Compress artifacts into ZIP
242+
run: |
243+
zip -r ${{ matrix.id }}.zip ./Publish
244+
245+
- name: Configure MINIO Credentials
246+
run: |
247+
echo "AWS_ACCESS_KEY_ID=${{ secrets.MINIO_KEY }}" >> $GITHUB_ENV
248+
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.MINIO_SECRET }}" >> $GITHUB_ENV
249+
echo "AWS_DEFAULT_REGION=us-east-1" >> $GITHUB_ENV
250+
251+
- name: Upload to Minio
252+
run: |
253+
aws --endpoint-url ${{ vars.MINIO_URL }} s3 cp ${{ matrix.id }}.zip s3://chats/r${{ github.run_number }}/${{ matrix.id }}.zip
254+
211255
create-release:
212256
if: github.ref == 'refs/heads/main'
213257
needs: [docker-manifest, build-binaries, upload-minio-latest]
@@ -333,47 +377,9 @@ jobs:
333377
with:
334378
name: ${{ matrix.asset }}
335379
336-
upload-minio:
337-
if: github.ref == 'refs/heads/main'
338-
strategy:
339-
matrix:
340-
include:
341-
- asset: chats
342-
- asset: chats-fe
343-
- asset: chats-win-x64
344-
- asset: chats-linux-x64
345-
- asset: chats-linux-arm64
346-
- asset: chats-linux-musl-x64
347-
- asset: chats-linux-musl-arm64
348-
- asset: chats-osx-arm64
349-
- asset: chats-osx-x64
350-
needs: build-binaries
351-
runs-on: ubuntu-latest
352-
steps:
353-
- name: Download build artifacts
354-
uses: actions/download-artifact@v4
355-
with:
356-
name: ${{ matrix.asset }}
357-
path: ${{ matrix.asset }}
358-
359-
- name: Compress artifacts into ZIP
360-
run: |
361-
zip -r ${{ matrix.asset }}.zip ${{ matrix.asset }}
362-
shell: bash
363-
364-
- name: Configure MINIO Credentials
365-
run: |
366-
echo "AWS_ACCESS_KEY_ID=${{ secrets.MINIO_KEY }}" >> $GITHUB_ENV
367-
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.MINIO_SECRET }}" >> $GITHUB_ENV
368-
echo "AWS_DEFAULT_REGION=us-east-1" >> $GITHUB_ENV
369-
370-
- name: Upload to Minio
371-
run: |
372-
aws --endpoint-url ${{ vars.MINIO_URL }} s3 cp ${{ matrix.asset }}.zip s3://chats/r${{ github.run_number }}/${{ matrix.asset }}.zip
373-
374380
upload-minio-latest:
375381
if: github.ref == 'refs/heads/main'
376-
needs: upload-minio
382+
needs: [build-binaries, upload-fe-to-minio]
377383
runs-on: ubuntu-latest
378384
steps:
379385
- name: Configure MINIO Credentials
@@ -387,20 +393,29 @@ jobs:
387393
aws --endpoint-url ${{ vars.MINIO_URL }} s3 rm s3://chats/latest --recursive
388394
aws --endpoint-url ${{ vars.MINIO_URL }} s3 cp s3://chats/r${{ github.run_number }} s3://chats/latest --recursive
389395
390-
deploy-dev-stg:
396+
deploy:
391397
runs-on: ubuntu-latest
392398
needs: build-primary-container
393399
steps:
394400
- uses: webfactory/ssh-agent@v0.9.0
395401
with:
396402
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
397403
398-
- name: deploy dev/stg
404+
- name: deploy dev/stg or feature
399405
run: |
400406
ssh -o StrictHostKeyChecking=no -p 22 ${{ secrets.SSH_TARGET }} << 'EOF'
401407
docker pull ${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_NAMESPACE }}/chats:r${{ github.run_number }}-linux-x64
402408
cd chats
403-
sed -i "s/^TAG=.*/TAG=r${{ github.run_number }}-linux-x64/" ~/chats/dev.env
404-
sed -i "s/^TAG=.*/TAG=r${{ github.run_number }}-linux-x64/" ~/chats/stg.env
405-
./dev.sh && ./stg.sh
406-
EOF
409+
410+
if [[ "${{ github.ref_name }}" == feature/* ]]; then
411+
echo "Deploying feature branch: ${{ github.ref_name }}"
412+
sed -i "s/^TAG=.*/TAG=r${{ github.run_number }}-linux-x64/" ~/chats/feature.env
413+
docker compose --env-file=./feature.env --project-name chats-feature up -d --remove-orphans
414+
else
415+
echo "Deploying non-feature branch: ${{ github.ref_name }}"
416+
sed -i "s/^TAG=.*/TAG=r${{ github.run_number }}-linux-x64/" ~/chats/dev.env
417+
sed -i "s/^TAG=.*/TAG=r${{ github.run_number }}-linux-x64/" ~/chats/stg.env
418+
docker compose --env-file=./dev.env --project-name chats-dev up -d --remove-orphans
419+
docker compose --env-file=./stg.env --project-name chats-stg up -d --remove-orphans
420+
fi
421+
EOF

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Sdcb Chats 是一个强大且灵活的大语言模型前端,支持多种功能
2121

2222
## 快速开始
2323

24+
### 开发文档
25+
26+
Chats使用`C#`/`TypeScript`开发,有关如何编译Chats,请查看 [开发文档链接](./doc/zh-CN/build.md)
27+
2428
### Docker 部署
2529

2630
对于大多数用户而言,Docker 提供了最简单快速的部署方式。以下是一步到位的部署命令:

README_EN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Sdcb Chats is a powerful and flexible frontend for large language models that su
1919

2020
## Quick Start
2121

22+
### Development Documentation
23+
24+
Chats is developed using `C#`/`TypeScript`. For information on how to compile Chats, please refer to the [development documentation link](./doc/en-US/build.md).
25+
2226
### Docker Deployment
2327

2428
For most users, Docker provides the simplest and fastest way to deploy. Here is an all-in-one deployment command:

doc/en-US/build.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# Chats Development Guide
2+
3+
Welcome to Chats! This guide will help you quickly get started with development and understand how to use and configure the Chats project during the development phase. In the development phase, Chats adopts a front-end and back-end separation model, but in production, they will be combined into a single deployment package.
4+
5+
## Technology Stack
6+
7+
- **Backend:** Developed using C#/ASP.NET Core.
8+
- **Frontend:** Developed using Next.js/React/TypeScript.
9+
- **CSS:** Utilizes Tailwind CSS.
10+
11+
## Environment Requirements
12+
13+
- Git
14+
- .NET SDK 8.0
15+
- Node.js >= 20
16+
- Visual Studio Code
17+
- Visual Studio 2022 (optional but recommended)
18+
19+
## Obtaining the Code
20+
21+
First, clone the Chats code repository:
22+
23+
```bash
24+
git clone https://github.com/sdcb/chats.git
25+
```
26+
27+
## Joint Frontend and Backend Development
28+
29+
### Backend Development Guide
30+
31+
1. Use Visual Studio to open the solution:
32+
33+
Locate the `chats/Chats.sln` solution file in the root directory and open it. In Visual Studio, you'll see a website project named `Chats.BE`.
34+
35+
2. Run the project:
36+
37+
- Press F5 to run the project. The default configuration will check if the SQLite database file `chats.db` exists, and if not, it will automatically create it in the `./AppData` directory and initialize the database.
38+
- The service will run on `http://localhost:5146`, providing API services. If running in development mode (`ASPNETCORE_ENVIRONMENT=Development`), Swagger UI will be available at `http://localhost:5146/swagger`.
39+
40+
3. Configuration file explanation:
41+
42+
The default configuration is located in `appsettings.json`, but it is strongly recommended to manage sensitive information using `userSecrets.json`. This can prevent accidental exposure of sensitive development configurations in the code base.
43+
44+
**Default configuration structure:**
45+
46+
```json
47+
{
48+
"Logging": {
49+
"LogLevel": {
50+
"Default": "Information",
51+
"Microsoft.AspNetCore": "Warning"
52+
}
53+
},
54+
"AllowedHosts": "*",
55+
"FE_URL": "http://localhost:3001",
56+
"ENCRYPTION_PASSWORD": "this is used for encrypt auto increment int id, please set as a random string.",
57+
"DBType": "sqlite",
58+
"ConnectionStrings": {
59+
"ChatsDB": "Data Source=./AppData/chats.db"
60+
}
61+
}
62+
```
63+
64+
**Configuration options explanation:**
65+
66+
- `Logging`: Manages log level; defaults to recording information level logs.
67+
- `AllowedHosts`: Configures allowed host names; `*` accepts all hosts.
68+
- `FE_URL`: Frontend URL, defaults to `http://localhost:3001`. The frontend can access the backend via CORS, with no extra configuration required for port 3000.
69+
- `DBType`: Database type, supporting `sqlite` (default), `mssql`, and `postgresql`.
70+
- `ConnectionStrings:ChatsDB`: Database `ADO.NET` connection string, varying based on `DBType`.
71+
- `ENCRYPTION_PASSWORD`: Used for encrypting auto-increment integer IDs. In a production environment, it should be set to a random string to avoid direct exposure of IDs.
72+
73+
**Why use integer + encryption instead of GUID?**
74+
75+
Initially, the Chats project used GUIDs, but due to the following two reasons and careful consideration, it was switched to auto-increment integer IDs:
76+
- GUID fields are larger, taking up more space;
77+
- GUIDs as clustered indexes can lead to index fragmentation, affecting performance;
78+
79+
80+
**Managing sensitive configurations:**
81+
82+
It's not recommended to directly modify configuration items in `appsettings.json`. Instead, use `userSecrets.json` via Visual Studio:
83+
84+
- Visual Studio: Right-click the `Chats.BE` project -> `Manage User Secrets`.
85+
- CLI: Manage user secrets with the following commands.
86+
87+
```bash
88+
dotnet user-secrets init
89+
dotnet user-secrets set "key" "value"
90+
dotnet user-secrets list
91+
```
92+
93+
This helps avoid accidentally uploading sensitive information when committing code.
94+
95+
4. Running without Visual Studio:
96+
97+
Navigate to the backend directory:
98+
99+
```bash
100+
cd ./chats/src/BE
101+
dotnet run
102+
```
103+
104+
### Frontend Development Guide
105+
106+
1. Navigate to the frontend directory:
107+
108+
```bash
109+
cd ./chats/src/FE
110+
```
111+
112+
2. Create a `.env.local` file and specify the backend URL:
113+
114+
```bash
115+
echo "API_URL=http://localhost:5146" > .env.local
116+
```
117+
118+
3. Install dependencies and run the development server:
119+
120+
```bash
121+
npm i
122+
npm run dev
123+
```
124+
125+
After running, the frontend service will listen on `http://localhost:3000`. The backend already supports CORS configuration with no extra setup needed.
126+
127+
## Frontend Only Development
128+
129+
For frontend-focused development scenarios, we provide a pre-deployed backend development environment:
130+
131+
1. Clone the repository:
132+
133+
```bash
134+
git clone https://github.com/sdcb/chats.git
135+
```
136+
137+
2. Enter the frontend directory and specify the remote backend:
138+
139+
```bash
140+
cd ./chats/src/FE
141+
echo "API_URL=https://chats-dev.starworks.cc:88" > .env.local
142+
```
143+
144+
This environment already allows cross-origin access behavior from http://localhost:3000.
145+
146+
3. Install dependencies and run:
147+
148+
```bash
149+
npm i
150+
npm run dev
151+
```
152+
153+
### Notes
154+
155+
To simulate a production build process, execute:
156+
157+
```bash
158+
npm run build
159+
```
160+
161+
This command will generate an `./out` folder in the current directory containing all necessary static files.
162+
163+
## Backend Only Development
164+
165+
For backend-focused development scenarios, you can use packaged frontend files:
166+
167+
1. Clone the repository and navigate to the backend directory:
168+
169+
```bash
170+
git clone https://github.com/sdcb/chats.git
171+
cd ./chats/src/BE
172+
```
173+
174+
2. Download and extract frontend static files into `wwwroot`:
175+
176+
**On Linux:**
177+
178+
```bash
179+
curl -O https://github.com/sdcb/chats/releases/latest/download/chats-fe.zip
180+
unzip chats-fe.zip
181+
cp -r chats-fe/* wwwroot/
182+
```
183+
184+
**On Windows:**
185+
186+
```powershell
187+
Invoke-WebRequest -Uri "https://github.com/sdcb/chats/releases/latest/download/chats-fe.zip" -OutFile "chats-fe.zip"
188+
Expand-Archive -Path "chats-fe.zip" -DestinationPath "."
189+
Copy-Item -Path ".\chats-fe\*" -Destination ".\wwwroot" -Recurse -Force
190+
```
191+
192+
### Note
193+
1. I have also uploaded the above https://github.com/sdcb/chats/releases/latest/download/chats-fe.zip to my personal Minio file server at: http://io.starworks.cc:88/chats/latest/chats-fe.zip
194+
195+
If downloading directly from GitHub is too slow, you can use this address instead.
196+
197+
2. The attached `chats-fe.zip` is automatically generated by GitHub Actions when code is merged into the `main` branch, not triggered for `dev` branch merges.
198+
199+
3. Run the backend:
200+
201+
```bash
202+
dotnet run
203+
```
204+
205+
Alternatively, open `Chats.sln` in Visual Studio and run the `Chats.BE` project.
206+
207+
Once running, visiting `http://localhost:5146/login` will directly take you to the Chats login page, realizing a deployment mode where front-end and back-end are not separated.
208+
209+
I hope this guide will assist you in successfully developing the Chats project. If you have any questions, please refer to the documentation in the source code or create an issue at https://github.com/sdcb/chats to receive support.

0 commit comments

Comments
 (0)