本地调试
401字约1分钟
2024-10-03
环境准备
- python 3.8
- mysql 5.7
- node 16.20
拉取代码
git clone https://gitee.com/lucky_liuzhe/devops_api.git
git clone https://gitee.com/lucky_liuzhe/devops_web.git
后端配置
#进入代码目录安装依赖,安装前注释掉ansible==6.7.0,因为本地安装可能会有问题
pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
#windows本地安装依赖ansible会有问题,以下三处需要用到ansible模块,可在linux下进行调试ansible,linux下正常不会有问题
app_release->views.py #from libs.ansible_cicd import AnsibleApi
batch->views.py #from libs.ansible_cicd import AnsibleApi
cron->views.py #from libs.ansible_cicd import AnsibleApi
#配置数据库前需进入mysql创建数据库
CREATE DATABASE devops DEFAULT CHARACTER SET utf8;
#修改mysql用户名、密码、地址
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'devops',
'USER': 'root',
'PASSWORD': '123456',
'HOST': '192.168.0.11',
'PORT': '3306',
}
}
#同步数据库
python manage.py migrate
#创建管理员账号-user.py文件默认有配置的创建管理员用户名密码信息,之后用于登录,如果需要变动,请修改该配置
username = 'admin'
email = 'admin@example.com'
password = '123456'
first_name = '管理员'
#执行创建账号命令
python user.py
#启动服务
python manage.py runserver 0.0.0.0:8000
前端配置
#npm 建议使用淘宝镜像
npm config set registry https://registry.npmmirror.com/
#进入代码目录安装依赖
npm install #会自动根据package.json文件中的依赖关系信息自动下载并安装对应的模块
#如果没有安装上,请手动安装
npm install ace
npm install nprogress
npm install xterm
npm install xterm-addon-fit
#启动服务
npm run server
测试访问
http://ip:port/
默认管理员账号密码:admin/123456
swagger
http://ip:port/api/docs/