From 050a1c15344e4b26bbf2ee5df8eb7128e7a18263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=98=89=E4=BC=9F?= <8473136@qq.com> Date: Mon, 2 Mar 2026 18:05:19 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 59 +++++++++ .github/workflows/release.yml | 216 ++++++++++++++++++++++++++++++++ build/Dockerfile => Dockerfile | 0 build/docker-build.sh | 6 +- deploy/docker-compose.build.yml | 2 +- site/package.json | 4 +- 6 files changed, 281 insertions(+), 6 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/release.yml rename build/Dockerfile => Dockerfile (100%) diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ccf5dbf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,59 @@ +# Git +.git +.gitignore +.gitattributes + +# IDE +.vscode +.idea +*.swp +*.swo +*~ + +# CI/CD +.github/ +.claude/ + +# Build output +build/dist/ +dist/ +*.tar.gz +*.zip +frpc-hub +frpc-hub.exe + +# Frontend (built inside Docker) +site/node_modules/ +site/dist/ + +# Runtime data +pb_data/ +pb_public/ +*.db +*.db-shm +*.db-wal + +# Logs +*.log +logs/ + +# OS +.DS_Store +Thumbs.db + +# Temp +*.tmp +*.temp +tmp/ +temp/ + +# Env +.env.local +.env.*.local + +# Docs +*.md +!README.md + +# Test +*_test.go diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7bbde42 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,216 @@ +name: Release + +on: + push: + tags: + - 'v*' + +env: + GO_VERSION_FILE: go.mod + NODE_VERSION: '20' + PNPM_VERSION: '10' + APP_NAME: frpc-hub + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + # ────────────────────────────────────────────── + # Job 1: Build React frontend + # ────────────────────────────────────────────── + build-frontend: + name: Build Frontend + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: pnpm/action-setup@v4 + with: + version: ${{ env.PNPM_VERSION }} + + - uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: pnpm + cache-dependency-path: site/pnpm-lock.yaml + + - name: Install dependencies + run: pnpm install --frozen-lockfile + working-directory: site + + - name: Build + run: pnpm run build + working-directory: site + + - name: Upload frontend dist + uses: actions/upload-artifact@v4 + with: + name: frontend-dist + path: site/dist/ + retention-days: 1 + + # ────────────────────────────────────────────── + # Job 2: Cross-compile Go binaries (all platforms) + # ────────────────────────────────────────────── + build-binaries: + name: Build ${{ matrix.platform }} + needs: build-frontend + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - { goos: linux, goarch: amd64, platform: linux-amd64 } + - { goos: linux, goarch: arm64, platform: linux-arm64 } + - { goos: linux, goarch: arm, goarm: '7', platform: linux-arm } + - { goos: darwin, goarch: amd64, platform: darwin-amd64 } + - { goos: darwin, goarch: arm64, platform: darwin-arm64 } + - { goos: windows, goarch: amd64, platform: windows-amd64 } + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: ${{ env.GO_VERSION_FILE }} + cache: true + + - name: Download frontend dist + uses: actions/download-artifact@v4 + with: + name: frontend-dist + path: pb_public/ + + - name: Build binary + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + GOARM: ${{ matrix.goarm }} + CGO_ENABLED: '0' + VERSION: ${{ github.ref_name }} + BUILD_TIME: ${{ github.event.head_commit.timestamp }} + run: | + PLATFORM="${{ matrix.platform }}" + OUTPUT_DIR="dist/${PLATFORM}" + mkdir -p "${OUTPUT_DIR}" + + BINARY="${{ env.APP_NAME }}" + [ "$GOOS" = "windows" ] && BINARY="${BINARY}.exe" + + go build \ + -trimpath \ + -ldflags "-s -w -X main.Version=${VERSION} -X main.BuildTime=${BUILD_TIME}" \ + -o "${OUTPUT_DIR}/${BINARY}" \ + main.go + + - name: Package archive + run: | + PLATFORM="${{ matrix.platform }}" + VERSION="${{ github.ref_name }}" + OUTPUT_DIR="dist/${PLATFORM}" + ARCHIVE_NAME="${{ env.APP_NAME }}-${VERSION}-${PLATFORM}" + + mkdir -p artifacts + cd "${OUTPUT_DIR}" + + if [ "${{ matrix.goos }}" = "windows" ]; then + zip "../../artifacts/${ARCHIVE_NAME}.zip" "${{ env.APP_NAME }}.exe" + else + tar -czf "../../artifacts/${ARCHIVE_NAME}.tar.gz" "${{ env.APP_NAME }}" + fi + + cd ../.. + ls -lh artifacts/ + + - name: Upload binary artifact + uses: actions/upload-artifact@v4 + with: + name: binary-${{ matrix.platform }} + path: artifacts/ + retention-days: 1 + + # ────────────────────────────────────────────── + # Job 3: Create GitHub Release + # ────────────────────────────────────────────── + create-release: + name: Create GitHub Release + needs: build-binaries + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Download all binary artifacts + uses: actions/download-artifact@v4 + with: + pattern: binary-* + merge-multiple: true + path: release-assets/ + + - name: Generate checksums + run: | + cd release-assets + sha256sum * > checksums.txt + cat checksums.txt + + - name: Create Release + uses: softprops/action-gh-release@v2 + with: + files: release-assets/* + generate_release_notes: true + draft: false + prerelease: ${{ contains(github.ref_name, '-') }} + fail_on_unmatched_files: true + + # ────────────────────────────────────────────── + # Job 4: Build & push multi-arch Docker image + # (Dockerfile handles frontend build internally) + # ────────────────────────────────────────────── + docker: + name: Docker (multi-arch) + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=raw,value=latest,enable=${{ !contains(github.ref_name, '-') }} + labels: | + org.opencontainers.image.title=frpc-hub + org.opencontainers.image.description=FRP client hub with web UI + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + VERSION=${{ github.ref_name }} + BUILD_TIME=${{ github.event.head_commit.timestamp }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/build/Dockerfile b/Dockerfile similarity index 100% rename from build/Dockerfile rename to Dockerfile diff --git a/build/docker-build.sh b/build/docker-build.sh index c339866..488fc89 100755 --- a/build/docker-build.sh +++ b/build/docker-build.sh @@ -104,8 +104,8 @@ else FULL_IMAGE_NAME="${IMAGE_NAME}" fi -# Navigate to build directory -cd "$(dirname "$0")" +# Navigate to project root +cd "$(dirname "$0")/.." print_header "Docker Build for ${IMAGE_NAME}" print_info "Version: ${VERSION}" @@ -161,7 +161,7 @@ fi # Build the image print_header "Building Docker Image" -docker buildx build "${BUILD_ARGS[@]}" .. +docker buildx build "${BUILD_ARGS[@]}" . if [ $? -eq 0 ]; then print_header "Build Successful!" diff --git a/deploy/docker-compose.build.yml b/deploy/docker-compose.build.yml index 27c8147..a6b32c7 100644 --- a/deploy/docker-compose.build.yml +++ b/deploy/docker-compose.build.yml @@ -7,7 +7,7 @@ services: frpc-hub: build: context: .. - dockerfile: build/Dockerfile + dockerfile: Dockerfile args: VERSION: ${VERSION:-latest} BUILD_TIME: ${BUILD_TIME:-$(date -u '+%Y-%m-%d_%H:%M:%S')} diff --git a/site/package.json b/site/package.json index 376264f..ee640b9 100644 --- a/site/package.json +++ b/site/package.json @@ -1,7 +1,7 @@ { - "name": "site", + "name": "frpc-hub-web", "private": true, - "version": "0.0.0", + "version": "1.0.0", "type": "module", "scripts": { "dev": "vite",