From 69d4d53a5161960a747a8a8d5d7072e346c810ab Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Fri, 11 Oct 2024 10:25:33 +0800 Subject: [PATCH] 24w15a --- .github/workflows/build-dev.yml | 32 +++++++++++++------ DEV-VERSION | 2 +- config/config.go | 54 +++++++++++++++++++++++++++++--- config/config.toml | 23 ++++++++++++++ docker/dockerfile/dev/Dockerfile | 2 +- docker/dockerfile/dev/init.sh | 2 +- go.mod | 1 + go.sum | 2 ++ 8 files changed, 102 insertions(+), 16 deletions(-) create mode 100644 config/config.toml diff --git a/.github/workflows/build-dev.yml b/.github/workflows/build-dev.yml index 402fb8e..169c187 100644 --- a/.github/workflows/build-dev.yml +++ b/.github/workflows/build-dev.yml @@ -70,6 +70,7 @@ jobs: needs: build env: IMAGE_NAME: wjqserver/ghproxy + PROG_NAME: ghproxy DOCKERFILE: docker/dockerfile/dev/Dockerfile steps: @@ -95,12 +96,25 @@ jobs: 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 }} - ${{ env.IMAGE_NAME }}:dev + - name: Build Docker image + run: | + docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.PROG_NAME }}:dev,${{ env.PROG_NAME }}:${{ env.VERSION }} -f ./${{ env.DOCKERFILE }} + + - name: Install Slim + run: | + curl -L -o ds.tar.gz https://github.com/slimtoolkit/slim/releases/download/1.40.11/dist_linux.tar.gz + tar -xvf ds.tar.gz + mv dist_linux/slim /usr/local/bin/ + mv dist_linux/slim-sensor /usr/local/bin/ + rm -rf ds.tar.gz dist_linux + + - name: Optimize Docker image using Slim + run: | + slimlim build --include-path /data --http-probe --continue-after 20 --tag ${{ env.PROG_NAME }}:${{ env.VERSION }} ${{ env.PROG_NAME }}:dev + + - name: Push Docker image + run: | + docker tag ${{ env.PROG_NAME }}:${{ env.VERSION }} ${{ env.IMAGE_NAME }}:${{ env.VERSION }} + docker tag ${{ env.PROG_NAME }}:dev ${{ env.IMAGE_NAME }}:dev + docker push ${{ env.IMAGE_NAME }}:${{ env.VERSION }} + docker push ${{ env.IMAGE_NAME }}:dev diff --git a/DEV-VERSION b/DEV-VERSION index efb7733..8684a7d 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -24w14a +24w15a \ No newline at end of file diff --git a/config/config.go b/config/config.go index 2acfc51..04928d5 100644 --- a/config/config.go +++ b/config/config.go @@ -1,12 +1,10 @@ package config import ( - "os" - - "gopkg.in/yaml.v3" + "github.com/BurntSushi/toml" ) -type Config struct { +/*type Config struct { Server struct { Port int `yaml:"port"` Host string `yaml:"host"` @@ -54,4 +52,52 @@ func loadYAML(filePath string, out interface{}) error { return err } return yaml.Unmarshal(data, out) +}*/ + +type Config struct { + Server ServerConfig + Log LoggerConfig + CORS CORSConfig + Auth AuthConfig + Blacklist BlacklistConfig + Whitelist WhitelistConfig +} + +type ServerConfig struct { + Port int `toml:"port"` + Host string `toml:"host"` + SizeLimit int `toml:"sizelimit"` +} + +type LoggerConfig struct { + LogFilePath string `toml:"logfilepath"` + MaxLogSize int `toml:"maxlogsize"` +} + +type CORSConfig struct { + Enabled bool `toml:"enabled"` +} + +type AuthConfig struct { + Enabled bool `toml:"enabled"` + AuthToken string `toml:"authtoken"` +} + +type BlacklistConfig struct { + Enabled bool `toml:"enabled"` + BlacklistFile string `toml:"blacklistfile"` +} + +type WhitelistConfig struct { + Enabled bool `toml:"enabled"` + WhitelistFile string `toml:"whitelistfile"` +} + +// LoadConfig 从 TOML 配置文件加载配置 +func LoadConfig(filePath string) (*Config, error) { + var config Config + if _, err := toml.DecodeFile(filePath, &config); err != nil { + return nil, err + } + return &config, nil } diff --git a/config/config.toml b/config/config.toml new file mode 100644 index 0000000..9379db8 --- /dev/null +++ b/config/config.toml @@ -0,0 +1,23 @@ +[server] +host = "127.0.0.1" +port = 8080 +sizelimit = 131072000 # 125MB + +[logger] +logfilepath = "/data/ghproxy/log/ghproxy.log" +maxlogsize = 5 # MB + +[cors] +enabled = true + +[auth] +authtoken = "test" +enabled = false + +[blacklist] +blacklistfile = "/data/ghproxy/config/blacklist.json" +enabled = false + +[whitelist] +enabled = false +whitelistfile = "/data/ghproxy/config/whitelist.json" diff --git a/docker/dockerfile/dev/Dockerfile b/docker/dockerfile/dev/Dockerfile index cd15be6..ec9fac4 100644 --- a/docker/dockerfile/dev/Dockerfile +++ b/docker/dockerfile/dev/Dockerfile @@ -26,7 +26,7 @@ RUN wget -O /usr/local/bin/init.sh https://raw.githubusercontent.com/${USER}/${R # 拉取配置 RUN wget -O /data/caddy/Caddyfile https://raw.githubusercontent.com/${USER}/${REPO}/main/caddyfile/dev/Caddyfile -RUN wget -O /data/${APPLICATION}/config.yaml https://raw.githubusercontent.com/${USER}/${REPO}/main/config/config.yaml +RUN wget -O /data/${APPLICATION}/config.toml https://raw.githubusercontent.com/${USER}/${REPO}/main/config/config.toml RUN wget -O /data/${APPLICATION}/blacklist.json https://raw.githubusercontent.com/${USER}/${REPO}/main/config/blacklist.json RUN wget -O /data/${APPLICATION}/whitelist.json https://raw.githubusercontent.com/${USER}/${REPO}/main/config/whitelist.json diff --git a/docker/dockerfile/dev/init.sh b/docker/dockerfile/dev/init.sh index 78f8bc3..a8f1655 100644 --- a/docker/dockerfile/dev/init.sh +++ b/docker/dockerfile/dev/init.sh @@ -20,7 +20,7 @@ fi /data/caddy/caddy run --config /data/caddy/config/Caddyfile > /data/${APPLICATION}/log/caddy.log 2>&1 & -/data/${APPLICATION}/${APPLICATION} -cfg /data/${APPLICATION}/config/config.yaml > /data/${APPLICATION}/log/run.log 2>&1 & +/data/${APPLICATION}/${APPLICATION} -cfg /data/${APPLICATION}/config/config.toml > /data/${APPLICATION}/log/run.log 2>&1 & while true; do sleep 1 diff --git a/go.mod b/go.mod index bbfa29e..05ba622 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( ) require ( + github.com/BurntSushi/toml v1.4.0 // indirect github.com/andybalholm/brotli v1.1.0 // indirect github.com/bytedance/sonic v1.12.3 // indirect github.com/bytedance/sonic/loader v0.2.0 // indirect diff --git a/go.sum b/go.sum index f4753ff..a686c25 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= +github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=