diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 627e43f..40f04b6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ build: - image: docker:23.0.1-dind + image: docker.educg.net/container-mirrors/docker:23.0.1-dind stage: build tags: - dind-runner @@ -12,7 +12,7 @@ build: deploy: image: - name: bitnami/kubectl:1.26.2 + name: docker.educg.net/container-mirrors/bitnami/kubectl:1.26.2 entrypoint: [""] stage: deploy only: diff --git a/Makefile b/Makefile index 7ecf641..a2b2abb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -TAG ?= v1.1.10 +TAG ?= v1.1.11 IMAGE_TAG ?= docker.educg.net/cg/k8s-manager:$(TAG) build: export CGO_ENABLED=0 @@ -11,14 +11,14 @@ docker: docker build --rm -t $(IMAGE_TAG) . install: docker - kubectl apply -f install.yaml + sed 's/DOCKER_TAG_NAME/$(TAG)/' install.yaml | kubectl apply -f - uninstall: - kubectl delete -f install.yaml + sed 's/DOCKER_TAG_NAME/$(TAG)/' install.yaml | kubectl delete -f - restart: docker - kubectl delete -f install.yaml - kubectl apply -f install.yaml + sed 's/DOCKER_TAG_NAME/$(TAG)/' install.yaml | kubectl delete -f - + sed 's/DOCKER_TAG_NAME/$(TAG)/' install.yaml | kubectl apply -f - push: docker docker push $(IMAGE_TAG) diff --git a/README.md b/README.md index e0876dd..113fd1e 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,4 @@ type: kubernetes.io/service-account-token EOF kubectl get secret dev-secret -o yaml -``` - -## 安装Traefik -```bash -helm repo add traefik https://traefik.github.io/charts -helm repo update -helm install -f traefik-conf.yaml traefik traefik/traefik -helm uninstall traefik -helm install traefik traefik/traefik --set expose.dashboard=true ``` \ No newline at end of file diff --git a/install.yaml b/install.yaml index e58c84b..9017ebb 100644 --- a/install.yaml +++ b/install.yaml @@ -21,6 +21,8 @@ spec: ports: - containerPort: 8080 env: + - name: GIN_MODE + value: release - name: URL_PREFIX value: admin - name: DB_HOST diff --git a/main.go b/main.go index 57f1bfd..ca01d50 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,6 @@ import ( "encoding/base64" "errors" "fmt" - "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" "github.com/golang-jwt/jwt/v4" log "github.com/sirupsen/logrus" @@ -21,12 +20,31 @@ import ( //go:embed template/* static/* var f embed.FS +func Cors() gin.HandlerFunc { + return func(c *gin.Context) { + method := c.Request.Method + origin := c.Request.Header.Get("Origin") + if origin != "" { + c.Header("Access-Control-Allow-Origin", "*") + c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") + c.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization") + c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type") + c.Header("Access-Control-Allow-Credentials", "true") + } + if method == "OPTIONS" { + c.AbortWithStatus(http.StatusNoContent) + } + c.Next() + } +} + func main() { m.InitConfig() m.InitClient() r := gin.Default() - r.Use(cors.Default()) + // r.Use(cors.Default()) + r.Use(Cors()) fp, _ := fs.Sub(f, "static") r.StaticFS("/static", http.FS(fp)) diff --git a/src/jwt_utils.go b/src/jwt_utils.go index 86e175b..e1ce139 100644 --- a/src/jwt_utils.go +++ b/src/jwt_utils.go @@ -52,10 +52,10 @@ func JWTAuthMiddleware(c *gin.Context) { authHeader = "" } } - if authHeader == "debug_special_key:83bsiablwtxv13" { - c.Set("username", "cg_wmj") - return - } + //if authHeader == "debug_special_key:83bsiablwtxv13" { + // c.Set("username", "cg_wmj") + // return + //} if authHeader == "" { c.JSON(http.StatusUnauthorized, gin.H{ "code": http.StatusUnauthorized,