diff --git a/.github/workflows/build-dev.yml b/.github/workflows/build-dev.yml index df601a4..53c78dc 100644 --- a/.github/workflows/build-dev.yml +++ b/.github/workflows/build-dev.yml @@ -21,31 +21,34 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Load VERSION + - name: 加载版本号 run: | if [ -f DEV-VERSION ]; then echo "VERSION=$(cat DEV-VERSION)" >> $GITHUB_ENV else echo "DEV-VERSION file not found!" && exit 1 fi - - name: Set up Go + - name: 安装 Go uses: actions/setup-go@v3 with: go-version: ${{ env.GO_VERSION }} - - name: Install UPX + - name: 安装UPX run: | sudo apt update sudo apt install upx -y - - name: Build + - name: 编译 env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} 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}} - - name: Package + - name: 打包 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 uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a342b5a..2b23b64 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -62,7 +62,8 @@ jobs: tag: ${{ env.VERSION }} allowUpdates: true env: - export PATH: $PATH:/usr/local/go/bin + export PATH: $PATH:/usr/local/go/bin + docker: runs-on: ubuntu-latest needs: build # 确保这个作业在 build 作业完成后运行 @@ -102,3 +103,45 @@ jobs: tags: | ${{ env.IMAGE_NAME }}:${{ env.VERSION }} ${{ 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 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index d3812f2..119e680 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # 更新日志 +24w21b +--- +- PRE-RELEASE: 此版本是v1.7.0的预发布版本,请勿在生产环境中使用 +- ADD: 加入版本号标识与对应API接口 +- ADD: 加入速率限制API接口 +- CHANGE: 修改打包部分 + 24w21a --- - PRE-RELEASE: 此版本是v1.7.0的预发布版本,请勿在生产环境中使用 diff --git a/DEV-VERSION b/DEV-VERSION index b9b04a9..b902b37 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -24w21a \ No newline at end of file +24w21b \ No newline at end of file diff --git a/api/api.go b/api/api.go index 42f11ae..47d2992 100644 --- a/api/api.go +++ b/api/api.go @@ -13,7 +13,6 @@ var ( cfg *config.Config ) -// 日志模块 var ( logw = logger.Logw logInfo = logger.LogInfo @@ -21,8 +20,7 @@ var ( 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.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) { 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") } @@ -84,3 +88,19 @@ func HealthcheckHandler(c *gin.Context) { "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, + }) +} diff --git a/main.go b/main.go index 98f7391..3671b72 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ var ( configfile = "/data/ghproxy/config/config.toml" cfgfile string limiter *rate.RateLimiter + version string ) var ( @@ -61,8 +62,8 @@ func loadlist(cfg *config.Config) { auth.Init(cfg) } -func setupApi(cfg *config.Config, router *gin.Engine) { - api.InitHandleRouter(cfg, router) +func setupApi(cfg *config.Config, router *gin.Engine, version string) { + api.InitHandleRouter(cfg, router, version) } func setupRateLimit(cfg *config.Config) { @@ -85,7 +86,7 @@ func init() { router = gin.Default() router.UseH2C = true - setupApi(cfg, router) + setupApi(cfg, router, version) if cfg.Pages.Enabled { indexPagePath := fmt.Sprintf("%s/index.html", cfg.Pages.StaticDir)