zoukankan      html  css  js  c++  java
  • Django项目构建发布Harbor仓库

    前言:

    之前的Django项目直接部署到Docker容器中,简单高效;
    
    不过生产中还是要部署到K8S中,在此总结一下工作经历

    一、Harbor仓库

    创建harbor仓库项目

    传送门:Harbor单点仓库部署

    二、编写Dockefile

    Dockerfile文件

    FROM python:3.6
    WORKDIR /root
    COPY . /root/
    RUN pip install --default-timeout=100 -i https://pypi.tuna.tsinghua.edu.cn/simple -r /root/requirements.txt
    CMD uwsgi --ini /root/cops_uwsgi.ini

    requirements.txt文件

    requests
    django
    djangorestframework
    uwsgi
    mysqlclient
    ldap3
    redis
    boto

    uwsgi配置

    为什么要用uwsgi请自行百度

    [uwsgi]
    http=0.0.0.0:9001
    chdir=/root
    module = Project.wsgi
    vacuum=True
    master=True
    workers=8
    enable-threads=True
    threads=32
    memory-report=True

    构建脚本build.sh

    #!/bin/sh
    REV=`git rev-parse --short HEAD`
    docker build -t cloudops_test:$REV .
    
    docker tag cloudops_test:${REV} 10.60.128.219:888/cloudops/cloudops_test:${REV}
    docker push 10.60.128.219:888/cloudops/cloudops_test:${REV}

    三、发布代码到仓库

    3.1 拉取git仓库代码

    [root@10-60-128-219 harbor]# cd /data/web/xxx/
    [root@10-60-128-219 xxx]# git pull   #### 各位看官,请跟实际环境操作

    3.2 Harbor项目推送示例

    3.2 构建Django代码

    [root@10-60-128-219 opsservice]# cat build.sh 
    #!/bin/sh
    REV=`git rev-parse --short HEAD`
    docker build -t cloudops_test:$REV .
    
    
    docker tag cloudops_test:${REV} 10.60.128.219:888/cloudops/cloudops_test:${REV}
    docker push 10.60.128.219:888/cloudops/cloudops_test:${REV}
    [root@10-60-128-219 opsservice]# /bin/sh build.sh

    3.3 检测镜像

    [root@10-60-128-219 opsservice]# docker images|grep cloudops_test
    cloudops_test                              ffbaa25             8cd31496a16a        18 hours ago        987MB
    10.60.128.219:888/cloudops/cloudops_test   78b8ccc             ad7ef3db0a88        47 hours ago        987MB
    cloudops_test                              78b8ccc             ad7ef3db0a88        47 hours ago        987MB
    [root@10-60-128-219 opsservice]# 

    四、K8S拉取镜像创建pod

    传送门:K8S拉取Django项目创建pod

  • 相关阅读:
    JQuery Mobile
    JQuery
    JQuery Mobile
    JQuery Mobile
    JQuery Mobile
    5G && 物联网
    Sass(Syntactically Awesome Stylesheets)——概述(待续)
    Sass(Syntactically Awesome Stylesheets)——使用React JS实现
    Yarn概述——FAST, RELIABLE, AND SECURE DEPENDENCY MANAGEMENT
    webpack——Modules && Hot Module Replacement
  • 原文地址:https://www.cnblogs.com/supery007/p/12800347.html
Copyright © 2011-2022 走看看