From 70fce850c8ab4c572a944acc6502c8084b6ec026 Mon Sep 17 00:00:00 2001 From: KenGrofork Date: Tue, 23 Jan 2024 21:45:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E9=83=A8=E7=BD=B2=E6=B5=81?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用docker-compose一键启动 --- .dockerignore | 20 ++++++++++++++++++++ .env.example | 4 ++-- Dockerfile | 19 +++++++++++++++++++ docker-compose.yml | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9880403 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,20 @@ +node_modules +data + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### VS Code ### +.vscode/ + +### Macos ### +.DS_Store +.env +.git +.gitignore +docker +docs +README.md diff --git a/.env.example b/.env.example index 6cffcef..019ddca 100644 --- a/.env.example +++ b/.env.example @@ -4,7 +4,7 @@ PREFIX=/docs APIPREFIX=/api # mysql -DB_HOST=localhost +DB_HOST=localhost # 使用docker-compose时值应该为mysql DB_PORT=3306 DB_USER=root DB_PASS= @@ -24,7 +24,7 @@ MAILER_FROM= # Redis REDIS_PORT=6379 -REDIS_HOST=127.0.0.1 +REDIS_HOST=127.0.0.1 # 使用docker-compose时值应该为redis REDIS_PASSWORD= REDIS_USER= diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4d8880a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# 编译阶段 +FROM node:18-alpine AS build + +WORKDIR /app +COPY . . + +# 使用 pnpm 安装项目依赖 +RUN npm install -g pnpm +RUN pnpm install + +# 运行阶段 +FROM node:18-alpine +ENV TZ="Asia/Shanghai" + +WORKDIR /app +COPY --from=build /app . +EXPOSE 9520 + +CMD ["node", "./dist/main.js"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ff09336 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,39 @@ +version: '3.9' + +services: + mysql: + image: mysql:8 + command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci + restart: always + volumes: + - ./data/mysql/:/var/lib/mysql/ +# ports: +# - "3306:3306" + environment: + TZ: Asia/Shanghai # 指定时区 + MYSQL_ROOT_PASSWORD: "123456" # 配置root用户密码 + MYSQL_DATABASE: "chatgpt" # 业务库名 + MYSQL_USER: "chatgpt" # 业务库用户名 + MYSQL_PASSWORD: "chatgpt" # 业务库密码 + + redis: + image: redis + # command: --requirepass "12345678" # redis库密码,不需要密码注释本行 + restart: always +# ports: +# - "6379:6379" + environment: + TZ: Asia/Shanghai # 指定时区 + volumes: + - ./data/redis/:/data/ + + nineai-open: + build: ./ + container_name: nineai-open + restart: always + ports: + - "9520:9520" + volumes: + - ./.env:/app/.env + environment: + - TZ=Asia/Shanghai