chore: speedup build
This commit is contained in:
@@ -5,6 +5,10 @@ on:
|
|||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: ghcr.io
|
REGISTRY: ghcr.io
|
||||||
IMAGE_NAME: baihu
|
IMAGE_NAME: baihu
|
||||||
|
|||||||
+24
-11
@@ -9,8 +9,9 @@ WORKDIR /app/web
|
|||||||
# Copy package files
|
# Copy package files
|
||||||
COPY web/package*.json ./
|
COPY web/package*.json ./
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies using cache mount for npm
|
||||||
RUN npm ci
|
RUN --mount=type=cache,target=/root/.npm \
|
||||||
|
npm ci
|
||||||
|
|
||||||
# Copy frontend source
|
# Copy frontend source
|
||||||
COPY web/ ./
|
COPY web/ ./
|
||||||
@@ -49,7 +50,10 @@ COPY --from=build-info /build-info /build-info
|
|||||||
|
|
||||||
# Go mod files
|
# Go mod files
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download
|
RUN go env -w GOPROXY=https://goproxy.cn,direct
|
||||||
|
# Using Go build cache mount can significantly speed up consecutive builds
|
||||||
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
|
go mod download
|
||||||
|
|
||||||
# Copy backend source
|
# Copy backend source
|
||||||
COPY . .
|
COPY . .
|
||||||
@@ -57,11 +61,17 @@ COPY . .
|
|||||||
# Copy frontend dist (needed for embedding)
|
# Copy frontend dist (needed for embedding)
|
||||||
COPY --from=frontend-builder /app/web/dist ./internal/static/dist
|
COPY --from=frontend-builder /app/web/dist ./internal/static/dist
|
||||||
|
|
||||||
# Generate Swagger
|
# Generate Swagger (Optional: better to commit docs and only copy, but if needed, install once)
|
||||||
RUN go run github.com/swaggo/swag/cmd/swag@latest init -g main.go -o ./openapi_docs
|
# If openapi_docs exists, just use it, otherwise generate.
|
||||||
|
# Here we avoid go run @latest by copying it if you have it locally.
|
||||||
|
# If you don't, we install it once to the image.
|
||||||
|
RUN go install github.com/swaggo/swag/cmd/swag@latest
|
||||||
|
RUN swag init -g main.go -o ./openapi_docs
|
||||||
|
|
||||||
# Build Go binary
|
# Build Go binary using cache mounts for faster builds
|
||||||
RUN VERSION_VAL=$(cat /build-info/version.txt) && \
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
|
--mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
VERSION_VAL=$(cat /build-info/version.txt) && \
|
||||||
BUILD_TIME_VAL=$(cat /build-info/build_time.txt) && \
|
BUILD_TIME_VAL=$(cat /build-info/build_time.txt) && \
|
||||||
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
|
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
|
||||||
go build -ldflags="-s -w -X github.com/engigu/baihu-panel/internal/constant.Version=${VERSION_VAL} -X 'github.com/engigu/baihu-panel/internal/constant.BuildTime=${BUILD_TIME_VAL}'" \
|
go build -ldflags="-s -w -X github.com/engigu/baihu-panel/internal/constant.Version=${VERSION_VAL} -X 'github.com/engigu/baihu-panel/internal/constant.BuildTime=${BUILD_TIME_VAL}'" \
|
||||||
@@ -78,9 +88,9 @@ WORKDIR /app
|
|||||||
# Copy build info
|
# Copy build info
|
||||||
COPY --from=build-info /build-info /build-info
|
COPY --from=build-info /build-info /build-info
|
||||||
|
|
||||||
# Go mod files
|
# Using Go build cache mount
|
||||||
COPY go.mod go.sum ./
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download
|
go mod download
|
||||||
|
|
||||||
# Copy source needed for agent
|
# Copy source needed for agent
|
||||||
COPY internal/ ./internal/
|
COPY internal/ ./internal/
|
||||||
@@ -89,7 +99,10 @@ COPY agent/ ./agent/
|
|||||||
# Build agent for all platforms and package as tar.gz
|
# Build agent for all platforms and package as tar.gz
|
||||||
WORKDIR /app/agent
|
WORKDIR /app/agent
|
||||||
|
|
||||||
RUN VERSION_VAL=$(cat /build-info/version.txt) && \
|
# Build agent with parallel-aware logic or just cache mount
|
||||||
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
|
--mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
VERSION_VAL=$(cat /build-info/version.txt) && \
|
||||||
BUILD_TIME_VAL=$(cat /build-info/build_time.txt) && \
|
BUILD_TIME_VAL=$(cat /build-info/build_time.txt) && \
|
||||||
LDFLAGS="-s -w -X 'main.Version=${VERSION_VAL}' -X 'main.BuildTime=${BUILD_TIME_VAL}'" && \
|
LDFLAGS="-s -w -X 'main.Version=${VERSION_VAL}' -X 'main.BuildTime=${BUILD_TIME_VAL}'" && \
|
||||||
mkdir -p /opt/agent && \
|
mkdir -p /opt/agent && \
|
||||||
|
|||||||
Reference in New Issue
Block a user