自動化測試平台開發(二):項目基礎結構搭建 - 前后端分離


本平台涉及后端服務、數據管理、前端交互,所以需要搭建兩個項目:前端、后端,並且實現前后端分離。

  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 --------


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM