mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-09 00:56:37 +08:00
fix(build): embed frontend into driver_http dist
Copy the static export to backend/plugins/drivers/driver_http/dist so Wavelet's //go:embed all:dist actually ships the OpenFlare UI. Point release builds at backend/go.mod and assert index.html after copy.
This commit is contained in:
@@ -33,3 +33,4 @@ frontend/*.tsbuildinfo
|
|||||||
frontend/package-lock.json
|
frontend/package-lock.json
|
||||||
internal/router/dist/
|
internal/router/dist/
|
||||||
internal/router/root/dist/
|
internal/router/root/dist/
|
||||||
|
backend/plugins/drivers/driver_http/dist/
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ on:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
APP_NAME: openflare-server
|
APP_NAME: openflare-server
|
||||||
|
GO_DIR: backend
|
||||||
GO_MAIN: ./main.go
|
GO_MAIN: ./main.go
|
||||||
GO_BUILD_TAGS: embed_frontend
|
GO_BUILD_TAGS: embed_frontend
|
||||||
GO_LDFLAGS: -s -w
|
GO_LDFLAGS: -s -w
|
||||||
@@ -20,7 +21,7 @@ env:
|
|||||||
FRONTEND_DIR: frontend
|
FRONTEND_DIR: frontend
|
||||||
FRONTEND_BUILD_COMMAND: pnpm build:embed
|
FRONTEND_BUILD_COMMAND: pnpm build:embed
|
||||||
FRONTEND_OUT_DIR: frontend/out
|
FRONTEND_OUT_DIR: frontend/out
|
||||||
EMBED_DIST_DIR: backend/OpenFlare/plugins/server/router/root/dist
|
EMBED_DIST_DIR: backend/plugins/drivers/driver_http/dist
|
||||||
EXTRA_FILES: |
|
EXTRA_FILES: |
|
||||||
LICENSE
|
LICENSE
|
||||||
README.md
|
README.md
|
||||||
@@ -145,6 +146,7 @@ jobs:
|
|||||||
rm -rf "$EMBED_DIST_DIR"
|
rm -rf "$EMBED_DIST_DIR"
|
||||||
mkdir -p "$(dirname "$EMBED_DIST_DIR")"
|
mkdir -p "$(dirname "$EMBED_DIST_DIR")"
|
||||||
cp -R "$FRONTEND_OUT_DIR" "$EMBED_DIST_DIR"
|
cp -R "$FRONTEND_OUT_DIR" "$EMBED_DIST_DIR"
|
||||||
|
test -f "$EMBED_DIST_DIR/index.html"
|
||||||
|
|
||||||
- name: Upload embedded frontend
|
- name: Upload embedded frontend
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
@@ -192,7 +194,7 @@ jobs:
|
|||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: go.mod
|
go-version-file: ${{ env.GO_DIR }}/go.mod
|
||||||
cache: true
|
cache: true
|
||||||
|
|
||||||
- name: Build binary
|
- name: Build binary
|
||||||
@@ -212,6 +214,9 @@ jobs:
|
|||||||
binary_name="${binary_name}.exe"
|
binary_name="${binary_name}.exe"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Assert the embedded UI is present so a release cannot ship an API-only binary.
|
||||||
|
test -f "$EMBED_DIST_DIR/index.html"
|
||||||
|
|
||||||
ldflags="$GO_LDFLAGS -X Wavelet/pkg/buildinfo.Version=$VERSION -X Wavelet/pkg/buildinfo.BuildTime=$BUILD_DATE"
|
ldflags="$GO_LDFLAGS -X Wavelet/pkg/buildinfo.Version=$VERSION -X Wavelet/pkg/buildinfo.BuildTime=$BUILD_DATE"
|
||||||
build_args=(
|
build_args=(
|
||||||
-trimpath
|
-trimpath
|
||||||
@@ -223,7 +228,7 @@ jobs:
|
|||||||
build_args=(-tags "$GO_BUILD_TAGS" "${build_args[@]}")
|
build_args=(-tags "$GO_BUILD_TAGS" "${build_args[@]}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
( cd backend && go build "${build_args[@]}" "$GO_MAIN" )
|
(cd "$GO_DIR" && go build "${build_args[@]}" "$GO_MAIN")
|
||||||
|
|
||||||
- name: Package artifact
|
- name: Package artifact
|
||||||
id: package
|
id: package
|
||||||
@@ -296,7 +301,7 @@ jobs:
|
|||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: go.mod
|
go-version-file: ${{ env.GO_DIR }}/go.mod
|
||||||
|
|
||||||
# GeoIP MMDB is not embedded; Docker images COPY mmdb files, bare binaries seed via download on first start.
|
# GeoIP MMDB is not embedded; Docker images COPY mmdb files, bare binaries seed via download on first start.
|
||||||
- name: Build Agent
|
- name: Build Agent
|
||||||
@@ -345,7 +350,7 @@ jobs:
|
|||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: go.mod
|
go-version-file: ${{ env.GO_DIR }}/go.mod
|
||||||
|
|
||||||
- name: Build Relay
|
- name: Build Relay
|
||||||
env:
|
env:
|
||||||
@@ -393,7 +398,7 @@ jobs:
|
|||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: go.mod
|
go-version-file: ${{ env.GO_DIR }}/go.mod
|
||||||
|
|
||||||
- name: Build Flared
|
- name: Build Flared
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -29,8 +29,9 @@ build-embedded:
|
|||||||
NEXT_PUBLIC_APP_VERSION="$(VERSION)" \
|
NEXT_PUBLIC_APP_VERSION="$(VERSION)" \
|
||||||
NEXT_PUBLIC_APP_BUILD_DATE="$(BUILD_DATE)" \
|
NEXT_PUBLIC_APP_BUILD_DATE="$(BUILD_DATE)" \
|
||||||
pnpm build:embed
|
pnpm build:embed
|
||||||
rm -rf backend/OpenFlare/plugins/server/router/root/dist
|
rm -rf backend/plugins/drivers/driver_http/dist
|
||||||
cp -R frontend/out backend/OpenFlare/plugins/server/router/root/dist
|
cp -R frontend/out backend/plugins/drivers/driver_http/dist
|
||||||
|
test -f backend/plugins/drivers/driver_http/dist/index.html
|
||||||
cd backend && go build \
|
cd backend && go build \
|
||||||
-tags embed_frontend \
|
-tags embed_frontend \
|
||||||
-ldflags "-s -w -X '$(MODULE)/pkg/buildinfo.Version=$(VERSION)' -X '$(MODULE)/pkg/buildinfo.BuildTime=$(BUILD_DATE)'" \
|
-ldflags "-s -w -X '$(MODULE)/pkg/buildinfo.Version=$(VERSION)' -X '$(MODULE)/pkg/buildinfo.BuildTime=$(BUILD_DATE)'" \
|
||||||
|
|||||||
+16
-7
@@ -20,12 +20,13 @@ RUN corepack enable && corepack prepare pnpm@10.10.0 --activate
|
|||||||
|
|
||||||
WORKDIR /workspace/frontend
|
WORKDIR /workspace/frontend
|
||||||
|
|
||||||
COPY frontend/package.json frontend/pnpm-lock.yaml ./
|
COPY frontend/package.json frontend/pnpm-lock.yaml frontend/pnpm-workspace.yaml ./
|
||||||
RUN pnpm install --frozen-lockfile
|
RUN pnpm install --frozen-lockfile
|
||||||
|
|
||||||
COPY frontend/ ./
|
COPY frontend/ ./
|
||||||
|
|
||||||
RUN pnpm build:embed
|
# Assert index.html so a silent export failure cannot ship an API-only binary.
|
||||||
|
RUN pnpm build:embed && test -f out/index.html
|
||||||
|
|
||||||
FROM golang:${GO_VERSION}-alpine AS backend-builder
|
FROM golang:${GO_VERSION}-alpine AS backend-builder
|
||||||
|
|
||||||
@@ -36,13 +37,21 @@ RUN apk add --no-cache ca-certificates git
|
|||||||
|
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
|
|
||||||
COPY backend/go.mod backend/go.sum ./
|
# Cache dependency layer
|
||||||
RUN go mod download
|
COPY backend/go.mod backend/go.sum ./backend/
|
||||||
|
RUN cd backend && go mod download
|
||||||
|
|
||||||
COPY backend/ ./
|
COPY . .
|
||||||
COPY --from=frontend-builder /workspace/frontend/out ./internal/router/root/dist
|
|
||||||
|
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build \
|
# Drop any stale bundle carried in the context, then overlay the fresh export so
|
||||||
|
# `//go:embed all:dist` in driver_http picks up exactly this frontend build.
|
||||||
|
RUN rm -rf backend/plugins/drivers/driver_http/dist
|
||||||
|
COPY --from=frontend-builder /workspace/frontend/out backend/plugins/drivers/driver_http/dist
|
||||||
|
|
||||||
|
WORKDIR /workspace/backend
|
||||||
|
|
||||||
|
RUN test -f plugins/drivers/driver_http/dist/index.html && \
|
||||||
|
CGO_ENABLED=0 GOOS=linux go build \
|
||||||
-tags embed_frontend \
|
-tags embed_frontend \
|
||||||
-trimpath \
|
-trimpath \
|
||||||
-ldflags="-s -w -X Wavelet/pkg/buildinfo.Version=${VERSION} -X Wavelet/pkg/buildinfo.BuildTime=${BUILD_DATE}" \
|
-ldflags="-s -w -X Wavelet/pkg/buildinfo.Version=${VERSION} -X Wavelet/pkg/buildinfo.BuildTime=${BUILD_DATE}" \
|
||||||
|
|||||||
+13
-7
@@ -43,12 +43,13 @@ RUN corepack enable && corepack prepare pnpm@10.10.0 --activate
|
|||||||
WORKDIR /workspace/frontend
|
WORKDIR /workspace/frontend
|
||||||
|
|
||||||
# Cache dependency layer
|
# Cache dependency layer
|
||||||
COPY frontend/package.json frontend/pnpm-lock.yaml ./
|
COPY frontend/package.json frontend/pnpm-lock.yaml frontend/pnpm-workspace.yaml ./
|
||||||
RUN pnpm install --frozen-lockfile
|
RUN pnpm install --frozen-lockfile
|
||||||
|
|
||||||
COPY frontend/ ./
|
COPY frontend/ ./
|
||||||
|
|
||||||
RUN pnpm build:embed
|
# Assert index.html so a silent export failure cannot ship API-only binaries.
|
||||||
|
RUN pnpm build:embed && test -f out/index.html
|
||||||
|
|
||||||
# ── Stage 2: Cross-compile Go backend ──────────────────────────────────────
|
# ── Stage 2: Cross-compile Go backend ──────────────────────────────────────
|
||||||
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS builder
|
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS builder
|
||||||
@@ -66,13 +67,17 @@ RUN apk add --no-cache ca-certificates git
|
|||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
|
|
||||||
# Cache dependency layer
|
# Cache dependency layer
|
||||||
COPY backend/go.mod backend/go.sum ./
|
COPY backend/go.mod backend/go.sum ./backend/
|
||||||
RUN go mod download
|
RUN cd backend && go mod download
|
||||||
|
|
||||||
COPY backend/ ./
|
COPY . .
|
||||||
|
|
||||||
# Overlay the compiled frontend into the embed path
|
# Drop any stale bundle carried in the context, then overlay the fresh export so
|
||||||
COPY --from=frontend-builder /workspace/frontend/out ./internal/router/root/dist
|
# `//go:embed all:dist` in driver_http picks up exactly this frontend build.
|
||||||
|
RUN rm -rf backend/plugins/drivers/driver_http/dist
|
||||||
|
COPY --from=frontend-builder /workspace/frontend/out backend/plugins/drivers/driver_http/dist
|
||||||
|
|
||||||
|
WORKDIR /workspace/backend
|
||||||
|
|
||||||
# Build matrix: GOOS × GOARCH
|
# Build matrix: GOOS × GOARCH
|
||||||
# CGO_ENABLED=0 — fully static, no libc dependency, required for cross-compilation.
|
# CGO_ENABLED=0 — fully static, no libc dependency, required for cross-compilation.
|
||||||
@@ -81,6 +86,7 @@ COPY --from=frontend-builder /workspace/frontend/out ./internal/router/root/dist
|
|||||||
# -X — stamp version string at link time.
|
# -X — stamp version string at link time.
|
||||||
# TARGET_OS / TARGET_ARCH — when non-empty, skip non-matching combinations.
|
# TARGET_OS / TARGET_ARCH — when non-empty, skip non-matching combinations.
|
||||||
RUN set -e; \
|
RUN set -e; \
|
||||||
|
test -f plugins/drivers/driver_http/dist/index.html; \
|
||||||
mkdir -p /out; \
|
mkdir -p /out; \
|
||||||
FILTER_OS="${TARGET_OS}"; \
|
FILTER_OS="${TARGET_OS}"; \
|
||||||
FILTER_ARCH="${TARGET_ARCH}"; \
|
FILTER_ARCH="${TARGET_ARCH}"; \
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ find_go_files() {
|
|||||||
-o -path './frontend/out' \
|
-o -path './frontend/out' \
|
||||||
-o -path './internal/router/dist' \
|
-o -path './internal/router/dist' \
|
||||||
-o -path './internal/router/root/dist' \
|
-o -path './internal/router/root/dist' \
|
||||||
|
-o -path './backend/plugins/drivers/driver_http/dist' \
|
||||||
|
-o -path './plugins/drivers/driver_http/dist' \
|
||||||
-o -path './vendor' \) -prune \
|
-o -path './vendor' \) -prune \
|
||||||
-o -type f -name '*.go' -print
|
-o -type f -name '*.go' -print
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user