Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

ci: full refacto (native workers, seperate build, etc) (#185)

Andrii Andrushchyshyne80eeaa08ead
diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml
index 34096353f..09067f558 100644
--- a/.github/workflows/docker-publish.yml
+++ b/.github/workflows/docker-publish.yml
@@ -2,79 +2,289 @@ name: Docker Publish
on:
push:
+ branches:
+ - master # Trigger workflow on push to master branch
tags:
- - "v*"
+ - 'v*' # Trigger workflow on version tag push (e.g., v1.2.3)
jobs:
- build-and-push:
- runs-on: ubuntu-latest
+
+ client:
+
+ name: Build Client Images
+
permissions:
- contents: read
- packages: write
+ contents: read # Allows reading repository contents
+ packages: write # Required to push images to GitHub Container Registry (GHCR)
+
+ strategy:
+ fail-fast: false # Continue building other platforms even if one fails
+ matrix:
+ include:
+ - os: ubuntu-latest
+ arch: amd64
+ platform: linux/amd64 # x86_64 architecture
+ - os: ubuntu-24.04-arm
+ arch: arm64
+ platform: linux/arm64 # ARM architecture
+
+ runs-on: ${{ matrix.os }} # Use the selected OS from the matrix
steps:
+
- name: Checkout repository
- uses: actions/checkout@v4
+ uses: actions/checkout@v4 # Checkout the code from the repository
- # 1) Register QEMU emulators for cross-platform builds
- - name: Set up QEMU
- uses: docker/setup-qemu-action@v2
+ - name: Log in to GitHub Container Registry
+ uses: docker/login-action@v3
+ with:
+ registry: ghcr.io # GitHub Container Registry URL
+ username: ${{ github.repository_owner }} # GitHub repository owner
+ password: ${{ secrets.GITHUB_TOKEN }} # Token to authenticate with GHCR
- # 2) Create and use a Docker Buildx builder instance
- name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v3
+ uses: docker/setup-buildx-action@v3 # Set up Docker Buildx for building multi-platform images
+
+ - name: Prepare Environment Variables for Build
+ run: |
+ # Define platform pair (e.g., linux-amd64) and save to environment variables
+ platform=${{ matrix.platform }}
+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
+
+ # Define repository owner in lowercase for GHCR and save to env
+ echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
+
+ # Set short git commit SHA and branch name, then save to env
+ calculatedSha=$(git rev-parse --short HEAD)
+ branchName=$(git rev-parse --abbrev-ref HEAD)
+ echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
+ echo "COMMIT_BRANCH=$branchName" >> $GITHUB_ENV
+
+ - name: Extract metadata (tags, labels) for Docker
+ id: meta
+ uses: docker/metadata-action@v5
+ with:
+ images: ghcr.io/${{ env.REPO_OWNER }}/rybbit-client
+
+ - name: Build and push client by digest
+ id: build
+ uses: docker/build-push-action@v6
with:
- buildkitd-flags: --debug
+ context: ./client # Path to the Dockerfile for the client
+ file: ./client/Dockerfile # Dockerfile for the client
+ platforms: ${{ matrix.platform }} # Build the image for the platform specified in the matrix
+ labels: ${{ steps.meta.outputs.labels }}
+ # Push image by digest only; manifest list will be created later
+ outputs: type=image,"name=ghcr.io/${{ env.REPO_OWNER }}/rybbit-client",push-by-digest=true,name-canonical=true,push=true
+
+ - name: Export digests
+ run: |
+ # Create a temporary directory to store digests
+ mkdir -p /tmp/digests
+ # Save the digests of client images
+ echo "${{ steps.build.outputs.digest }}" > /tmp/digests/client-${{ env.PLATFORM_PAIR }}
+
+ - name: Upload digest
+ uses: actions/upload-artifact@v4
+ with:
+ name: digests-client-${{ env.PLATFORM_PAIR }} # Name of the artifact (unique per platform)
+ path: /tmp/digests/* # Path to the digests files
+ if-no-files-found: error # Fail if no files are found
+ retention-days: 1 # Retain artifacts for 1 day
+
+ backend:
+
+ name: Build Backend Images
+
+ permissions:
+ contents: read # Allows reading repository contents
+ packages: write # Required to push images to GitHub Container Registry (GHCR)
+
+ strategy:
+ fail-fast: false # Continue building other platforms even if one fails
+ matrix:
+ include:
+ - os: ubuntu-latest
+ arch: amd64
+ platform: linux/amd64 # x86_64 architecture
+ - os: ubuntu-24.04-arm
+ arch: arm64
+ platform: linux/arm64 # ARM architecture
+
+ runs-on: ${{ matrix.os }} # Use the selected OS from the matrix
+
+ steps:
+
+ - name: Checkout repository
+ uses: actions/checkout@v4 # Checkout the code from the repository
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
- registry: ghcr.io
- username: ${{ github.repository_owner }}
- password: ${{ secrets.GITHUB_TOKEN }}
+ registry: ghcr.io # GitHub Container Registry URL
+ username: ${{ github.repository_owner }} # GitHub repository owner
+ password: ${{ secrets.GITHUB_TOKEN }} # Token to authenticate with GHCR
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v3 # Set up Docker Buildx for building multi-platform images
+
+ - name: Prepare Environment Variables for Build
+ run: |
+ # Define platform pair (e.g., linux-amd64) and save to environment variables
+ platform=${{ matrix.platform }}
+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- - name: Extract metadata (tags, labels) for Docker - Backend
- id: meta_backend
+ # Define repository owner in lowercase for GHCR and save to env
+ echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
+
+ # Set short git commit SHA and branch name, then save to env
+ calculatedSha=$(git rev-parse --short HEAD)
+ branchName=$(git rev-parse --abbrev-ref HEAD)
+ echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
+ echo "COMMIT_BRANCH=$branchName" >> $GITHUB_ENV
+
+ - name: Extract metadata (tags, labels) for Docker
+ id: meta
uses: docker/metadata-action@v5
with:
- images: ghcr.io/${{ github.repository_owner }}/rybbit-backend
- tags: |
- type=raw,value=${{ github.ref_name }}
- type=raw,value=latest
- type=sha
+ images: ghcr.io/${{ env.REPO_OWNER }}/rybbit-backend
- - name: Build and push Backend Docker image (multi-arch)
+ - name: Build and push backend by digest
+ id: build
uses: docker/build-push-action@v6
with:
- context: ./server
- file: ./server/Dockerfile
- push: true
- platforms: linux/amd64,linux/arm64
- tags: ${{ steps.meta_backend.outputs.tags }}
- labels: ${{ steps.meta_backend.outputs.labels }}
- # Optional: enable build cache for speed
- # cache-from: type=gha,scope=${{ github.workflow }}-backend
- # cache-to: type=gha,scope=${{ github.workflow }}-backend,mode=max
-
- - name: Extract metadata (tags, labels) for Docker - Client
- id: meta_client
+ context: ./server # Path to the Dockerfile for the backend
+ file: ./server/Dockerfile # Dockerfile for the backend
+ platforms: ${{ matrix.platform }} # Build the image for the platform specified in the matrix
+ labels: ${{ steps.meta.outputs.labels }}
+ # Push image by digest only; manifest list will be created later
+ outputs: type=image,"name=ghcr.io/${{ env.REPO_OWNER }}/rybbit-backend",push-by-digest=true,name-canonical=true,push=true
+
+ - name: Export digests
+ run: |
+ # Create a temporary directory to store digests
+ mkdir -p /tmp/digests
+ # Save the digests of backend images
+ echo "${{ steps.build.outputs.digest }}" > /tmp/digests/backend-${{ env.PLATFORM_PAIR }}
+
+ - name: Upload digest
+ uses: actions/upload-artifact@v4
+ with:
+ name: digests-backend-${{ env.PLATFORM_PAIR }} # Name of the artifact (unique per platform)
+ path: /tmp/digests/* # Path to the digests files
+ if-no-files-found: error # Fail if no files are found
+ retention-days: 1 # Retain artifacts for 1 day
+
+ merge:
+
+ name: Merge Images and Push
+
+ runs-on: ubuntu-latest
+
+ needs:
+ - backend # Wait for client before running the merge job
+ - client # Wait for client before running the merge job
+
+ steps:
+
+ - name: Download digests
+ uses: actions/download-artifact@v4
+ with:
+ path: /tmp/digests # Download the digests to the /tmp/digests directory
+ pattern: digests-* # Match all artifacts starting with 'digests-'
+ merge-multiple: true # Merge all platform digests into one folder
+
+ - name: Prepare Environment Variables for Merge
+ run: |
+ # Define repository owner in lowercase for GHCR and save to env
+ echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
+
+ - name: Log in to GitHub Container Registry
+ uses: docker/login-action@v3
+ with:
+ registry: ghcr.io # GitHub Container Registry URL
+ username: ${{ github.repository_owner }} # GitHub repository owner
+ password: ${{ secrets.GITHUB_TOKEN }} # Token to authenticate with GHCR
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v3 # Set up Docker Buildx for multi-platform builds
+
+ - name: Extract client metadata (tags, labels)
+ id: client-meta
uses: docker/metadata-action@v5
with:
- images: ghcr.io/${{ github.repository_owner }}/rybbit-client
+ images: ghcr.io/${{ env.REPO_OWNER }}/rybbit-client
tags: |
- type=raw,value=${{ github.ref_name }}
- type=raw,value=latest
+ # Add 'latest' tag only if this is a version tag (e.g., v1.2.3)
+ ${{ startsWith(github.ref, 'refs/tags/v') && 'type=raw,value=latest,priority=901' || '' }}
+
+ # Add the version tag itself (e.g., v1.2.3)
+ ${{ startsWith(github.ref, 'refs/tags/v') && format('type=raw,value={0},priority=900', github.ref_name) || '' }}
+
+ # Always add 'edge' tag for build on latest commit indicator
+ type=edge
+
+ # Always add short SHA tag for traceability
type=sha
- - name: Build and push Client Docker image (multi-arch)
- uses: docker/build-push-action@v6
+ - name: Create manifest list and push client images
+ working-directory: /tmp/digests # Change working directory to /tmp/digests
+ run: |
+ digests=""
+
+ # Collect all the digests for the client component
+ for file in client-*; do
+ digest=$(cat "$file")
+ digests+="ghcr.io/${{ env.REPO_OWNER }}/rybbit-client@${digest} "
+ done
+
+ # Create a manifest list and push to GHCR
+ docker buildx imagetools create \
+ $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
+ $digests
+
+ - name: Extract backend metadata (tags, labels)
+ id: backend-meta
+ uses: docker/metadata-action@v5
with:
- context: ./client
- file: ./client/Dockerfile
- push: true
- platforms: linux/amd64,linux/arm64
- tags: ${{ steps.meta_client.outputs.tags }}
- labels: ${{ steps.meta_client.outputs.labels }}
- # Optional: enable build cache for speed
- # cache-from: type=gha,scope=${{ github.workflow }}-client
- # cache-to: type=gha,scope=${{ github.workflow }}-client,mode=max
\ No newline at end of file
+ images: ghcr.io/${{ env.REPO_OWNER }}/rybbit-backend
+ tags: |
+ # Add 'latest' tag only if this is a version tag (e.g., v1.2.3)
+ ${{ startsWith(github.ref, 'refs/tags/v') && 'type=raw,value=latest,priority=901' || '' }}
+
+ # Add the version tag itself (e.g., v1.2.3)
+ ${{ startsWith(github.ref, 'refs/tags/v') && format('type=raw,value={0},priority=900', github.ref_name) || '' }}
+
+ # Always add 'edge' tag for build on latest commit indicator
+ type=edge
+
+ # Always add short SHA tag for traceability
+ type=sha
+
+ - name: Create manifest list and push backend images
+ working-directory: /tmp/digests # Change working directory to /tmp/digests
+ run: |
+ digests=""
+
+ # Collect all the digests for the backend component
+ for file in backend-*; do
+ digest=$(cat "$file")
+ digests+="ghcr.io/${{ env.REPO_OWNER }}/rybbit-backend@${digest} "
+ done
+
+ # Create a manifest list and push to GHCR
+ docker buildx imagetools create \
+ $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
+ $digests
+
+ - name: Inspect client images
+ run: |
+ # Inspect the client image to verify the push
+ echo "Inspecting client..."
+ docker buildx imagetools inspect ghcr.io/${{ env.REPO_OWNER }}/rybbit-client:${{ steps.client-meta.outputs.version }}
+
+ - name: Inspect backend images
+ run: |
+ # Inspect the backend image to verify the push
+ echo "Inspecting backend..."
+ docker buildx imagetools inspect ghcr.io/${{ env.REPO_OWNER }}/rybbit-backend:${{ steps.backend-meta.outputs.version }}