part 2 #93
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Package | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build-and-package: | |
| name: Build and Package | |
| strategy: | |
| matrix: | |
| include: | |
| - arch: amd64 | |
| runner: ubuntu-24.04 | |
| target: x86_64-unknown-linux-musl | |
| cross: false | |
| - arch: arm64 | |
| runner: ubuntu-24.04 | |
| target: aarch64-unknown-linux-musl | |
| cross: true | |
| runs-on: ${{ matrix.runner }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v2 | |
| with: | |
| version: 10 | |
| run_install: false | |
| - name: Get pnpm store directory | |
| id: pnpm-cache | |
| shell: bash | |
| run: | | |
| echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT | |
| - name: Setup pnpm cache | |
| uses: actions/cache@v3 | |
| with: | |
| path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} | |
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm-store- | |
| - name: Install frontend dependencies | |
| run: | | |
| cd ./frontend | |
| pnpm install | |
| - name: Build frontend | |
| run: | | |
| cd ./frontend | |
| pnpm build | |
| - name: Install stable Rust toolchain | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| profile: minimal | |
| toolchain: stable | |
| target: ${{ matrix.target }} | |
| override: true | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y musl-tools pkg-config libssl-dev | |
| - name: Install Sentry CLI | |
| run: | | |
| npm install -g @sentry/cli | |
| - name: Rust Cache | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| prefix-key: ${{ runner.os }}-${{ matrix.target }} | |
| - name: Build release binary | |
| uses: actions-rs/cargo@v1 | |
| with: | |
| use-cross: ${{ matrix.cross }} | |
| command: build | |
| args: --release --target ${{ matrix.target }} | |
| - name: Process release binary | |
| run: | | |
| sentry-cli --url ${{ secrets.SENTRY_URL }} debug-files upload --include-sources --org ${{ secrets.SENTRY_ORG }} --project ${{ secrets.SENTRY_PROJECT }} --auth-token ${{ secrets.SENTRY_AUTH_TOKEN }} target/${{ matrix.target }}/release/api | |
| mkdir -p dist/${{ matrix.arch }} | |
| cp target/${{ matrix.target }}/release/api dist/${{ matrix.arch }}/api | |
| - name: Strip release binary (x86_64 only) | |
| if: matrix.arch == 'amd64' | |
| run: | | |
| strip dist/${{ matrix.arch }}/api | |
| - name: Upload binary artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: api-${{ matrix.arch }} | |
| path: dist/${{ matrix.arch }}/api | |
| retention-days: 1 | |
| create-multiarch-image: | |
| name: Create multi-arch Docker image | |
| needs: build-and-package | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download all binary artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: dist | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v2 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Prepare binaries | |
| run: | | |
| chmod +x dist/api-amd64/api | |
| chmod +x dist/api-arm64/api | |
| mkdir -p .docker/amd64 .docker/arm64 | |
| cp dist/api-amd64/api .docker/amd64/api | |
| cp dist/api-arm64/api .docker/arm64/api | |
| cp entrypoint.sh .docker/ | |
| - name: Build and push multi-arch Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ghcr.io/mcjars/www:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |