You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@casbin.apache.org by hs...@apache.org on 2026/08/18 11:19:39 UTC

(casbin-gateway) branch master updated: feat: build and embed the web2 UI in CI and Docker

This is an automated email from the ASF dual-hosted git repository.

hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-gateway.git


The following commit(s) were added to refs/heads/master by this push:
     new bc6f589  feat: build and embed the web2 UI in CI and Docker
bc6f589 is described below

commit bc6f589d810255a4327d97685f15ccc59add775c
Author: Yang Luo <hs...@gmail.com>
AuthorDate: Tue Aug 18 19:19:30 2026 +0800

    feat: build and embed the web2 UI in CI and Docker
---
 .dockerignore                 |  4 +++-
 .github/workflows/build.yml   |  6 +++---
 .github/workflows/nightly.yml | 16 ++++++++--------
 Dockerfile                    | 12 ++++++------
 README.md                     |  8 ++++----
 embed.go                      | 13 +++++++------
 embedsupport/setup.go         |  8 ++++----
 embedsupport/web.go           |  2 +-
 8 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/.dockerignore b/.dockerignore
index 735a8b4..c184cd1 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1 +1,3 @@
-web/node_modules/
\ No newline at end of file
+web/node_modules/
+web2/node_modules/
+web2/build/
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 771b9cc..76897f2 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -34,9 +34,9 @@ jobs:
         with:
           node-version: 20
           cache: 'yarn'
-          cache-dependency-path: ./web/yarn.lock
-      - run: yarn install && CI=false yarn run build
-        working-directory: ./web
+          cache-dependency-path: ./web2/yarn.lock
+      - run: yarn install && yarn build
+        working-directory: ./web2
 
   backend:
     name: Back-end
diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml
index 24d05f3..47892d2 100644
--- a/.github/workflows/nightly.yml
+++ b/.github/workflows/nightly.yml
@@ -38,19 +38,19 @@ jobs:
         with:
           node-version: 20
           cache: 'yarn'
-          cache-dependency-path: ./web/yarn.lock
+          cache-dependency-path: ./web2/yarn.lock
 
-      # Source maps are left out on purpose: everything under web/build ends up
-      # inside every one of the three binaries below.
+      # Everything under web2/build ends up inside every one of the three
+      # binaries below, which is why the Vite config leaves source maps out.
       - name: Build
-        run: yarn install && CI=false GENERATE_SOURCEMAP=false yarn run build
-        working-directory: ./web
+        run: yarn install && yarn build
+        working-directory: ./web2
 
       - name: Upload web build
         uses: actions/upload-artifact@v4
         with:
           name: web-build-${{ github.run_id }}
-          path: ./web/build
+          path: ./web2/build
           retention-days: 1
 
   nightly:
@@ -68,12 +68,12 @@ jobs:
           cache-dependency-path: ./go.mod
 
       # The binaries are built with -tags embed, which bakes conf/app.conf, the
-      # web UI and the IP database in, so web/build has to be in place first.
+      # web UI and the IP database in, so web2/build has to be in place first.
       - name: Download web build
         uses: actions/download-artifact@v4
         with:
           name: web-build-${{ github.run_id }}
-          path: ./web/build
+          path: ./web2/build
 
       - name: Build the platform archives
         run: |
diff --git a/Dockerfile b/Dockerfile
index 32d7377..e932c07 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,7 +1,7 @@
-FROM node:18.19.0 AS FRONT
-WORKDIR /web
-COPY ./web .
-RUN yarn install --frozen-lockfile --network-timeout 1000000 && yarn run build
+FROM node:20 AS FRONT
+WORKDIR /web2
+COPY ./web2 .
+RUN yarn install --frozen-lockfile --network-timeout 1000000 && yarn build
 
 FROM golang:1.20.12 AS BACK
 WORKDIR /go/src/casbin-gateway
@@ -12,8 +12,8 @@ FROM alpine:latest AS STANDARD
 LABEL MAINTAINER="https://caswaf.org/"
 
 COPY --from=BACK /go/src/casbin-gateway/ ./
-RUN mkdir -p web/build && apk add --no-cache bash coreutils tzdata
-COPY --from=FRONT /web/build /web/build
+RUN mkdir -p web2/build && apk add --no-cache bash coreutils tzdata
+COPY --from=FRONT /web2/build /web2/build
 # Holds the SQLite database at /data/casbin-gateway.db.
 VOLUME /data
 ENTRYPOINT ["./server"]
diff --git a/README.md b/README.md
index c088fbd..0649815 100644
--- a/README.md
+++ b/README.md
@@ -141,24 +141,24 @@ You should get your backend's response. A `site not found for host` reply means
 
 ### Single binary
 
-Normally Gateway reads three things from disk when it starts: `conf/app.conf`, the compiled web UI, and the IP location database `ip/17monipdb.dat`. Building with the `embed` tag bakes all three into the executable, so it can be copied somewhere on its own and started from anywhere. The web UI it bakes in is still the Ant Design build from `web/build`; a `web2/build` on disk takes over whenever it is present:
+Normally Gateway reads three things from disk when it starts: `conf/app.conf`, the compiled web UI in `web2/build`, and the IP location database `ip/17monipdb.dat`. Building with the `embed` tag bakes all three into the executable, so it can be copied somewhere on its own and started from anywhere:
 
 ```bash
-cd web && yarn install && GENERATE_SOURCEMAP=false yarn build
+cd web2 && yarn install && yarn build
 ```
 
 ```bash
 go build -tags embed -o casbin-gateway .
 ```
 
-Build the frontend first: everything under `web/build` goes into the binary, so `go build -tags embed` fails to compile while that directory is missing. Turning source maps off keeps them out of the binary, where they would cost several times what the code they map costs.
+Build the frontend first: everything under `web2/build` goes into the binary, so `go build -tags embed` fails to compile while that directory is missing. The Vite config leaves source maps out, which keeps them out of the binary too, where they would cost several times what the code they map costs.
 
 Files on disk always win over the embedded copies, so a single binary can still be configured and developed against without rebuilding it:
 
 | Embedded asset | Overridden by |
 | --- | --- |
 | `conf/app.conf` | `conf/app.conf` in the working directory, or next to the executable |
-| `web/build` | `web2/build/index.html` or `web/build/index.html` in the working directory, the first of those found then serving the whole UI |
+| `web2/build` | `web2/build/index.html` or `web/build/index.html` in the working directory, the first of those found then serving the whole UI |
 | `ip/17monipdb.dat` | `ip/17monipdb.dat` in the working directory |
 
 The startup summary reports which source each one came from:
diff --git a/embed.go b/embed.go
index 83a6629..69a21b7 100644
--- a/embed.go
+++ b/embed.go
@@ -19,13 +19,14 @@
 // the binary runs on its own with no files next to it. Files on disk still win
 // over the embedded copies at runtime — see the embedsupport package.
 //
-// web/build must exist before building with this tag, or go:embed fails to
+// web2/build must exist before building with this tag, or go:embed fails to
 // compile: build the frontend first with
 //
-//	cd web && yarn install && GENERATE_SOURCEMAP=false yarn build
+//	cd web2 && yarn install && yarn build
 //
-// Source maps are worth turning off because everything under web/build ends up
-// inside the binary, and they are several times the size of the code they map.
+// Everything under web2/build ends up inside the binary, which is why the Vite
+// config turns source maps off: they are several times the size of the code
+// they map.
 
 package main
 
@@ -45,14 +46,14 @@ import (
 //go:embed conf/app.conf
 var embeddedAppConf string
 
-//go:embed web/build
+//go:embed web2/build
 var embeddedWeb embed.FS
 
 //go:embed ip/17monipdb.dat
 var embeddedIpDb []byte
 
 func init() {
-	webFS, err := fs.Sub(embeddedWeb, "web/build")
+	webFS, err := fs.Sub(embeddedWeb, "web2/build")
 	if err != nil {
 		panic(err)
 	}
diff --git a/embedsupport/setup.go b/embedsupport/setup.go
index 3760ca1..ebcb025 100644
--- a/embedsupport/setup.go
+++ b/embedsupport/setup.go
@@ -14,13 +14,13 @@
 
 // Package embedsupport wires up the assets that are baked into the binary when
 // it is built with -tags embed: conf/app.conf, the compiled web UI in
-// web/build, and the IP location database. Those are every file Gateway needs
+// web2/build, and the IP location database. Those are every file Gateway needs
 // to find on disk at startup, so embedding them turns it into a single
 // executable that runs with nothing next to it.
 //
 // The embedded copies are a fallback, never an override: whenever the matching
 // file exists on disk it wins, so an operator can drop a conf/app.conf beside
-// the binary, or keep developing against a live web/build, without rebuilding.
+// the binary, or keep developing against a live web2/build, without rebuilding.
 //
 // A build without -tags embed never calls Setup, so both accessors report
 // "nothing embedded" and every caller keeps its original on-disk behaviour.
@@ -35,7 +35,7 @@ var (
 
 // Setup must be called before any config value is read or any request is
 // served. appConf is the contents of the embedded conf/app.conf, web is the
-// embedded web/build tree, and ipDb is the embedded IP location database; each
+// embedded web2/build tree, and ipDb is the embedded IP location database; each
 // of them may be empty or nil.
 func Setup(appConf string, web fs.FS, ipDatabase []byte) {
 	webFS = web
@@ -43,7 +43,7 @@ func Setup(appConf string, web fs.FS, ipDatabase []byte) {
 	setupConf(appConf)
 }
 
-// WebFS returns the embedded web/build filesystem, or nil when the binary was
+// WebFS returns the embedded web2/build filesystem, or nil when the binary was
 // built without embedded web assets.
 func WebFS() fs.FS { return webFS }
 
diff --git a/embedsupport/web.go b/embedsupport/web.go
index bcc353e..39332d5 100644
--- a/embedsupport/web.go
+++ b/embedsupport/web.go
@@ -24,7 +24,7 @@ import (
 	"time"
 )
 
-// ServeWeb answers a request for a frontend asset from the embedded web/build
+// ServeWeb answers a request for a frontend asset from the embedded web2/build
 // tree. urlPath is the request path, e.g. "/" or "/static/js/main.abc123.js".
 // Anything the tree does not contain falls back to index.html, because the web
 // UI is a single-page app whose routes ("/sites", "/rules", ...) exist only in


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For additional commands, e-mail: commits-help@casbin.apache.org