From b69bc8746880e1ae70c0e4aedbb139343c5cb35e Mon Sep 17 00:00:00 2001 From: linwenxiang <991154416@qq.com> Date: Thu, 8 Apr 2021 21:33:36 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E2=9C=A8=20=E9=AA=8C=E8=AF=81=E7=A0=81s?= =?UTF-8?q?tore=E6=94=AF=E6=8C=81go-admin=20cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev-lwx.yml | 60 +++++++++++++++++++++++++++++++ cmd/api/server.go | 5 ++- common/middleware/handler/auth.go | 11 ++---- go.mod | 3 +- scripts/Dockerfile | 6 ++++ scripts/k8s/deploy.yml | 2 +- 6 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/dev-lwx.yml create mode 100644 scripts/Dockerfile diff --git a/.github/workflows/dev-lwx.yml b/.github/workflows/dev-lwx.yml new file mode 100644 index 00000000..b62a4c6b --- /dev/null +++ b/.github/workflows/dev-lwx.yml @@ -0,0 +1,60 @@ +name: build + +on: + push: + branches: [ dev-lwx ] + pull_request: + branches: [ dev-lwx ] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.15 + uses: actions/setup-go@v1 + with: + go-version: 1.15 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: Get dependencies + run: | + go get -v -t -d ./... + if [ -f Gopkg.toml ]; then + curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh + dep ensure + fi + - name: Build + run: | + CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -a -installsuffix cgo -o go-admin . + mv go-admin ./scripts + + - uses: Azure/docker-login@v1 + with: + login-server: registry.cn-shanghai.aliyuncs.com + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + - run: | + docker build ./scripts -t registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin:${{ github.sha }} + docker push registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin:${{ github.sha }} + - uses: Azure/k8s-set-context@v1 + with: + kubeconfig: ${{ secrets.KUBE_CONFIG }} + + - uses: Azure/k8s-create-secret@v1 + with: + namespace: 'go-admin' + container-registry-url: registry.cn-shanghai.aliyuncs.com + container-registry-username: ${{ secrets.REGISTRY_USERNAME }} + container-registry-password: ${{ secrets.REGISTRY_PASSWORD }} + secret-name: aliyuncs-k8s-secret + + - uses: Azure/k8s-deploy@v1 + with: + namespace: 'go-admin' + manifests: 'scripts/k8s/deploy.yml' + images: 'registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin:${{ github.sha }}' + imagepullsecrets: 'aliyuncs-k8s-secret' + kubectl-version: 'latest' diff --git a/cmd/api/server.go b/cmd/api/server.go index 7e382cb8..7d315633 100644 --- a/cmd/api/server.go +++ b/cmd/api/server.go @@ -3,8 +3,6 @@ package api import ( "context" "fmt" - "github.com/go-admin-team/go-admin-core/tools/captcha" - "go-admin/common/middleware/handler" "log" "net/http" "os" @@ -16,6 +14,7 @@ import ( "github.com/go-admin-team/go-admin-core/sdk" "github.com/go-admin-team/go-admin-core/sdk/config" "github.com/go-admin-team/go-admin-core/sdk/pkg" + "github.com/go-admin-team/go-admin-core/sdk/pkg/captcha" "github.com/go-admin-team/go-admin-core/sdk/pkg/logger" "github.com/spf13/cobra" @@ -74,7 +73,7 @@ func setup() { } sdk.Runtime.SetCacheAdapter(cacheAdapter) //5. 设置验证码store - handler.SetStore(captcha.NewCacheStore(cacheAdapter, 600)) + captcha.SetStore(captcha.NewCacheStore(cacheAdapter, 600)) usageStr := `starting api server...` log.Println(usageStr) diff --git a/common/middleware/handler/auth.go b/common/middleware/handler/auth.go index 392d227d..550b0725 100644 --- a/common/middleware/handler/auth.go +++ b/common/middleware/handler/auth.go @@ -8,23 +8,16 @@ import ( "github.com/go-admin-team/go-admin-core/sdk/api" "github.com/go-admin-team/go-admin-core/sdk/config" "github.com/go-admin-team/go-admin-core/sdk/pkg" + "github.com/go-admin-team/go-admin-core/sdk/pkg/captcha" jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth" "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user" "github.com/go-admin-team/go-admin-core/sdk/pkg/response" - "github.com/mojocn/base64Captcha" "github.com/mssola/user_agent" "go-admin/app/admin/models/system" "go-admin/common/global" ) -var store = base64Captcha.DefaultMemStore - -// SetStore 设置store -func SetStore(s base64Captcha.Store) { - store = s -} - func PayloadFunc(data interface{}) jwt.MapClaims { if v, ok := data.(map[string]interface{}); ok { u, _ := v["user"].(SysUser) @@ -90,7 +83,7 @@ func Authenticator(c *gin.Context) (interface{}, error) { return nil, jwt.ErrMissingLoginValues } if config.ApplicationConfig.Mode != "dev" { - if !store.Verify(loginVals.UUID, loginVals.Code, true) { + if !captcha.Verify(loginVals.UUID, loginVals.Code, true) { username = loginVals.Username msg = "验证码错误" status = "1" diff --git a/go.mod b/go.mod index a766e1e5..e673edad 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,8 @@ require ( github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5 github.com/casbin/casbin/v2 v2.25.1 github.com/gin-gonic/gin v1.6.3 - github.com/go-admin-team/go-admin-core v1.3.0-rc.0.0.20210407093008-7e27bec63f3e + github.com/go-admin-team/go-admin-core v1.3.4 github.com/google/uuid v1.2.0 - github.com/mojocn/base64Captcha v1.3.1 github.com/mssola/user_agent v0.5.2 github.com/opentracing/opentracing-go v1.1.0 github.com/prometheus/client_golang v1.1.0 diff --git a/scripts/Dockerfile b/scripts/Dockerfile new file mode 100644 index 00000000..01bdeb84 --- /dev/null +++ b/scripts/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine + +COPY ./go-admin / +EXPOSE 8000 + +CMD ["/go-admin","server","-c", "/config/settings.yml"] diff --git a/scripts/k8s/deploy.yml b/scripts/k8s/deploy.yml index 88d12534..44792278 100644 --- a/scripts/k8s/deploy.yml +++ b/scripts/k8s/deploy.yml @@ -35,7 +35,7 @@ spec: spec: containers: - name: go-admin - image: ${IMAGE} + image: registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin imagePullPolicy: IfNotPresent ports: - containerPort: 8000