This commit is contained in:
WJQSERVER 2024-11-03 07:13:54 +08:00
parent 1eed79463d
commit 3c162bf9d7
6 changed files with 89 additions and 15 deletions

View file

@ -21,31 +21,34 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Load VERSION - name: 加载版本号
run: | run: |
if [ -f DEV-VERSION ]; then if [ -f DEV-VERSION ]; then
echo "VERSION=$(cat DEV-VERSION)" >> $GITHUB_ENV echo "VERSION=$(cat DEV-VERSION)" >> $GITHUB_ENV
else else
echo "DEV-VERSION file not found!" && exit 1 echo "DEV-VERSION file not found!" && exit 1
fi fi
- name: Set up Go - name: 安装 Go
uses: actions/setup-go@v3 uses: actions/setup-go@v3
with: with:
go-version: ${{ env.GO_VERSION }} go-version: ${{ env.GO_VERSION }}
- name: Install UPX - name: 安装UPX
run: | run: |
sudo apt update sudo apt update
sudo apt install upx -y sudo apt install upx -y
- name: Build - name: 编译
env: env:
GOOS: ${{ matrix.goos }} GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }} GOARCH: ${{ matrix.goarch }}
run: | run: |
CGO_ENABLED=0 go build -o ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./main.go CGO_ENABLED=0 go build -ldflags "-X main.version=${{ env.VERSION }}" -o ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./main.go
upx -9 ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} upx -9 ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}
- name: Package - name: 打包
run: | run: |
tar -czvf ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}.tar.gz ./${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} mkdir ghproxyd
cp ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./ghproxyd/
cp LICENSE ./ghproxyd/
tar -czf ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}.tar.gz -C ghproxyd .
- name: Upload to GitHub Artifacts - name: Upload to GitHub Artifacts
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:

View file

@ -63,6 +63,7 @@ jobs:
allowUpdates: true allowUpdates: true
env: env:
export PATH: $PATH:/usr/local/go/bin export PATH: $PATH:/usr/local/go/bin
docker: docker:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: build # 确保这个作业在 build 作业完成后运行 needs: build # 确保这个作业在 build 作业完成后运行
@ -102,3 +103,45 @@ jobs:
tags: | tags: |
${{ env.IMAGE_NAME }}:${{ env.VERSION }} ${{ env.IMAGE_NAME }}:${{ env.VERSION }}
${{ env.IMAGE_NAME }}:latest ${{ env.IMAGE_NAME }}:latest
docker-nocache:
runs-on: ubuntu-latest
needs: build # 确保这个作业在 build 作业完成后运行
env:
IMAGE_NAME: wjqserver/ghproxy # 定义镜像名称变量
DOCKERFILE: docker/dockerfile/nocache/Dockerfile # 定义 Dockerfile 路径变量
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Load VERSION
run: |
if [ -f VERSION ]; then
echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV
else
echo "VERSION file not found!" && exit 1
fi
- name: Wait for Compile
run: sleep 300s
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 构建镜像
uses: docker/build-push-action@v6
with:
file: ./${{ env.DOCKERFILE }}
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.IMAGE_NAME }}:${{ env.VERSION }}-nocache
${{ env.IMAGE_NAME }}:nocache

View file

@ -1,5 +1,12 @@
# 更新日志 # 更新日志
24w21b
---
- PRE-RELEASE: 此版本是v1.7.0的预发布版本,请勿在生产环境中使用
- ADD: 加入版本号标识与对应API接口
- ADD: 加入速率限制API接口
- CHANGE: 修改打包部分
24w21a 24w21a
--- ---
- PRE-RELEASE: 此版本是v1.7.0的预发布版本,请勿在生产环境中使用 - PRE-RELEASE: 此版本是v1.7.0的预发布版本,请勿在生产环境中使用

View file

@ -1 +1 @@
24w21a 24w21b

View file

@ -13,7 +13,6 @@ var (
cfg *config.Config cfg *config.Config
) )
// 日志模块
var ( var (
logw = logger.Logw logw = logger.Logw
logInfo = logger.LogInfo logInfo = logger.LogInfo
@ -21,8 +20,7 @@ var (
logError = logger.LogError logError = logger.LogError
) )
func InitHandleRouter(cfg *config.Config, router *gin.Engine) { func InitHandleRouter(cfg *config.Config, router *gin.Engine, version string) {
// 设置路由
apiRouter := router.Group("api") apiRouter := router.Group("api")
{ {
apiRouter.GET("/size_limit", func(c *gin.Context) { apiRouter.GET("/size_limit", func(c *gin.Context) {
@ -40,6 +38,12 @@ func InitHandleRouter(cfg *config.Config, router *gin.Engine) {
apiRouter.GET("/healthcheck", func(c *gin.Context) { apiRouter.GET("/healthcheck", func(c *gin.Context) {
HealthcheckHandler(c) HealthcheckHandler(c)
}) })
apiRouter.GET("/version", func(c *gin.Context) {
VersionHandler(c, version)
})
apiRouter.GET("/rate_limit/status", func(c *gin.Context) {
RateLimitStatusHandler(c, cfg)
})
} }
logInfo("API router Init success") logInfo("API router Init success")
} }
@ -84,3 +88,19 @@ func HealthcheckHandler(c *gin.Context) {
"Status": "OK", "Status": "OK",
}) })
} }
func VersionHandler(c *gin.Context, version string) {
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
c.Writer.Header().Set("Content-Type", "application/json")
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
"Version": version,
})
}
func RateLimitStatusHandler(c *gin.Context, cfg *config.Config) {
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
c.Writer.Header().Set("Content-Type", "application/json")
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
"RateLimit": cfg.RateLimit.Enabled,
})
}

View file

@ -23,6 +23,7 @@ var (
configfile = "/data/ghproxy/config/config.toml" configfile = "/data/ghproxy/config/config.toml"
cfgfile string cfgfile string
limiter *rate.RateLimiter limiter *rate.RateLimiter
version string
) )
var ( var (
@ -61,8 +62,8 @@ func loadlist(cfg *config.Config) {
auth.Init(cfg) auth.Init(cfg)
} }
func setupApi(cfg *config.Config, router *gin.Engine) { func setupApi(cfg *config.Config, router *gin.Engine, version string) {
api.InitHandleRouter(cfg, router) api.InitHandleRouter(cfg, router, version)
} }
func setupRateLimit(cfg *config.Config) { func setupRateLimit(cfg *config.Config) {
@ -85,7 +86,7 @@ func init() {
router = gin.Default() router = gin.Default()
router.UseH2C = true router.UseH2C = true
setupApi(cfg, router) setupApi(cfg, router, version)
if cfg.Pages.Enabled { if cfg.Pages.Enabled {
indexPagePath := fmt.Sprintf("%s/index.html", cfg.Pages.StaticDir) indexPagePath := fmt.Sprintf("%s/index.html", cfg.Pages.StaticDir)