This commit is contained in:
w-mj 2023-03-13 20:48:27 +08:00
parent d0e8846e24
commit c7c657fe39
No known key found for this signature in database
GPG Key ID: 3A2CB5BE2F835897
6 changed files with 33 additions and 22 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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
```

View File

@ -21,6 +21,8 @@ spec:
ports:
- containerPort: 8080
env:
- name: GIN_MODE
value: release
- name: URL_PREFIX
value: admin
- name: DB_HOST

22
main.go
View File

@ -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))

View File

@ -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,