学习笔记:从git仓库拉取更新并部署到服务端

最近租了个云主机,在上面部署网站,为了节省资源(穷),采取云主机 + github + 手动触发方式部署 ,记录下过程

  • 1、创建git仓库
    进入github,创建一个新仓库,姑且叫Arepo

  • 2、在云主机编写自动部署脚本

#!/bin/bash
# -*- coding:utf-8 -*-

import os

def func_shell(cmdstr):
    if ( os.system(cmdstr) != 0):
        print ("Error " + cmdstr)

git_dir = "xxxx/Arepo"
site_dir = "xxxx/Asite"

if not os.path.exists(git_dir):
	#--depth 深度为1
    cmdstr = "git clone -b 分支名字 --depth 1  https://github.com/xxx/Arepo.git"
    func_shell(cmdstr)
else:
	#拉取更新
    cmdstr = "cd {}".format(git_dir)
    cmdstr += "&& git pull"
    func_shell(cmdstr)

#复制内容到网站文件夹
cmdstr = "&& cp -R {} {}".format(git_dir, site_dir)
func_shell(cmdstr)
  • 3、执行脚本,重启apache或其他服务

脚本较简单,其实可以细化,例如不用全部文件都复制到网站文件夹,只检测更新,然后将有变化的文件复制到网站文件夹

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值