Jenkins自動化部署項目

一. Jenkins自動化部署django項目

  1. 用到的技術棧

    Jenkins + supervisor + nginx + django + gunicornhtml

  2. gunicorn的使用

- 使用gunicorn啓動django項目
    gunicorn -w 3 -b 0.0.0.0:8001 projectdir.wsgi:application

  

  3. supervisor的使用 

- 啓動supervisor服務端
    python /usr/local/bin/supervisord    # 使用默認配置啓動
    python /usr/local/bin/supervisird -c ./xxx.conf    # 使用定製配置啓動 

- supervisor項目的配置

[program:projectname]
command=/usr/local/bin/gunicorn -w 3 -b 0.0.0.0:7000 projectdir.wsgi:application
directory=/home/projectdir/
autostart=true
autorestart=true

- supervisor的幾個經常使用指令
    supervisorctl start    # 開啓配置項目
    supervisorctl restart/reload    # 重啓
    supervisorctl update    # 啓動新項目,重啓修改的項目

  4. nginx的配置

- 普通的配置
    server {
            listen   80;
            server_name  192.168.1.95;	# nginx對外地址

            location / {
                proxy_pass http://0.0.0.0:8001;	# 代理地址
            }

            location /static/ {
                 alias /opt/yl/apps/static/;	# 靜態文件
            }
        }

- vue的配置
        server {
                listen       8003;
                server_name  192.168.1.95;
                location / {
                    root /opt/vue_project/dist;
                    index index.html;
                }
            }

  

  

  5. Jenkins的簡單使用

- Jenkins配置
    Repository URL(github/gitee遠程倉庫地址)
    Credentials(帳號密碼)
    構建觸發器(gitee插件, gitee webhook)
    構建shell(重啓supervisor + nginx)
    構建後(發送郵件等)

- 構建時部署django項目的shell
    sudo supervisorctl update
    sudo /etc/init.d/nginx reload

- 構建時部署vue項目的shell
  sudo npm install          # 下載工做區的npm包
  sudo rm -rf ./dist/*       # 刪除以前的, 從新進行打包
  sudo npm run build        # 進行打包
  sudo rm -rf /www/web/site/*  # 刪除服務器上以前存放dist文件
  sudo cp -rf ./dist/* /www/web/site  # 拷貝新的dist文件到項目
相關文章
相關標籤/搜索