feat: add docker

This commit is contained in:
WJG 2024-02-28 14:41:26 +08:00
parent 120a8cce77
commit 0e56bdff35
No known key found for this signature in database
GPG Key ID: 258474EF8590014A
13 changed files with 189 additions and 14 deletions

38
.dockerignore Normal file
View File

@ -0,0 +1,38 @@
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/engine/reference/builder/#dockerignore-file
**/.classpath
**/.dockerignore
**/.env*
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.next
**/.cache
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
**/build
**/dist
LICENSE
README.md
**/.bot.json
**/.mi.json
**/.migpt.js*
**/*.db*

1
.gitignore vendored
View File

@ -5,4 +5,5 @@ dist
.env .env
.bot.json .bot.json
.mi.json .mi.json
.migpt.js
*.db* *.db*

55
.migpt.js.example Normal file
View File

@ -0,0 +1,55 @@
const botName = "豆包";
const botProfile = `
性别:女
年龄20岁
学校:位于一个风景如画的小城市,一所综合性大学的文学院学生。
性格特点:
- 温婉可亲,对待人和事总是保持着乐观和善良的态度。
- 内向而思维敏捷,喜欢独处时阅读和思考。
- 对待朋友非常真诚,虽然不善于表达,但总是用行动去关心和帮助别人。
外貌特征:
- 清秀脱俗,长发及腰,喜欢简单的束发。
- 眼睛大而有神,总是带着温和的微笑。
- 穿着简单大方,偏爱文艺范的衣服,如棉麻连衣裙,不追求名牌,却总能穿出自己的风格。
爱好:
- 阅读,尤其是古典文学和现代诗歌,她的书房里收藏了大量的书籍。
- 写作,喜欢在闲暇时写写诗或是短篇小说,有时也会在学校的文学社团里分享自己的作品。
- 摄影,喜欢用镜头记录生活中的美好瞬间,尤其是自然风光和人文景观。
特长:
- 写作能力突出,曾多次获得学校文学比赛的奖项。
- 擅长钢琴,从小学习,能够演奏多首经典曲目。
- 有一定的绘画基础,喜欢在空闲时画一些风景或是静物。
梦想:
- 希望能成为一名作家,将自己对生活的感悟和对美的追求通过文字传达给更多的人。
- 想要环游世界,用镜头和笔记录下世界各地的美丽和人文。
`;
const masterName = "王黎";
const masterProfile = `
性别:男
年龄18
爱好:跑步,骑行,读书,追剧,旅游,听歌
职业:程序员
其他:
- 喜欢的电视剧有《请回答1988》、《漫长的季节》、《爱的迫降》等
- 喜欢吃土豆丝、茄子、山药、米线
- 喜欢黑红配色,浅蓝色和粉色
- 有空喜欢去公园静观人来人往
`;
export default {
speaker: {
name: botName,
userId: process.env.MI_USER,
password: process.env.MI_PASS,
did: process.env.MI_DID,
},
bot: {
name: botName,
profile: botProfile,
},
master: {
name: masterName,
profile: masterProfile,
},
};

11
.vscode/launch.json vendored
View File

@ -10,10 +10,19 @@
"--no-warnings", "--no-warnings",
"--experimental-specifier-resolution=node", "--experimental-specifier-resolution=node",
"--loader", "--loader",
"./tests/esm-loader.js" "./scripts/esm-loader.js"
], ],
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"internalConsoleOptions": "openOnSessionStart" "internalConsoleOptions": "openOnSessionStart"
},
{
"name": "Runner",
"type": "node",
"request": "launch",
"args": ["${workspaceFolder}/scripts/runner.js"],
"cwd": "${workspaceRoot}",
"envFile": "${workspaceFolder}/.env",
"internalConsoleOptions": "openOnSessionStart"
} }
] ]
} }

64
Dockerfile Normal file
View File

@ -0,0 +1,64 @@
# syntax=docker/dockerfile:1
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/
ARG NODE_VERSION=18.18.2
################################################################################
# Use node image for base image for all stages.
FROM node:${NODE_VERSION}-alpine as base
# Set working directory for all build stages.
WORKDIR /usr/src/app
################################################################################
# Create a stage for installing production dependecies.
FROM base as deps
# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.yarn to speed up subsequent builds.
# Leverage bind mounts to package.json and yarn.lock to avoid having to copy them
# into this layer.
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=yarn.lock,target=yarn.lock \
--mount=type=cache,target=/root/.yarn \
yarn install --production --frozen-lockfile
################################################################################
# Create a stage for building the application.
FROM deps as build
# Download additional development dependencies before building, as some projects require
# "devDependencies" to be installed to build. If you don't need this, remove this step.
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=yarn.lock,target=yarn.lock \
--mount=type=cache,target=/root/.yarn \
yarn install --frozen-lockfile
# Copy the rest of the source files into the image.
COPY . .
################################################################################
# Create a new stage to run the application with minimal runtime dependencies
# where the necessary files are copied from the build stage.
FROM base as final
# Use production node environment by default.
ENV NODE_ENV production
# Run the application as a non-root user.
USER node
# Copy package.json so that package manager commands can be used.
COPY package.json .
# Copy the production dependencies from the deps stage and also
# the built application from the build stage into the image.
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=build /usr/src/app/dist ./dist
# Run the application.
CMD yarn start

View File

@ -3,5 +3,5 @@
- ✅ Deactivate Xiaoai - ✅ Deactivate Xiaoai
- ✅ Update long/short memories - ✅ Update long/short memories
- ✅ Logger - ✅ Logger
- Docker - ✅ Npm export
- Npm export - ✅ Docker

6
compose.yaml Normal file
View File

@ -0,0 +1,6 @@
services:
server:
build:
context: .
environment:
NODE_ENV: production

View File

@ -22,7 +22,8 @@
"build": "tsup", "build": "tsup",
"db:gen": "npx prisma migrate dev --name init", "db:gen": "npx prisma migrate dev --name init",
"db:reset": "rm .bot.json && npx prisma migrate reset", "db:reset": "rm .bot.json && npx prisma migrate reset",
"prepublish": "npm run db:gen && npm run build" "prepublish": "npm run db:gen && npm run build",
"start": "node ./scripts/runner.js"
}, },
"dependencies": { "dependencies": {
"@prisma/client": "^5.8.1", "@prisma/client": "^5.8.1",

9
scripts/runner.js Normal file
View File

@ -0,0 +1,9 @@
import config from "../.migpt.js";
import { MiGPT } from "../dist/index.cjs";
async function main() {
const client = MiGPT.create(config);
await client.start();
}
main();

View File

@ -1,8 +0,0 @@
import { println } from "./utils/base";
import { kBannerASCII } from "./utils/string";
async function main() {
println(kBannerASCII);
}
main();

View File

@ -42,7 +42,7 @@ export class BaseSpeaker {
this.config = config; this.config = config;
const { const {
interval = 100, interval = 100,
tts = "doubao", tts = "xiaoai",
audio_beep = process.env.AUDIO_BEEP, audio_beep = process.env.AUDIO_BEEP,
} = config; } = config;
this.audio_beep = audio_beep; this.audio_beep = audio_beep;

View File

@ -8,6 +8,6 @@
"esModuleInterop": true, "esModuleInterop": true,
"moduleResolution": "node" "moduleResolution": "node"
}, },
"include": ["src", "tests"], "include": ["src", "tests", "scripts"],
"exclude": ["node_modules", "dist"] "exclude": ["node_modules", "dist"]
} }