Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roland #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"

[build]
# Array of commands to run before each build
#pre_cmd = ["echo 'hello air' > pre_cmd.txt"]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./tmp/main ."
# Array of commands to run after ^C
#post_cmd = ["echo 'hello air' > post_cmd.txt"]
# Binary file yields from `cmd`.
bin = "tmp/main"
# Customize binary, can setup environment variables when run your app.
full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html", "conf", "yaml", "tmp"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules",".git"]
# Watch these directories if you specified.
include_dir = ["conf","controllers","formvalidate","global","initialize","middleware","models","routers","services","static","tests","utils","views"]
# Watch these files.
include_file = ["config.yaml","main.go","app.conf"]
# Exclude files.
#exclude_file = []
# Exclude specific regular expressions.
#exclude_regex = ["_test\\.go"]
# Exclude unchanged files.
exclude_unchanged = true
# Follow symlink for directories
follow_symlink = true
# This log file places in your tmp_dir.
log = "air.log"
# Poll files for changes instead of using fsnotify.
poll = false
# Poll interval (defaults to the minimum interval of 500ms).
poll_interval = 500 # ms
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 0 # ms
# Stop running old binary when build errors occur.
stop_on_error = true
# Send Interrupt signal before killing process (windows does not support this feature)
send_interrupt = false
# Delay after sending Interrupt signal
kill_delay = 500 # nanosecond
# Rerun binary or not
rerun = false
# Delay after each executions
rerun_delay = 500
# Add additional arguments when running binary (bin/full_bin). Will run './tmp/main hello world'.
#args_bin = ["hello", "world"]

[log]
# Show log time
time = false
# Only show main log (silences watcher, build, runner)
main_only = false

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = true

[screen]
clear_on_rebuild = true
keep_scroll = true
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM docker.io/centos

MAINTAINER AUTHOR'S LUODI FROM RODDYPY.COM QQ:923401910

WORKDIR /usr/local/src/

COPY pcre-8.37.tar.gz .
COPY nginx-1.8.0.tar.gz .

#add user www
RUN useradd -s /sbin/nologin www && yum install gcc gcc-c++ openssl openssl-devel -y

RUN tar zxf pcre-8.37.tar.gz && cd pcre-8.37 && ./configure --prefix=/usr/local/pcre && make && make install

RUN tar zxf nginx-1.8.0.tar.gz && cd nginx-1.8.0 && ./configure --prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-file-aio \
--with-http_dav_module \
--with-pcre=/usr/local/src/pcre-8.37 && make && make install && chown -R www. /usr/local/nginx

COPY nginx.conf /usr/local/nginx/conf/nginx.conf
ADD vhosts /usr/local/nginx/conf/vhosts
ADD run.sh /root/run.sh
RUN chmod 755 /root/run.sh

CMD ["/root/run.sh"]

EXPOSE 80 443
89 changes: 89 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
pipeline {
agent any

tools {
go 'Go1.21.5'
}
stages {
stage('[checkout]拉取代码中....') {
steps {
// 使用 checkout 步骤拉取代码
checkout([$class: 'GitSCM', branches: [[name: '*/main']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'b4c9eb45-0344-409f-849a-2cdd091749ee', url: 'http://113.250.161.105:8180/geeker_yuyu/beego-admin.git']],destination: 'beego-admin'])
echo '拉取代码成功'
}
}
stage('[build]构建中....') {
steps {
// 构建 Golang 项目
script {
// 使用 Golang 工具
def gopath = tool 'Go1.21.5'
env.GOPATH = "${WORKSPACE}/gopath"
env.PATH = "${gopath}/bin:${env.PATH}"

// 构建命令
sh 'go build -o beego-admin .'

echo '构建完成'
}
}
}
stage('[test]发送软件到测试服务器....') {
steps {
script {
// 测试阶段的构建命令和其他操作

// 使用 SSH 将生成的可执行文件和 Dockerfile 发送到测试服务器
sshPublisher(
failOnError: true,
publishers: [
sshPublisherDesc(
configName: 'b4c9eb45-0344-409f-849a-2cdd091749ee', // 替换为你的 SSH 凭据的 ID
transfers: [
sshTransfer(
sourceFiles: 'beego-admin ./Dockerfile', // 本地构建好的二进制文件和 Dockerfile 路径
removePrefix: '',
remoteDirectory: '/opt/deployment' // 远程测试服务器的目录
)
]
)
]
)

echo '发送软件到测试服务器'
}
}
}
stage('[deploy]部署中....') {
steps {
script {
def remote = [:]
remote.name = 'gitlab-jenkins-beego-admin' // 服务器名字,提前配置好的
remote.host = '113.250.161.105' // 远程ip,待部署的服务器ip
remote.port = 22
remote.allowAnyHosts = true

withCredentials([usernamePassword(credentialsId: 'db4cb5f7-08fb-465a-baee-3a868f9d69e2', passwordVariable: 'Password', usernameVariable: 'Username')]) {
remote.user = "${Username}"
remote.password = "${Password}"
}

writeFile file: 'abc.sh', text: 'docker stop demo;docker container rm demo;docker rmi demo;chmod +x /opt/deployment/beego-admin;cd /opt/deployment;docker build -t demo .;docker run --name demo -d -p 7654:7654 demo'
sshScript remote: remote, script: 'abc.sh'
}

}
}
}

post {
success {
// 构建成功时执行的操作
echo 'Build and deployment successful!'
}
failure {
// 构建失败时执行的操作
echo 'Build or deployment failed!'
}
}
}
6 changes: 3 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
redis:
db: 0
addr: '127.0.0.1:6379'
password: ''
password: '123456'

# mysql connect configuration
mysql:
host: '127.0.0.1'
port: 3306
database: 'beego-admin'
database: 'beego_admin'
username: 'root'
password: 'root'
password: '123456'

# other configuration
other:
Expand Down
29 changes: 12 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,35 @@ module beego-admin

go 1.15

require github.com/astaxie/beego v1.12.1

require (
github.com/360EntSecGroup-Skylar/excelize v1.4.1
github.com/adam-hanna/arrayOperations v0.2.6
github.com/beego/bee/v2 v2.0.2 // indirect
github.com/beego/beego/v2 v2.0.2-0.20210205153711-4861b1f69239
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dchest/captcha v0.0.0-20200903113550-03f5f0333e1f
github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3 // indirect
github.com/fsnotify/fsnotify v1.4.9
github.com/go-delve/delve v1.6.0 // indirect
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.1.2
github.com/gookit/validate v1.2.4
github.com/gookit/goutil v0.6.14 // indirect
github.com/gookit/validate v1.5.1
github.com/lib/pq v1.9.0 // indirect
github.com/magiconair/properties v1.8.4 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-runewidth v0.0.10 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/peterh/liner v1.2.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
github.com/sirupsen/logrus v1.7.0 // indirect
github.com/smartystreets/goconvey v1.6.4
github.com/spf13/afero v1.5.1 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.1
go.starlark.net v0.0.0-20210126161401-bc864be25151 // indirect
golang.org/x/arch v0.0.0-20210127225635-455c95562d18 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
golang.org/x/text v0.3.5 // indirect
gopkg.in/ini.v1 v1.62.0
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
4 changes: 2 additions & 2 deletions initialize/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"os"
)

//加载配置文件
func init() {
// 加载配置文件
func InitConfig() {
var config string
if configEnv := os.Getenv(utils.ConfigEnv); configEnv == "" {
config = utils.ConfigFile
Expand Down
2 changes: 1 addition & 1 deletion initialize/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// init 注册mysql
func init() {
func InitDb() {
err := orm.RegisterDriver("mysql", orm.DRMySQL)
if err != nil {
beego.Error("mysql register driver error:", err)
Expand Down
2 changes: 1 addition & 1 deletion initialize/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package session

import beego "github.com/beego/beego/v2/adapter"

func init() {
func InitSession() {
//session 过期时间,默认值是 3600 秒
beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 7200

Expand Down
21 changes: 15 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package main

import (
_ "beego-admin/initialize/conf"
_ "beego-admin/initialize/mysql"
_ "beego-admin/initialize/session"
_ "beego-admin/routers"
_ "beego-admin/utils/template"
"beego-admin/initialize/conf"
"beego-admin/initialize/mysql"
"beego-admin/initialize/session"
"beego-admin/routers"
"beego-admin/utils/template"
beego "github.com/beego/beego/v2/adapter"
)

func main() {

//初始化配置文件
conf.InitConfig()
//初始化数据库
mysql.InitDb()
//初始化session
session.InitSession()
//初始化router
routers.InitRouter()
//初始化自定义模版
template.InitTtempate()
//输出文件名和行号
beego.SetLogFuncCall(true)

Expand Down
2 changes: 1 addition & 1 deletion routers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http"
)

func init() {
func InitRouter() {
//授权登录中间件
middleware.AuthMiddle()

Expand Down
4 changes: 2 additions & 2 deletions utils/template/template.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Package template 自定义模板函数
// Package template 自定义模板函数
package template

import (
Expand All @@ -8,7 +8,7 @@ import (
"time"
)

func init() {
func InitTtempate() {
beego.AddFuncMap("UnixTimeForFormat", UnixTimeForFormat)
beego.AddFuncMap("FormatSize", FormatSize)
}
Expand Down