Browse Source

admin added

pull/288/head
yedf2 4 years ago
parent
commit
300a5717a7
  1. 8
      .github/workflows/release.yml
  2. 2
      .gitignore
  3. 1
      admin/.env
  4. 2
      admin/.env.development
  5. 12
      admin/src/components.d.ts
  6. 1
      admin/src/utils/request.ts
  7. 8
      helper/Dockerfile-release
  8. 24
      main.go

8
.github/workflows/release.yml

@ -10,7 +10,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3
uses: actions/setup-node@v3
with:
node-version: 14
- run: cd admin
- run: yarn
- run: VITE_ADMIN_VERSION=${GITHUB_REF#refs/*/} yarn build
- name: Validates GO releaser config
uses: docker://goreleaser/goreleaser:v1.7.0

2
.gitignore

@ -1,7 +1,7 @@
conf.yml
*.out
*.log
dist
# dist
.idea/**
.vscode
default.etcd

1
admin/.env

@ -0,0 +1 @@
VITE_ADMIN_VERSION="v0.0.0-dev"

2
admin/.env.development

@ -1,2 +0,0 @@
VITE_PROXY=[["/api", "http://localhost:36789"]]
VITE_ADMIN_VERSION="v0.0.0-dev"

12
admin/src/components.d.ts

@ -5,6 +5,18 @@ import '@vue/runtime-core'
declare module '@vue/runtime-core' {
export interface GlobalComponents {
ABreadcrumb: typeof import('ant-design-vue/es')['Breadcrumb']
ABreadcrumbItem: typeof import('ant-design-vue/es')['BreadcrumbItem']
AButton: typeof import('ant-design-vue/es')['Button']
ALayout: typeof import('ant-design-vue/es')['Layout']
ALayoutContent: typeof import('ant-design-vue/es')['LayoutContent']
ALayoutHeader: typeof import('ant-design-vue/es')['LayoutHeader']
ALayoutSider: typeof import('ant-design-vue/es')['LayoutSider']
AMenu: typeof import('ant-design-vue/es')['Menu']
AMenuItem: typeof import('ant-design-vue/es')['MenuItem']
ASubMenu: typeof import('ant-design-vue/es')['SubMenu']
ATable: typeof import('ant-design-vue/es')['Table']
ATag: typeof import('ant-design-vue/es')['Tag']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
SvgIcon: typeof import('./components/SvgIcon/index.vue')['default']

1
admin/src/utils/request.ts

@ -1,7 +1,6 @@
import axios from 'axios'
const request = axios.create({
baseURL: import.meta.env.VITE_APP_API_BASE_URL as string | undefined,
timeout: 60000
})

8
helper/Dockerfile-release

@ -1,4 +1,11 @@
# syntax=docker/dockerfile:1
FROM node:14.5.0-alpine as bulder1
ARG RELEASE_VERSION
WORKDIR /app/dtm
COPY . .
RUN cd admin && yarn
RUN VITE_ADMIN_VERSION=$RELEASE_VERSION yarn build
FROM --platform=$TARGETPLATFORM golang:1.16-alpine as builder
ARG TARGETARCH
ARG TARGETOS
@ -7,6 +14,7 @@ WORKDIR /app/dtm
# RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
EXPOSE 8080
COPY . .
COPY --from=bulder1 /app/dtm/admin/dist /app/dtm/admin
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-s -w -X main.Version=$RELEASE_VERSION"
FROM --platform=$TARGETPLATFORM alpine

24
main.go

@ -10,6 +10,7 @@ import (
"embed"
"fmt"
"io/fs"
"io/ioutil"
"net/http"
"net/http/httputil"
"net/url"
@ -35,10 +36,7 @@ func main() {
//go:embed admin/dist
var admin embed.FS
//go:embed admin/dist/index.html
var indexFile string
var target = ""
var target = "admin.dtm.pub"
func getSub(f1 fs.FS, sub string) fs.FS {
f2, err := fs.Sub(f1, sub)
@ -46,14 +44,22 @@ func getSub(f1 fs.FS, sub string) fs.FS {
return f2
}
func addAdmin(app *gin.Engine, conf *config.ConfigType) {
// for released dtm, serve admin from local files because the build output has been embed
// for testing users, proxy admin to target because the build output has not been embed
dist := getSub(admin, "admin/dist")
_, err := dist.Open("index.html")
index, err := dist.Open("index.html")
if err == nil {
app.StaticFS("/assets", http.FS(getSub(dist, "assets")))
app.GET("/admin/*name", func(c *gin.Context) {
defer index.Close()
cont, err := ioutil.ReadAll(index)
logger.FatalIfError(err)
sfile := string(cont)
renderIndex := func(c *gin.Context) {
c.Header("content-type", "text/html;charset=utf-8")
c.String(200, indexFile)
})
c.String(200, sfile)
}
app.StaticFS("/assets", http.FS(getSub(dist, "assets")))
app.GET("/admin/*name", renderIndex)
app.GET("/", renderIndex)
logger.Infof("admin is served from dir 'admin/dist/'")
} else {
app.GET("/", proxyAdmin)

Loading…
Cancel
Save