Git Product home page Git Product logo

automatic-deployment's Introduction

AutoMaticDeployment---自动部署👇


项目简介 📒

基于GitHub提供的WebHooks勾子实现静态项目自动部署,流程如下:

  • 本地编码
  • 提交代码到GitHub,触发WebHooks
  • 请求url
  • 执行脚本,自动部署

技术栈 💻

  • Java
  • SpringBoot

使用说明 🔍

1、克隆代码到本地或者服务器,编辑src/main/resources下的application.properties文件,修改端口号,然后使用maven命令编译打包:

mvn clean install -Dmaven.test.skip=true

2、后台运行项目:

nohup java -jar AutomaticDeployment.jar > AutomaticDeployment.out 2>&1 &

3、访问http://{your_website}:{port}/hello,显示“hello”表示部署成功

4、配置触发WebHooks(以GitHub为例)。在项目的settings页面,点击左侧webhook选项,点击new新建webhooks,填写url,并在url拼接需要执行的shell脚本的位置: 图片

配置url:http://{your_website}:{port}/linux/exec?cmd={cmd}&secret={secret}

参数说明:其中cmd表示需要执行的shell脚本的位置:/root/xxx/update.sh:

echo "========== 开始执行home.sh脚本 =========="
echo "进入blog所在目录"
cd /usr/local/nginx/html/blog
## 拉取最新代码
echo "从github拉取最新代码"
git pull
## 重启nginx
echo "重启nginx"
../../sbin/nginx -s reload
## 打印提示语句
echo "========== 网站更新完成 =========="

secret表示自定义密码,这里需要和代码一致(默认:gongsir0630),以此验证用户身份,如需修改,请编辑src/main/java/club.gongsir.linux.controller.DemoController中exec方法的secret字符串: 图片

5、保存webhooks配置即可,这样当仓库的代码更新之后,就会自动发post请求以触发shell脚本的执行。

6、执行成功返回:
图片

TODO ✈️

  • 使用github的secret签名完成用户身份验证

联系我 👦

automatic-deployment's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.