Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: create dev-ci image embedding the frontend (#1726)
tianzhou225df6cea7e1
diff --git a/.github/workflows/build-push-ci-image.yml b/.github/workflows/build-push-ci-image.ymlindex 4265703667..67c62bb96f 100644--- a/.github/workflows/build-push-ci-image.yml+++ b/.github/workflows/build-push-ci-image.yml@@ -16,7 +16,7 @@ jobs:matrix:include:- docker-image-tag: "dev-ci"- docker-build-args: "RELEASE="+ docker-build-args: "RELEASE=dev"- docker-image-tag: "release-ci"docker-build-args: "RELEASE=release"steps:diff --git a/.gitignore b/.gitignoreindex 09d4448678..b1669aae14 100644--- a/.gitignore+++ b/.gitignore@@ -21,7 +21,8 @@ mysql-*.tar*.air# Frontend asset-dist+server/dist/*+!server/dist/index.html# Dev databasedata@@ -34,5 +35,4 @@ bytebase-build.DS_Store-dist/docs/openapi/swagger.jsondiff --git a/Dockerfile b/Dockerfileindex 5d6915cc2e..91b7f1dc16 100644--- a/Dockerfile+++ b/Dockerfile@@ -7,6 +7,8 @@FROM node:14 as frontend+ARG RELEASE="release"+RUN npm i -g pnpmWORKDIR /frontend-build@@ -18,7 +20,7 @@ RUN pnpm install --frozen-lockfileCOPY ./frontend/ .# Build frontend-RUN pnpm release-docker+RUN pnpm "${RELEASE}-docker"FROM golang:1.16.5 as backend@@ -28,7 +30,6 @@ ARG GIT_COMMIT="unknown"ARG BUILD_TIME="unknown"ARG BUILD_USER="unknown"-# Build in release mode so we will embed the frontendARG RELEASE="release"# Need gcc for CGO_ENABLED=1diff --git a/frontend/package.json b/frontend/package.jsonindex eed5680c71..b998159d5e 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -4,6 +4,7 @@"scripts": {"dev": "vite --mode dev","release": "vite build --mode release --outDir=../server/dist --emptyOutDir",+ "dev-docker": "export NODE_OPTIONS=--max_old_space_size=4096 && vite build --mode dev","release-docker": "export NODE_OPTIONS=--max_old_space_size=4096 && vite build --mode release","lint": "eslint --cache --ext .js,.ts,.tsx,.vue src","lint:fix": "eslint --cache --ext .js,.ts,.tsx,.vue --fix src",diff --git a/server/dist/index.html b/server/dist/index.htmlnew file mode 100644index 0000000000..a5379c5520--- /dev/null+++ b/server/dist/index.html@@ -0,0 +1,8 @@+<!DOCTYPE html>+<html>+ <body>+ <h1>Frontend is not embeded</h1>++ <p>This Bytebase build does not bundle frontend and backend together</p>+ </body>+</html>diff --git a/server/server.go b/server/server.goindex 195744d922..6de56097a1 100644--- a/server/server.go+++ b/server/server.go@@ -2,8 +2,10 @@ package serverimport ("context"+ "embed""encoding/json""fmt"+ "io/fs""net/http""runtime""strings"@@ -80,6 +82,35 @@ var casbinDBAPolicy string//go:embed acl_casbin_policy_developer.csvvar casbinDeveloperPolicy string+//go:embed dist+var embeddedFiles embed.FS++//go:embed dist/index.html+var indexContent string++func getFileSystem() http.FileSystem {+ fs, err := fs.Sub(embeddedFiles, "dist")+ if err != nil {+ panic(err)+ }++ return http.FS(fs)+}++// By default, we embed a placeholder index.html. If we want to build a monolithic binary including+// both frontend and backend (e.g. to produce our release build), we will instruct the build process+// to copy over the frontend artifacts and overwrite that placeholder.+func embedFrontend(e *echo.Echo) {+ // Catch-all route to return index.html, this is to prevent 404 when accessing non-root url.+ // See https://stackoverflow.com/questions/27928372/react-router-urls-dont-work-when-refreshing-or-writing-manually+ e.GET("/*", func(c echo.Context) error {+ return c.HTML(http.StatusOK, indexContent)+ })++ assetHandler := http.FileServer(getFileSystem())+ e.GET("/assets/*", echo.WrapHandler(assetHandler))+}+// Use following cmd to generate swagger doc// swag init -g ./server.go -d ./server --output docs/openapi --parseDependencydiff --git a/server/server_embed_dev.go b/server/server_embed_dev.godeleted file mode 100644index 1efa1deab7..0000000000--- a/server/server_embed_dev.go+++ /dev/null@@ -1,13 +0,0 @@-//go:build !release-// +build !release--package server--import (- "github.com/bytebase/bytebase/common/log"- "github.com/labstack/echo/v4"-)--func embedFrontend(_ *echo.Echo) {- log.Info("Dev mode, skip embedding frontend")-}diff --git a/server/server_embed_release.go b/server/server_embed_release.godeleted file mode 100644index cf1ac53890..0000000000--- a/server/server_embed_release.go+++ /dev/null@@ -1,38 +0,0 @@-//go:build release-// +build release--package server--import (- "embed"- "io/fs"- "net/http"-- "github.com/labstack/echo/v4"-)--//go:embed dist-var embeddedFiles embed.FS--//go:embed dist/index.html-var indexContent string--func getFileSystem() http.FileSystem {- fs, err := fs.Sub(embeddedFiles, "dist")- if err != nil {- panic(err)- }-- return http.FS(fs)-}--func embedFrontend(e *echo.Echo) {- // Catch-all route to return index.html, this is to prevent 404 when accessing non-root url.- // See https://stackoverflow.com/questions/27928372/react-router-urls-dont-work-when-refreshing-or-writing-manually- e.GET("/*", func(c echo.Context) error {- return c.HTML(http.StatusOK, indexContent)- })-- assetHandler := http.FileServer(getFileSystem())- e.GET("/assets/*", echo.WrapHandler(assetHandler))-}