添加docker-compose.prod

This commit is contained in:
xie7654
2025-07-04 22:52:22 +08:00
parent 87d8d5ffb4
commit d705a88bd3
19 changed files with 536 additions and 70 deletions

4
.gitignore vendored
View File

@@ -68,4 +68,6 @@ vite.config.ts.*
.history
celerybeat-schedule.db
**/.pnpm-store
data/mysql
data/mysql
data/mysql_prod
web/node-compile-cache

View File

@@ -2,6 +2,14 @@
本项目为基于 Django5 + Vue3vben-admin全栈开发的企业级中后台管理系统支持动态菜单、按钮权限、自动化代码生成、前后端权限联动等功能适用于多角色、多权限场景的管理后台。
## 在线体验
- admin/admin123
- chenze/admin123
演示地址http://demo.ywwuzi.cn
文档地址:待完成
# 许可证
本项目遵循 MIT License。

62
backend/.dockerignore Normal file
View File

@@ -0,0 +1,62 @@
**/.idea/
.idea/**
**/*.pyc
__pycache__/
build/
*.egg-info/
.python-version
.pytest_cache/
eggs/
lib/
lib64/
.DS_Store
docs/_build/
*.env
**/local_settings.py
static/
.nitro
.output
*-dist.zip
*-dist.tar
*-dist.war
coverage
*.local
**/.vitepress/cache
.cache
.turbo
.temp
dev-dist
.stylelintcache
yarn.lock
package-lock.json
.VSCodeCounter
**/backend-mock/data
# local env files
.env.local
.env.*.local
.eslintcache
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
vite.config.mts.*
vite.config.mjs.*
vite.config.js.*
vite.config.ts.*
# Editor directories and files
.idea
# .vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
.history
celerybeat-schedule.db

View File

@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1
FROM python:3.12.2 AS dev
FROM python:3.12.2 AS base
WORKDIR /app
@@ -14,8 +14,20 @@ RUN apt-get update && \
COPY . .
RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
# 入口命令由 docker-compose 控制
# 收集静态文件
RUN python manage.py collectstatic --noinput
CMD ["sh", "-c", "sleep 10 && python manage.py runserver 0.0.0.0:8000"]
# 默认命令,开发和生产通过 docker-compose 覆盖
#CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
#CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
FROM base AS dev
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
# CMD ["sh", "-c", "sleep 5 && python manage.py runserver 0.0.0.0:8000"]
FROM base AS prod

View File

@@ -23,7 +23,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = 'django-insecure-m4@pv814c_m^pgpyhz^i96a@mcqh_@m9ccu(17*895t!79e!nb'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = os.getenv('DEBUG', 'False') == 'True'
ALLOWED_HOSTS = [
'*',
@@ -92,9 +92,9 @@ DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_vue',
'USER': 'root',
'PASSWORD': 'my-secret-pw',
'HOST': os.getenv('DATABASE_HOST', 'localhost'),
'USER': os.getenv('DB_USER', 'chenze'),
'PASSWORD': os.getenv('DB_PASSWORD', 'my-secret-pw'),
'HOST': os.getenv('DB_HOST', 'localhost'),
# 'HOST': 'localhost',
}
}
@@ -168,9 +168,24 @@ REST_FRAMEWORK = {
]
}
# celery 配置
CELERY_BROKER_URL = 'redis://localhost:6379/6'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/6'
# ================= Redis 缓存配置 =================
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": f"redis://{os.environ.get('REDIS_HOST', 'localhost')}:{os.environ.get('REDIS_PORT', 6379)}/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
}
}
# SESSION 存 Redis
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "default"
# ================= Celery 配置(适配环境变量) =================
CELERY_BROKER_URL = f"redis://{os.environ.get('REDIS_HOST', 'localhost')}:{os.environ.get('REDIS_PORT', 6379)}/0"
CELERY_RESULT_BACKEND = CELERY_BROKER_URL
# 时区设置
CELERY_TIMEZONE = 'Asia/Shanghai'
# 任务序列化方式

View File

@@ -12,3 +12,5 @@ redis==6.2.0
eventlet==0.40.0
goofish_api==0.0.6
flower==2.0.1
gunicorn==23.0.0
django_redis==6.0.0

View File

@@ -1,9 +1,6 @@
services:
mysql:
db:
image: mysql:8
environment:
MYSQL_ROOT_PASSWORD: my-secret-pw
MYSQL_DATABASE: django_vue
ports:
- "43306:3306"
volumes:
@@ -19,6 +16,57 @@ services:
timeout: 5s
retries: 10
redis:
image: redis:7
restart: always
ports:
- "46379:6379"
networks:
- dj_admin_network
env_file:
- ./docker/.env.dev
celery_worker:
build:
context: ./backend
dockerfile: Dockerfile
command: celery -A backend worker -l info
env_file:
- ./docker/.env.dev
depends_on:
- backend
- redis
networks:
- dj_admin_network
celery_beat:
build:
context: ./backend
dockerfile: Dockerfile
command: celery -A backend beat -l info
env_file:
- ./docker/.env.dev
depends_on:
- backend
- redis
networks:
- dj_admin_network
flower:
build:
context: ./backend
dockerfile: Dockerfile
command: celery -A backend flower --port=5555
env_file:
- ./docker/.env.dev
depends_on:
- backend
- redis
ports:
- "45555:5555"
networks:
- dj_admin_network
backend:
build:
@@ -28,18 +76,16 @@ services:
- ./backend:/app
ports:
- "48000:8000"
command: python manage.py runserver 0.0.0.0:8000
environment:
- DATABASE_HOST=mysql
networks:
- dj_admin_network
env_file:
- ./docker/.env.dev
environment:
DATABASE_HOST: "db"
depends_on:
mysql:
db:
condition: service_healthy
web:
build:
context: ./web
@@ -47,12 +93,13 @@ services:
volumes:
- ./web:/app
ports:
- "5678:5678"
- "45678:5678"
depends_on:
- backend
networks:
- dj_admin_network
env_file:
- ./docker/.env.dev
- ./docker/.env.docker
networks:
dj_admin_network:

111
docker-compose.prod.yml Normal file
View File

@@ -0,0 +1,111 @@
services:
db:
image: mysql:8
restart: always
env_file:
- ./docker/.env.prod
environment:
TZ: Asia/Shanghai
ports:
- "33306:3306"
volumes:
- ./sql/django_vue.sql:/docker-entrypoint-initdb.d/django_vue.sql
- ./data/mysql_prod:/var/lib/mysql # <-- 加这一行
networks:
- app_net
redis:
image: redis:7
restart: always
ports:
- "36379:6379"
networks:
- app_net
env_file:
- ./docker/.env.prod
backend:
build:
context: ./backend
dockerfile: Dockerfile
target: prod
command: gunicorn backend.wsgi:application --bind 0.0.0.0:8000
env_file:
- ./docker/.env.prod
depends_on:
- db
- redis
volumes:
- static_data:/app/static
- media_data:/app/media
ports:
- "38000:8000"
networks:
- app_net
celery_worker:
build:
context: ./backend
dockerfile: Dockerfile
command: celery -A backend worker -l info
env_file:
- ./docker/.env.prod
depends_on:
- backend
- redis
networks:
- app_net
celery_beat:
build:
context: ./backend
dockerfile: Dockerfile
command: celery -A backend beat -l info
env_file:
- ./docker/.env.prod
depends_on:
- backend
- redis
networks:
- app_net
flower:
build:
context: ./backend
dockerfile: Dockerfile
command: celery -A backend flower --port=5555
env_file:
- ./docker/.env.prod
depends_on:
- backend
- redis
ports:
- "35555:5555"
networks:
- app_net
frontend:
build:
context: ./web
dockerfile: Dockerfile
target: prod
depends_on:
- backend
ports:
- "35678:80"
networks:
- app_net
env_file:
- ./docker/.env.prod
volumes:
db_data:
static_data:
media_data:
networks:
app_net:
driver: bridge

View File

@@ -1 +1,31 @@
VITE_BACKEND_URL=http://localhost:8000
VITE_BACKEND_URL=http://backend:8000
# MySQL
MYSQL_DATABASE=django_vue
MYSQL_USER=chenze
MYSQL_PASSWORD=ca25045c409e60fab517c7327dd527ef27c48ca6
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=58ce16c2ee80311e130b30f11160ef77e0ac6aa7
# Django
DEBUG=False
DJANGO_ALLOWED_HOSTS=*
DB_NAME=django_vue
DB_USER=root
DB_PASSWORD=58ce16c2ee80311e130b30f11160ef77e0ac6aa7
DB_HOST=db
DB_PORT=3306
# Redis
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=e4c173f1b708e8e90f12bc1481e8b3ef
# Flower
FLOWER_PORT=5555
# 后端服务端口
BACKEND_PORT=8000
# Nginx
NGINX_PORT=80

View File

@@ -1 +0,0 @@
VITE_BACKEND_URL=http://backend:8000

30
docker/.env.prod Normal file
View File

@@ -0,0 +1,30 @@
# MySQL
MYSQL_DATABASE=django_vue
MYSQL_USER=chenze
MYSQL_PASSWORD=ca25045c409e60fab517c7327dd527ef27c48ca6
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=58ce16c2ee80311e130b30f11160ef77e0ac6aa7
# Django
DEBUG=False
DJANGO_ALLOWED_HOSTS=*
DB_NAME=django_vue
DB_USER=chenze
DB_PASSWORD=ca25045c409e60fab517c7327dd527ef27c48ca6
DB_HOST=db
DB_PORT=3306
# Redis
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=e4c173f1b708e8e90f12bc1481e8b3ef
# Flower
FLOWER_PORT=5555
# 后端服务端口
BACKEND_PORT=8000
# Nginx
NGINX_PORT=80

View File

@@ -11,7 +11,7 @@
Target Server Version : 90300 (9.3.0)
File Encoding : 65001
Date: 03/07/2025 16:53:14
Date: 04/07/2025 22:51:23
*/
SET NAMES utf8mb4;
@@ -400,7 +400,7 @@ CREATE TABLE `system_login_log` (
`user_ip` varchar(50) NOT NULL COMMENT '用户 IP',
`user_agent` varchar(512) NOT NULL COMMENT '浏览器 UA',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- ----------------------------
-- Records of system_login_log
@@ -419,6 +419,11 @@ INSERT INTO `system_login_log` (`id`, `remark`, `creator`, `modifier`, `update_t
INSERT INTO `system_login_log` (`id`, `remark`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `username`, `result`, `user_ip`, `user_agent`) VALUES (11, NULL, NULL, NULL, '2025-07-02 08:57:47.575085', '2025-07-02 08:57:47.575095', 0, 'chenze', 1, '127.0.0.1', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36');
INSERT INTO `system_login_log` (`id`, `remark`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `username`, `result`, `user_ip`, `user_agent`) VALUES (12, NULL, NULL, NULL, '2025-07-02 09:16:09.528323', '2025-07-02 09:16:09.528338', 0, 'admin', 1, '127.0.0.1', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36');
INSERT INTO `system_login_log` (`id`, `remark`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `username`, `result`, `user_ip`, `user_agent`) VALUES (13, NULL, NULL, NULL, '2025-07-03 01:56:33.628362', '2025-07-03 01:56:33.628383', 0, 'admin', 1, '127.0.0.1', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36');
INSERT INTO `system_login_log` (`id`, `remark`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `username`, `result`, `user_ip`, `user_agent`) VALUES (14, NULL, NULL, NULL, '2025-07-03 09:03:55.601317', '2025-07-03 09:03:55.601325', 0, 'chenze', 1, '127.0.0.1', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36');
INSERT INTO `system_login_log` (`id`, `remark`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `username`, `result`, `user_ip`, `user_agent`) VALUES (15, NULL, NULL, NULL, '2025-07-04 05:48:38.799378', '2025-07-04 05:48:38.799423', 0, 'chenze', 1, '127.0.0.1', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36');
INSERT INTO `system_login_log` (`id`, `remark`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `username`, `result`, `user_ip`, `user_agent`) VALUES (16, NULL, NULL, NULL, '2025-07-04 09:41:07.394602', '2025-07-04 09:41:07.394619', 0, 'chenze', 1, '127.0.0.1', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36');
INSERT INTO `system_login_log` (`id`, `remark`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `username`, `result`, `user_ip`, `user_agent`) VALUES (17, NULL, NULL, NULL, '2025-07-04 14:46:34.812031', '2025-07-04 14:46:34.812041', 0, 'chenze', 1, '127.0.0.1', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36');
INSERT INTO `system_login_log` (`id`, `remark`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `username`, `result`, `user_ip`, `user_agent`) VALUES (18, NULL, NULL, NULL, '2025-07-04 14:48:20.347506', '2025-07-04 14:48:20.347516', 0, 'admin', 1, '127.0.0.1', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36');
COMMIT;
-- ----------------------------
@@ -634,7 +639,7 @@ CREATE TABLE `system_role` (
-- Records of system_role
-- ----------------------------
BEGIN;
INSERT INTO `system_role` (`id`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `name`, `status`, `sort`, `remark`, `code`) VALUES (2, NULL, 'admin', '2025-07-03 02:58:16.720330', '2025-06-30 13:43:33.222244', 0, '普通角色', 1, 0, '', 'common');
INSERT INTO `system_role` (`id`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `name`, `status`, `sort`, `remark`, `code`) VALUES (2, NULL, 'admin', '2025-07-03 09:05:32.917555', '2025-06-30 13:43:33.222244', 0, '普通角色', 1, 0, '', 'common');
INSERT INTO `system_role` (`id`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `name`, `status`, `sort`, `remark`, `code`) VALUES (3, 'admin', 'admin', '2025-07-03 02:58:07.056753', '2025-06-30 14:01:56.403744', 0, '超级管理员', 1, 0, '', 'super_admin');
COMMIT;
@@ -657,7 +662,7 @@ CREATE TABLE `system_role_permission` (
KEY `system_role_permission_role_id_ca5e9412_fk_system_role_id` (`role_id`),
CONSTRAINT `system_role_permission_menu_id_bf701eaf_fk_system_menu_id` FOREIGN KEY (`menu_id`) REFERENCES `system_menu` (`id`),
CONSTRAINT `system_role_permission_role_id_ca5e9412_fk_system_role_id` FOREIGN KEY (`role_id`) REFERENCES `system_role` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=79 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB AUTO_INCREMENT=88 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- ----------------------------
-- Records of system_role_permission
@@ -678,7 +683,6 @@ INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `up
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (23, NULL, NULL, NULL, '2025-06-30 14:01:56.610751', 0, '2025-06-30 14:01:56.610849', 8, 3);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (24, NULL, NULL, NULL, '2025-06-30 14:01:56.634161', 0, '2025-06-30 14:01:56.634243', 9, 3);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (25, NULL, NULL, NULL, '2025-06-30 14:01:56.657691', 0, '2025-06-30 14:01:56.657753', 10, 3);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (26, NULL, NULL, NULL, '2025-07-01 07:57:14.090252', 0, '2025-07-01 07:57:14.090324', 8, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (29, NULL, NULL, NULL, '2025-07-01 07:57:14.090386', 0, '2025-07-01 07:57:14.090399', 7, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (30, NULL, NULL, NULL, '2025-07-01 07:57:25.893132', 0, '2025-07-01 07:57:25.893185', 12, 3);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (31, NULL, NULL, NULL, '2025-07-01 07:57:25.893198', 0, '2025-07-01 07:57:25.893211', 13, 3);
@@ -686,10 +690,7 @@ INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `up
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (33, NULL, NULL, NULL, '2025-07-02 08:41:54.581823', 0, '2025-07-02 08:41:54.581874', 1, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (34, NULL, NULL, NULL, '2025-07-02 08:41:54.581888', 0, '2025-07-02 08:41:54.581902', 18, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (35, NULL, NULL, NULL, '2025-07-02 08:41:54.581914', 0, '2025-07-02 08:41:54.581927', 17, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (41, NULL, NULL, NULL, '2025-07-02 11:25:22.723470', 0, '2025-07-02 11:25:22.723543', 16, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (42, NULL, NULL, NULL, '2025-07-02 11:25:22.723559', 0, '2025-07-02 11:25:22.723574', 15, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (43, NULL, NULL, NULL, '2025-07-02 13:52:57.845593', 0, '2025-07-02 13:52:57.845675', 9, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (44, NULL, NULL, NULL, '2025-07-02 13:52:57.845692', 0, '2025-07-02 13:52:57.845710', 10, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (45, NULL, NULL, NULL, '2025-07-03 02:58:07.066807', 0, '2025-07-03 02:58:07.066937', 15, 3);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (46, NULL, NULL, NULL, '2025-07-03 02:58:07.066958', 0, '2025-07-03 02:58:07.066974', 16, 3);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (47, NULL, NULL, NULL, '2025-07-03 02:58:07.066986', 0, '2025-07-03 02:58:07.066999', 17, 3);
@@ -724,6 +725,15 @@ INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `up
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (76, NULL, NULL, NULL, '2025-07-03 02:58:07.067715', 0, '2025-07-03 02:58:07.067729', 51, 3);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (77, NULL, NULL, NULL, '2025-07-03 02:58:07.067740', 0, '2025-07-03 02:58:07.067752', 52, 3);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (78, NULL, NULL, NULL, '2025-07-03 02:58:07.067763', 0, '2025-07-03 02:58:07.067775', 53, 3);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (79, NULL, NULL, NULL, '2025-07-03 09:04:53.644448', 0, '2025-07-03 09:04:53.644494', 16, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (80, NULL, NULL, NULL, '2025-07-03 09:05:02.903456', 0, '2025-07-03 09:05:02.903513', 8, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (81, NULL, NULL, NULL, '2025-07-03 09:05:11.591940', 0, '2025-07-03 09:05:11.592014', 9, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (82, NULL, NULL, NULL, '2025-07-03 09:05:19.612920', 0, '2025-07-03 09:05:19.612966', 10, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (83, NULL, NULL, NULL, '2025-07-03 09:05:32.927909', 0, '2025-07-03 09:05:32.927962', 34, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (84, NULL, NULL, NULL, '2025-07-03 09:05:32.927975', 0, '2025-07-03 09:05:32.927988', 35, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (85, NULL, NULL, NULL, '2025-07-03 09:05:32.928000', 0, '2025-07-03 09:05:32.928012', 36, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (86, NULL, NULL, NULL, '2025-07-03 09:05:32.928024', 0, '2025-07-03 09:05:32.928036', 37, 2);
INSERT INTO `system_role_permission` (`id`, `remark`, `creator`, `modifier`, `update_time`, `is_deleted`, `create_time`, `menu_id`, `role_id`) VALUES (87, NULL, NULL, NULL, '2025-07-03 09:05:32.928047', 0, '2025-07-03 09:05:32.928060', 38, 2);
COMMIT;
-- ----------------------------
@@ -766,8 +776,8 @@ CREATE TABLE `system_users` (
-- Records of system_users
-- ----------------------------
BEGIN;
INSERT INTO `system_users` (`id`, `password`, `last_login`, `is_superuser`, `username`, `first_name`, `last_name`, `email`, `is_staff`, `is_active`, `date_joined`, `remark`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `mobile`, `nickname`, `gender`, `language`, `city`, `province`, `country`, `avatar_url`, `status`, `login_ip`) VALUES (1, 'pbkdf2_sha256$1000000$ce99fyPlGRhdkDDRDsvQvw$6qzU+iuxtczU0Ebki6Tu0IUgYDWqELLUj9kgHfrlkJI=', '2025-07-03 01:56:33.596708', 1, 'admin', '', '', '765462425@qq.com', 1, 1, '2025-06-29 13:09:47.780431', NULL, NULL, 'admin', '2025-07-03 03:41:58.074874', '2025-06-29 13:09:47.892332', 0, '18888888888', NULL, 0, NULL, NULL, NULL, NULL, NULL, 1, '127.0.0.1');
INSERT INTO `system_users` (`id`, `password`, `last_login`, `is_superuser`, `username`, `first_name`, `last_name`, `email`, `is_staff`, `is_active`, `date_joined`, `remark`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `mobile`, `nickname`, `gender`, `language`, `city`, `province`, `country`, `avatar_url`, `status`, `login_ip`) VALUES (2, 'pbkdf2_sha256$1000000$Kio1bmTf57Vi05slZAeIQm$lNBERuBlhT2UYJYt+vO2M5szmFT51S34/Cy4B5O76uw=', '2025-07-02 08:57:47.554870', 0, 'chenze', '', '', '765462425@qq.com', 0, 1, '2025-07-01 06:25:50.946515', NULL, 'admin', 'admin', '2025-07-03 03:20:14.862186', '2025-07-01 06:25:50.947136', 0, '18677777777', NULL, 0, NULL, NULL, NULL, NULL, NULL, 1, '127.0.0.1');
INSERT INTO `system_users` (`id`, `password`, `last_login`, `is_superuser`, `username`, `first_name`, `last_name`, `email`, `is_staff`, `is_active`, `date_joined`, `remark`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `mobile`, `nickname`, `gender`, `language`, `city`, `province`, `country`, `avatar_url`, `status`, `login_ip`) VALUES (1, 'pbkdf2_sha256$1000000$b8gwLD046kZQIz1VMiUnmN$8/HRWXvV2MawPTME6SBo2bmA+pXYMN375l91lFdIIZE=', '2025-07-04 14:48:20.327087', 1, 'admin', '', '', '765462425@qq.com', 1, 1, '2025-06-29 13:09:47.780431', NULL, NULL, 'admin', '2025-07-04 14:48:13.446261', '2025-06-29 13:09:47.892332', 0, '18888888888', NULL, 0, NULL, NULL, NULL, NULL, NULL, 1, '127.0.0.1');
INSERT INTO `system_users` (`id`, `password`, `last_login`, `is_superuser`, `username`, `first_name`, `last_name`, `email`, `is_staff`, `is_active`, `date_joined`, `remark`, `creator`, `modifier`, `update_time`, `create_time`, `is_deleted`, `mobile`, `nickname`, `gender`, `language`, `city`, `province`, `country`, `avatar_url`, `status`, `login_ip`) VALUES (2, 'pbkdf2_sha256$1000000$HTigORn4exnjjE2JJqJXy5$c3Ivb+1m+9a5aOnjDJvEEfCcUO1/JfZKYLbnkvJTbBE=', '2025-07-04 14:46:34.788246', 0, 'chenze', '', '', '765462425@qq.com', 0, 1, '2025-07-01 06:25:50.946515', NULL, 'admin', 'admin', '2025-07-03 09:03:50.080498', '2025-07-01 06:25:50.947136', 0, '18677777777', NULL, 0, NULL, NULL, NULL, NULL, NULL, 1, '127.0.0.1');
COMMIT;
-- ----------------------------

View File

@@ -1,7 +1,55 @@
**/node_modules
.git
.gitignore
*.md
dist
**/.idea/
.idea/**
**/*.pyc
__pycache__/
build/
*.egg-info/
.python-version
.pytest_cache/
dist/
eggs/
lib/
lib64/
.DS_Store
docs/_build/
static/
.nitro
.output
coverage
**/.vitepress/cache
.cache
.turbo
dist.zip
.temp
.stylelintcache
yarn.lock
package-lock.json
.VSCodeCounter
**/backend-mock/data
# local env files
.eslintcache
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
vite.config.mts.*
vite.config.mjs.*
vite.config.js.*
vite.config.ts.*
# Editor directories and files
.idea
# .vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
.history
**/node_modules

View File

@@ -1,46 +1,62 @@
# syntax=docker/dockerfile:1
####################
# 生产阶段
# 公共基础阶段
####################
FROM nginx:alpine AS prod
# 拷贝编译后的静态文件到 nginx
COPY --from=build /app/dist /usr/share/nginx/html
# 拷贝 nginx 配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
####################
# 开发阶段
####################
FROM node:22.17.0 AS dev
FROM node:22.17.0 AS base
WORKDIR /app
ENV PNPM_SKIP_PROMPT=true
# 拷贝项目
COPY . .
COPY /apps/web-antd/.env.docker /apps/web-antd/.env.local
# 安装 pnpm(官方推荐 corepack更好
# 安装 pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
# 安装依赖(一定要在 monorepo 根目录,保证 workspace 有效)
# 清理依赖缓存
RUN pnpm store prune && rm -rf $(pnpm store path) && \
rm -rf node_modules .npmrc package-lock.json pnpm-lock.yaml .pnpm-store .turbo && \
find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +
RUN npm run clean
RUN yes | pnpm recursive install
# 安装依赖
RUN pnpm install --force
# 设置前端工作目录(根据实际情况修改)
# 暴露前端 dev server 端口
EXPOSE 5678
#CMD ["tail", "-f", "/dev/null"]
####################
# 开发阶段
####################
# 默认启动 dev server
FROM base AS dev
# 暴露端口(根据需要)
EXPOSE 5678
# CMD ["tail", "-f", "/dev/null"]
# 启动开发服务器
CMD ["npm", "run", "dev:antd"]
# --- 构建阶段 ---
FROM base AS build
# 构建生产版本
RUN npm run build:antd
# --- 生产阶段 ---
FROM nginx:1.25-alpine AS prod
# 删除默认配置
RUN rm -rf /usr/share/nginx/html/*
# 从构建阶段拷贝打包产物到 nginx html 目录
COPY --from=build /app/apps/web-antd/dist /usr/share/nginx/html
# 如果有需要,也可以拷贝自定义 nginx 配置
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 5268
# 默认启动 nginx
CMD ["nginx", "-g", "daemon off;"]

View File

@@ -1 +0,0 @@
VITE_BACKEND_URL=http://backend:8000

View File

@@ -1,7 +1,7 @@
VITE_BASE=/
# 接口地址
VITE_GLOB_API_URL=http://127.0.0.1:8000/api
VITE_GLOB_API_URL=/api
# 是否开启压缩,可以设置为 none, brotli, gzip
VITE_COMPRESS=gzip

View File

@@ -24,7 +24,7 @@ const MOCK_USER_OPTIONS: BasicOption[] = [
},
{
label: 'User',
value: 'xj',
value: 'chenze',
},
];

View File

@@ -1,10 +1,13 @@
import { defineConfig } from '@vben/vite-config';
import { loadEnv } from 'vite';
import * as console from "node:console";
export default defineConfig(async ({ mode }) => {
// eslint-disable-next-line n/prefer-global/process
const env = loadEnv(mode, process.cwd(), '');
const env = loadEnv(mode, process.cwd());
// 这样获取
const backendUrl = env.VITE_BACKEND_URL;
console.log(backendUrl)
return {
application: {},
vite: {
@@ -13,7 +16,7 @@ export default defineConfig(async ({ mode }) => {
port: 5678,
proxy: {
'/api': {
target: env.VITE_BACKEND_URL,
target: backendUrl,
changeOrigin: true,
},
},

72
web/nginx.conf Normal file
View File

@@ -0,0 +1,72 @@
worker_processes 1;
events { worker_connections 1024; }
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name _;
# 前端静态资源
root /usr/share/nginx/html;
# 健康检查
location /healthz {
return 200 'ok';
add_header Content-Type text/plain;
}
# 代理 Django 静态文件
location /static/ {
alias /app/static/;
expires 30d;
add_header Cache-Control "public";
}
# 代理 Django 媒体文件
location /media/ {
alias /app/media/;
expires 30d;
add_header Cache-Control "public";
}
# 代理后端 API
location /api/ {
proxy_pass http://backend:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 100m;
client_body_buffer_size 128k;
proxy_connect_timeout 180;
proxy_send_timeout 180;
proxy_read_timeout 180;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
#proxy_cache_bypass $http_upgrade;
#proxy_cache_key $uri$request_body; #增加此行
#proxy_cache_methods GET POST; #增加此行
#add_header Access-Control-Allow-Headers X-API-Token;
access_log /var/log/nginx/assets_access.log;
error_log /var/log/nginx/assets_error.log;
}
# 前端 history 路由
location / {
try_files $uri $uri/ /index.html;
}
# gzip
gzip on;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css application/json;
gzip_min_length 1k;
gzip_comp_level 2;
}
}