mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
feat: dev docker
This commit is contained in:
parent
31520debb2
commit
5cf8b8024c
24
.github/workflows/release.yml
vendored
24
.github/workflows/release.yml
vendored
@ -4,6 +4,8 @@ on:
|
|||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- "v*"
|
- "v*"
|
||||||
|
branches:
|
||||||
|
- dev
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@ -33,7 +35,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Fetch IPInfo GeoIP Database
|
- name: Fetch IPInfo GeoIP Database
|
||||||
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
|
if: github.event_name == 'push'
|
||||||
env:
|
env:
|
||||||
IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
|
IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
@ -81,6 +83,7 @@ jobs:
|
|||||||
done
|
done
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
|
if: contains(github.ref, 'refs/tags/')
|
||||||
uses: ncipollo/release-action@v1
|
uses: ncipollo/release-action@v1
|
||||||
with:
|
with:
|
||||||
artifacts: "assets/*/*/*.zip"
|
artifacts: "assets/*/*/*.zip"
|
||||||
@ -99,6 +102,7 @@ jobs:
|
|||||||
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/config.yaml
|
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/config.yaml
|
||||||
|
|
||||||
- name: Trigger sync
|
- name: Trigger sync
|
||||||
|
if: contains(github.ref, 'refs/tags/')
|
||||||
env:
|
env:
|
||||||
GH_REPO: ${{ github.repository }}
|
GH_REPO: ${{ github.repository }}
|
||||||
GH_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ github.token }}
|
||||||
@ -108,7 +112,7 @@ jobs:
|
|||||||
|
|
||||||
release-docker:
|
release-docker:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
|
if: github.event_name == 'push'
|
||||||
needs: build
|
needs: build
|
||||||
name: Release Docker images
|
name: Release Docker images
|
||||||
steps:
|
steps:
|
||||||
@ -124,12 +128,26 @@ jobs:
|
|||||||
chmod -R +x ./assets/*
|
chmod -R +x ./assets/*
|
||||||
mkdir dist
|
mkdir dist
|
||||||
mv ./assets/*/*/* ./dist
|
mv ./assets/*/*/* ./dist
|
||||||
|
|
||||||
|
- name: prepare frontend dists
|
||||||
|
run: |
|
||||||
|
wget https://github.com/nezhahq/nezha-dashboard/releases/download/v0.0.2/dist.zip
|
||||||
|
unzip dist.zip
|
||||||
|
mv dist admin-dist
|
||||||
|
|
||||||
- name: Extract branch name
|
- name: Extract branch name in tag
|
||||||
|
if: contains(github.ref, 'refs/tags/')
|
||||||
run: |
|
run: |
|
||||||
export TAG_NAME=$(echo ${GITHUB_REF#refs/tags/})
|
export TAG_NAME=$(echo ${GITHUB_REF#refs/tags/})
|
||||||
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
|
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
|
||||||
id: extract_branch
|
id: extract_branch
|
||||||
|
|
||||||
|
- name: Extract branch name in branch
|
||||||
|
if: not(contains(github.ref, 'refs/tags/'))
|
||||||
|
run: |
|
||||||
|
export TAG_NAME=$(echo ${GITHUB_REF#refs/heads/})
|
||||||
|
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
|
||||||
|
id: extract_branch
|
||||||
|
|
||||||
- name: Log into GHCR
|
- name: Log into GHCR
|
||||||
uses: docker/login-action@master
|
uses: docker/login-action@master
|
||||||
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -12,11 +12,12 @@
|
|||||||
*.out
|
*.out
|
||||||
*.pprof
|
*.pprof
|
||||||
.idea
|
.idea
|
||||||
/data
|
|
||||||
/dist
|
/dist
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/main
|
/cmd/dashboard/data
|
||||||
/cmd/dashboard/main
|
/cmd/dashboard/main
|
||||||
|
/cmd/dashboard/admin-dist
|
||||||
|
/cmd/dashboard/user-dist
|
||||||
/config.yml
|
/config.yml
|
||||||
/resource/template/theme-custom
|
/resource/template/theme-custom
|
||||||
/resource/static/custom
|
/resource/static/custom
|
||||||
|
@ -7,6 +7,7 @@ ARG TARGETOS
|
|||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
|
|
||||||
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
|
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
|
||||||
|
COPY ./frontend /dashboard/frontend
|
||||||
COPY ./script/entrypoint.sh /entrypoint.sh
|
COPY ./script/entrypoint.sh /entrypoint.sh
|
||||||
RUN chmod +x /entrypoint.sh
|
RUN chmod +x /entrypoint.sh
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
jwt "github.com/appleboy/gin-jwt/v2"
|
jwt "github.com/appleboy/gin-jwt/v2"
|
||||||
@ -13,7 +15,6 @@ import (
|
|||||||
swaggerfiles "github.com/swaggo/files"
|
swaggerfiles "github.com/swaggo/files"
|
||||||
ginSwagger "github.com/swaggo/gin-swagger"
|
ginSwagger "github.com/swaggo/gin-swagger"
|
||||||
|
|
||||||
docs "github.com/naiba/nezha/cmd/dashboard/docs"
|
|
||||||
"github.com/naiba/nezha/model"
|
"github.com/naiba/nezha/model"
|
||||||
"github.com/naiba/nezha/service/singleton"
|
"github.com/naiba/nezha/service/singleton"
|
||||||
)
|
)
|
||||||
@ -21,7 +22,7 @@ import (
|
|||||||
func ServeWeb() http.Handler {
|
func ServeWeb() http.Handler {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
docs.SwaggerInfo.BasePath = "/api/v1"
|
|
||||||
if singleton.Conf.Debug {
|
if singleton.Conf.Debug {
|
||||||
gin.SetMode(gin.DebugMode)
|
gin.SetMode(gin.DebugMode)
|
||||||
pprof.Register(r)
|
pprof.Register(r)
|
||||||
@ -90,6 +91,8 @@ func routers(r *gin.Engine) {
|
|||||||
auth.POST("/ddns", commonHandler(createDDNS))
|
auth.POST("/ddns", commonHandler(createDDNS))
|
||||||
auth.PATCH("/ddns/:id", commonHandler(updateDDNS))
|
auth.PATCH("/ddns/:id", commonHandler(updateDDNS))
|
||||||
auth.POST("/batch-delete/ddns", commonHandler(batchDeleteDDNS))
|
auth.POST("/batch-delete/ddns", commonHandler(batchDeleteDDNS))
|
||||||
|
|
||||||
|
r.NoRoute(fallbackToFrontend)
|
||||||
}
|
}
|
||||||
|
|
||||||
func recordPath(c *gin.Context) {
|
func recordPath(c *gin.Context) {
|
||||||
@ -144,3 +147,26 @@ func commonHandler[T any](handler handlerFunc[T]) func(*gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fallbackToFrontend(c *gin.Context) {
|
||||||
|
if strings.HasPrefix(c.Request.URL.Path, "/api") {
|
||||||
|
c.JSON(http.StatusOK, newErrorResponse(errors.New("404 Not Found")))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(c.Request.URL.Path, "/dashboard") {
|
||||||
|
stripPath := strings.TrimPrefix(c.Request.URL.Path, "/dashboard")
|
||||||
|
localFilePath := filepath.Join("./admin-dist", stripPath)
|
||||||
|
if _, err := os.Stat(localFilePath); err == nil {
|
||||||
|
c.File(localFilePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.File("admin-dist/index.html")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
localFilePath := filepath.Join("user-dist", c.Request.URL.Path)
|
||||||
|
if _, err := os.Stat(localFilePath); err == nil {
|
||||||
|
c.File(localFilePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.File("user-dist/index.html")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user