基于Gokins自动化部署

[toc]

写在前面

最近在公司学习到一个新玩意-Gokins基于Golang开发的自动化构建工具, 在此之前我是使用有使用过Jenkins进行项目自动化部署,Gokins相比于Jenkins功能非常简单,使用起来也非常方便,下面本文将以Gokins完成项目后端的部署。

Gokins的安装

方法一

直接服务器服务器下载Gokins(以ubuntu为例),使用以下命令:

wget http://down.gokins.cn/static/golang/gokins/gokins

下载完成后可能需要更改权限:

chmod 777 gokins

运行Gokins:

./gokins &

直接访问:

http://your:8030/

方法二

使用docker安装,首先您的服务器上有安装docker, 然后直接使用命令:

docker pull mgr9525/gokins:latest

运行容器:

docker run -d -p 8030:8030 mgr9525/gokins:latest

直接访问:

http://your:8030/

如何使用

关于Gokins官方文档写得更好这里不做介绍了,参考Gokins官方文档

部署项目

登录Gokins后,新建流水线,填写项目名称,项目描述,项目托管仓库(github,gitlab,gitee等)

注意:如果是项目不公开或者不是仓库目录模式下,需要填写仓库拥有者的账号并且需要填写Access Token。

注意:这里有一个小问题,项目拉取不下来,没有权限的原因,但是我填写了相关的数据,所以这里我先将项目从远程仓库clone到了我的服务器。

接下来填写yaml文件:

version: 1.0
vars:
stages:
  - stage:
    displayName: build
    name: build
    steps:
      - step: shell@bash
        displayName: bash
        repo: /home/ubuntu/gokins/web
        name: bash
        commands:
          - git pull
          - nohup go run main.go > web-go.log

这里您可能需要修改repo: /home/ubuntu/gokins/web指你项目在服务器上位置

将日志写入到日志文件中nohup go run main.go > web-go.log,保存yaml后,直接点击构建,即可完成项目的部署,构建输出:

git pull                                                         00:02
1                                             2023-06-21 16:25:43
Already up to date.
nohup go run main.go > web-go.log    00:00
1

我们还可以在服务器上查看日志文件web-go.log

[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /v1/pong                  --> main.Pong (3 handlers)
[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
[GIN-debug] Listening and serving HTTP on :8093

这样整个项目就构建完成了。

本作品采用《CC 协议》,转载必须注明作者和本文链接
刻意学习
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
118
粉丝
89
喜欢
173
收藏
246
排名:365
访问:2.6 万
私信
所有博文
社区赞助商