Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/*
.next
.git
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 使用官方 Node.js 为基础镜像
FROM node:latest

# 设置工作目录
WORKDIR /app

# 复制 package.json 和 package-lock.json(如果存在)
COPY package.json yarn.lock ./

# 设置淘宝镜像源
RUN yarn config set registry https://registry.npmmirror.com

# 设置 Prisma 引擎的国内镜像源
ENV PRISMA_ENGINES_MIRROR="https://registry.npmmirror.com/-/binary/prisma"

# 安装项目依赖
RUN yarn install

# 复制项目文件和文件夹到工作目录
COPY . .
COPY .env ./.env

# 预安装 Prisma CLI
RUN npx prisma generate

# 构建 Next.js 项目
RUN yarn build

# 暴露 3000 端口
EXPOSE 3000

# 启动 Next.js 服务器
CMD ["yarn", "start"]
1 change: 1 addition & 0 deletions MP_verify_uuVKNEzV7WrJ2xyt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uuVKNEzV7WrJ2xyt
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,44 @@ and that's all you need to get started!
## License

[MIT](https://choosealicense.com/licenses/mit/)



## 阿里云部署
- 将 docker-compose.yml 文件部署到服务器上并使用 Podman Compose 运行
- 运行 Podman Compose:在项目目录中,运行以下命令以使用 Podman Compose 启动你的服务:
- podman-compose up
停止服务:podman-compose down
查看运行的容器:podman ps

Redis 容器启动时的内存超额分配警告指的是 Linux 系统中 vm.overcommit_memory 设置的问题。这个设置控制着 Linux 内核如何管理内存分配,尤其是对于需要创建大内存快照(如 Redis 的持久化操作)的场景。当 vm.overcommit_memory 设置为 0(默认值),操作系统允许超额分配内存,但在内存不足时可能导致OOM(内存不足)杀手终止进程。设置为 1 时,内核允许超额承诺所有物理内存和交换空间,这对于 Redis 来说是推荐的设置,因为它可以减少因内存超分配而导致的失败。你可以通过执行 sysctl vm.overcommit_memory=1 来调整这个设置。

- 测试mysql连接,测试redis连接
redis-cli -h 60.205.108.91 -p 6379 -a your_redis_password


- 保存 schema.prisma 文件之后,运行以下命令重新生成 Prisma Client:
npx prisma generate

为了将你的项目中的数据表部署到数据库中,首先确保你的环境变量 DATABASE_URL 正确配置了数据库连接信息。然后,在项目目录中运行
npx prisma db push 命令。
这个命令会根据你的 schema.prisma 文件中定义的模型,创建或更新数据库中的表结构,使其与你的 Prisma 模型匹配。这是一个快速同步 Prisma 模型到数据库的方法,非常适用于开发环境。在执行之前,确保数据库服务已经运行,并且可以从你的服务器访问。


# 构建Docker镜像
docker build -t your-app-name .

# 运行Docker容器
docker run -p 3000:3000 your-app-name


<!--
在部署的时候,遇到的问题
1、yarn install 时,会遇到prisma 的问题,可以通过设置国内镜像解决
export PRISMA_ENGINES_MIRROR="https://registry.npmmirror.com/-/binary/prisma"
2、 然后就可以执行 npx prisma generate npx prisma db push
3、重新执行 yarn install 可以成功
4、继续 yarn run build 会遇到谷歌字体的问题,先注释掉
5、重新 yarn run build
6、执行 yarn run start 就可以了
-->
102 changes: 102 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
version: "3.8"

services:
huiyuan:
#app服务使用 build: . 来构建 Dockerfile。
build: .
#podman build -t huiyuan-app:latest . 根据Dockerfile创建镜像
#指定镜像名称
image: huiyuan:latest
ports:
- "3000:3000"
environment:
#确保 DATABASE_URL 和 REDIS_URL 环境变量使用服务名,例如 mysql 和 redis。
- NEXTAUTH_SECRET:woaiwo
- DATABASE_URL=mysql://your_user:your_user_password@60.205.108.91:3306/your_database
- REDIS_URL=redis://:your_redis_password@60.205.108.91:6379
- UPLOAD_SERVER=http://img.ipaintgarden.com/upload
- UPLOAD_SECRET=img-generated-api-key
#微信回调域名
- NEXT_PUBLIC_SERVER_DOMAIN=http://hy.ipaintgarden.com
#绘园公众号
- NEXT_PUBLIC_WEIXIN_APP_ID=wxf32187893c13aafb
- WEIXIN_APP_SECRET=333e179ffcb17113165d8624de32ad23
#绘园开放平台
- NEXT_PUBLIC_WX_OPEN_APP_ID=wxf5e5974b6aacfafb
- WX_OPEN_APP_SECRET=b14baebd47f83f11bebd7ba17a275af9
# volumes:
# - /opt/prisma-engines:/opt/prisma-engines
#depends_on 表示 app 服务依赖于 mysql 和 redis 服务
depends_on:
- mysql
- redis

mysql:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: your_password # Replace with your desired password
MYSQL_DATABASE: your_database # Replace with your desired database name
MYSQL_USER: your_user # Replace with your desired user
MYSQL_PASSWORD: your_user_password # Replace with your desired user password
ports:
- "3306:3306"
volumes:
- mysql_data:/var/lib/mysql

redis:
image: redis:latest
command: redis-server --requirepass your_redis_password # Replace with your desired Redis password
ports:
- "6379:6379"
volumes:
- redis_data:/data

volumes:
mysql_data:
redis_data:

#npx prisma generate
#打包上传后解压
#unzip -o huiyuan.zip

#您可以通过 docker-compose up --build 启动所有服务。这样就可以确保您的应用容器能够与数据库和缓存容器通信
#容器启动后手动运行
#进入到运行你的 Node.js 应用的 Docker 容器内部,然后运行
#将schema.prisma 文件中定义的模型,创建到数据库中
#npx prisma db push

# 根据Dockerfile创建镜像
# podman build -t huiyuan-app:latest .
# docker build -t huiyuan-app:latest .
# docker run -p 3000:3000 --name huiyuan-app-1 huiyuan-app
# podman-compose up

# podman exec -it huiyuan_app_1 sh 进入容器中
# npx prisma db push 数据库迁移或创建操作


#运行 podman-compose down 命令会停止并删除由 podman-compose up 命令启动的所有容器
#这个命令在你需要清理所有由 docker-compose.yml 文件定义的服务时非常有用,比如在开发结束后,或者想要重启所有服务时。它为你提供了一种快速将环境恢复到初始状态的方法。
#如果你想在删除容器的同时自动清理相关的卷,可以在删除容器时使用 docker-compose down -v 命令,其中 -v 标志会删除与在 docker-compose.yml 文件中定义的服务相关联的所有卷。
#请记住,删除卷是不可逆的操作,所以在执行删除操作之前,请确保你已经保存了所有需要的数据。

# podman images
# podman rmi 8ce071eea1df 019814493c7a 170a1e90f843
# 修改docker-compose.yml文件后
# podman-compose down
# podman-compose up --build 重新生成镜像和容器

# docker-compose up 是 Docker Compose 的一个命令,用于启动并运行整个应用。你提到的两种形式之间的区别在于是否附带了 --build 选项:

# docker-compose up:这个命令会启动并运行 docker-compose.yml 文件中定义的所有服务。如果服务所依赖的镜像不存在,Docker Compose 会尝试从本地或远程镜像仓库拉取这些镜像。如果镜像已经存在,它不会尝试重新构建镜像,而是直接使用现有的镜像来启动容器。

# docker-compose up --build:这个命令除了执行 docker-compose up 的所有操作之外,还会强制构建(或重建)服务所依赖的镜像,即使这些镜像已经存在。这对于确保使用的是最新的代码和依赖非常有用,特别是在开发过程中,当你频繁更改应用代码或依赖时。在构建完成后,它会启动并运行服务。

# 简而言之,不带 --build 选项时,Docker Compose 会尝试使用现有镜像来启动服务,而不会尝试构建新的镜像。当使用 --build 选项时,Docker Compose 会先构建(或重建)镜像,然后再启动服务,这样可以确保你的容器运行的是最新版本的镜像。

# 在开发过程中,如果你对 Dockerfile 或服务的构建上下文(如项目文件)进行了更改,使用 docker-compose up --build 会很有帮助,因为它确保了你的更改会被包含在新构建的镜像中。如果你确定没有对服务的依赖或代码进行更改,或者你只是想快速启动服务,使用 docker-compose up 就足够了。





14 changes: 12 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
domains: ['uploadthing.com', 'lh3.googleusercontent.com'],
domains: ['127.0.0.1','60.205.108.91','thirdwx.qlogo.cn','localhost','img.ipaintgarden.com','lh3.googleusercontent.com'],
},
experimental: {
appDir: true
}
},
webpack: (config, options) => {
// 添加 SVG 处理规则
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
});

// 返回更新后的配置
return config;
},
}

module.exports = nextConfig
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@upstash/redis": "^1.21.0",
"autoprefixer": "10.4.14",
"axios": "^1.4.0",
"bcryptjs": "^2.4.3",
"class-variance-authority": "^0.6.0",
"clsx": "^1.2.1",
"cmdk": "^0.2.0",
Expand All @@ -55,6 +56,7 @@
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.44.2",
"react-textarea-autosize": "^8.4.1",
"redis": "^4.6.13",
"server-only": "^0.0.1",
"sharp": "^0.32.1",
"tailwind-merge": "^1.12.0",
Expand All @@ -65,10 +67,12 @@
"zod": "^3.21.4"
},
"devDependencies": {
"@svgr/webpack": "^8.1.0",
"@types/editorjs__header": "^2.6.0",
"@types/lodash.debounce": "^4.0.7",
"@types/node": "20.2.5",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"@types/editorjs__header": "^2.6.0",
"@types/lodash.debounce": "^4.0.7"
"@types/uuid": "^9.0.8"
}
}
26 changes: 26 additions & 0 deletions prisma/addUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { PrismaClient } = require('@prisma/client');
const bcrypt = require('bcryptjs');
const prisma = new PrismaClient();
//ts-node --esm prisma/addUser.ts
async function createUser() {
try {
// 使用 bcrypt 哈希密码
const hashedPassword = await bcrypt.hash('123456', 10);

// 使用 Prisma 创建用户
const user = await prisma.user.create({
data: {
username: 'test',
password: hashedPassword,
// 如果有其他必填字段,请在这里添加
// 例如: email: 'your-email@example.com'
},
});

console.log('User created:', user);
} catch (error) {
console.error('Error creating user:', error);
}
}

createUser();
17 changes: 16 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// npm install -g prisma 安装新的Prisma CLI:然后,你可以通过npx来调用本地安装的Prisma CLI,例如:npx prisma --help
// npx prisma generate
// npx prisma db push

//设置国内镜像
//export PRISMA_ENGINES_MIRROR="https://registry.npmmirror.com/-/binary/prisma"
//使用 nano 或 vi 等命令行文本编辑器来编辑这些文件
//vi ~/.bashrc
//滚动到文件的底部,然后添加以下行
//export PRISMA_ENGINES_MIRROR="https://registry.npmmirror.com/-/binary/prisma"
//如果您使用 vi,请按 Esc,输入 :wq,然后按 Enter 来保存并退出
//为了让这些更改立即生效(而不需要注销并重新登录),在终端中运行以下命令
//source ~/.bashrc

generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "linux-arm64-openssl-3.0.x", "rhel-openssl-1.1.x", "debian-openssl-3.0.x"]
}

datasource db {
Expand Down Expand Up @@ -46,6 +60,7 @@ model Session {
model User {
id String @id @default(cuid())
name String?
password String?
email String? @unique
emailVerified DateTime?
createdSubreddits Subreddit[] @relation("CreatedBy")
Expand Down Expand Up @@ -134,4 +149,4 @@ model CommentVote {
type VoteType

@@id([userId, commentId])
}
}
Loading