自动化测试平台开发(二):项目基础结构搭建 - 前后端分离

本平台涉及后端服务、数据管理、前端交互,所以需要搭建两个项目:前端、后端,并且实现前后端分离。

  1. 后端项目采用Mysql + Django + djangorestframwork实现,提供前端交互所需请求接口。
  2. 前端项目采用vue-admin-template模块项目,做二次开发,实现用户行为交互。

一、项目搭建

  1. 新建django项目backend
    # 安装Django
    pip install -U Django
    
    # 新建django项目
    django-admin startproject backend
    
    # backend项目创建后,可看到自动新建了文件及目录:backend/backend/*, 新建 app
    cd backend/
    python manage.py startapp user_auth  // 这里新建一个app用来实现用户登录验证
    
    # 启动django服务
    python manage.py runserver 127.0.0.1:8000
    
    # 注:django项目新建后默认配置数据库为sqlite3,这里我暂时没有机器安装了MySQL服务,所以暂时不做修改,本地开发调试先使用sqlite3
    
    # 新建superuser
    python manage.py createsuperuser
    
    # 浏览器打开地址登录后台管理: http://127.0.0.1:8000/admin/
    

      

  2. 创建前端项目frontend
    # 前端项目我们采用vue-admin-template模板项目做二次开发,所以先下载源码
    
    # 安装npm 或yarn
    
    # 安装依赖包
    npm install
    
    # 修改后端服务地址
    
    # 启动前端服务
    npm run dev

    # 进入前端项目可看到基本模板页面

     

     

      

二、项目服务运行

 

  1. 后端服务 - supervisor

    # supervisor守护进程运行
    # supervisorctl status
    # supervisorctl restart xxx
    
    [root@iZbp1aal369fl3i2lkqybkZ ~]# cat /etc/supervisord.d/platform-backend.ini
    [program:test-platform-backend]
    command=/data/platform/test-platform/venv/bin/python3 manage.py runserver --noreload 0.0.0.0:8862
    directory=/data/platform/test-platform/backend
    autostart=true       ; 在supervisord启动的时候也自动启动
    stopasgroup=true     ;默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
    killasgroup=true     ;默认为false,向进程组发送kill信号,包括子进程nclude /etc/nginx/uwsgi_params;
     
    [root@iZbp1aal369fl3i2lkqybkZ ~]# supervisorctl status
    test-platform-backend            RUNNING   pid 31727, uptime 0:30:49
     
    [root@iZbp1aal369fl3i2lkqybkZ ~]# supervisorctl restart test-platform-backend
  2. 前端服务、docs在线文档 - nginx

    [root@iZbp1aal369fl3i2lkqybkZ ~]# cat /etc/nginx/conf.d/server.conf
    # test platform  production env
    server {
            listen 8869;
            #listen [::]:80 default_server;
     
            #root /var/www/html;
     
            # Add index.php to the list if you are using PHP
            #index index.html index.htm index.nginx-debian.html;
     
            # 测试服务器
            server_name 47.9.15.123;
     
            location /api {
                    client_max_body_size 100M;
                    client_body_buffer_size 100M;
                    client_body_timeout 120;
                    # uwsgi_send_timeout 600;
                    # uwsgi_connect_timeout 600;
                    # uwsgi_read_timeout 600;
                    # uwsgi_param X-Real-IP $remote_addr;
                    # uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
                    # uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
                    # include uwsgi_params;
                    # uwsgi_pass 127.0.0.1:8862;
                    proxy_pass http://127.0.0.1:8862;
            }
     
            location / {
                    root    /data/platform/test-platform/frontend/dist;
                    index  index.html index.htm index.jsp;
                    #proxy_pass http://127.0.0.1:8867;
            }
     
    }
     
     
    # test platform docs
    server {
            listen 8865;
            #listen [::]:80 default_server;
     
            # 测试服务器
            server_name 47.9.15.123;
     
            location / {
                    root   /data/platform/test-platform/docs/dist;
                    index  index.html index.htm index.jsp;
            }
    }

     

 

三、版本发布

jenkins -》视图 -》测试平台 -》

  1. test-platform-frontend:前端项目代码构建
    源码管理 https://git.xxx.com/apitest/test-platform.git
    分支:master
    构建 shell:
    cd UiProject && yarn install && yarn build:prod && sudo cp -r dist/* /data/platform/test-platform/frontend/dist/ && sudo /usr/sbin/nginx -s reload
    构建后操作
      test-platform-backend
  2. test-platform-backend:后端服务构建
    源码管理 https://git.xxx.com/apitest/test-platform.git
    分支:master
    构建
    shell:
    sudo git pull && sudo supervisorctl status && sudo supervisorctl restart test-platform-backend
  3. test-platform-docs:在线文档构建
    源码管理 https://git.xxx.com/apitest/test-platform.git
    分支:master
    构建
    shell:
    cd PlatPress && yarn install && yarn docs:build && sudo cp -r docs/.vuepress/dist/* /data/platform/test-platform/docs/dist/test-platform-report:平台测试执行报告构建 – allure参数
  4. allure_results
    默认值:/data/Docker-test/jenkins/workspace/test-platform-report/allure-results
    描述:Jenkins工作目录下,测试结果源文件(json、attach),用于生成allure报告
    xml_report_path
    默认值:空
    描述:测试目录下,测试生成的xml结果文件路径(json、attach),用于生成allure报告,需输入
    构建触发器
    触发远程构建 (例如,使用脚本),配置 身份验证令牌
    构建
    执行shell
    rm -rf ${allure_results}/*; cp -r ${xml_report_path}/* ${allure_results}

    构建后操作

    Allure Report

 

 

 

 

-------- THE END --------

posted @ 2021-11-28 16:47  徒手沉浮  阅读(1046)  评论(0编辑  收藏  举报