Skip to content

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

ci: standardize formatting and improve readability in docker-publish workflow

Bill Yang3bbfbb6d5804
diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml
index d1cf302f7..4c031c091 100644
--- a/.github/workflows/docker-publish.yml
+++ b/.github/workflows/docker-publish.yml
@@ -3,47 +3,47 @@ name: Docker Publish
on:
push:
branches:
- - master # Trigger workflow on push to master branch
+ - master # Trigger workflow on push to master branch
tags:
- - 'v*' # Trigger workflow on version tag push (e.g., v1.2.3)
+ - "v*" # Trigger workflow on version tag push (e.g., v1.2.3)
+ pull_request:
+ branches:
+ - master # Trigger workflow on pull requests to master branch
jobs:
-
client:
-
name: Build Client Images
permissions:
- contents: read # Allows reading repository contents
- packages: write # Required to push images to GitHub Container Registry (GHCR)
+ 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
+ fail-fast: false # Continue building other platforms even if one fails
matrix:
include:
- os: ubuntu-latest
arch: amd64
- platform: linux/amd64 # x86_64 architecture
+ platform: linux/amd64 # x86_64 architecture
- os: ubuntu-24.04-arm
arch: arm64
- platform: linux/arm64 # ARM architecture
+ platform: linux/arm64 # ARM architecture
- runs-on: ${{ matrix.os }} # Use the selected OS from the matrix
+ 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
+ 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 # GitHub Container Registry URL
- username: ${{ github.repository_owner }} # GitHub repository owner
- password: ${{ secrets.GITHUB_TOKEN }} # Token to authenticate with GHCR
+ 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
+ uses: docker/setup-buildx-action@v3 # Set up Docker Buildx for building multi-platform images
- name: Prepare Environment Variables for Build
run: |
@@ -70,9 +70,9 @@ jobs:
id: build
uses: docker/build-push-action@v6
with:
- 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
+ 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
@@ -87,46 +87,44 @@ jobs:
- 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
+ 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)
+ 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
+ fail-fast: false # Continue building other platforms even if one fails
matrix:
include:
- os: ubuntu-latest
arch: amd64
- platform: linux/amd64 # x86_64 architecture
+ platform: linux/amd64 # x86_64 architecture
- os: ubuntu-24.04-arm
arch: arm64
- platform: linux/arm64 # ARM architecture
+ platform: linux/arm64 # ARM architecture
- runs-on: ${{ matrix.os }} # Use the selected OS from the matrix
+ 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
+ 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 # GitHub Container Registry URL
- username: ${{ github.repository_owner }} # GitHub repository owner
- password: ${{ secrets.GITHUB_TOKEN }} # Token to authenticate with GHCR
+ 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
+ uses: docker/setup-buildx-action@v3 # Set up Docker Buildx for building multi-platform images
- name: Prepare Environment Variables for Build
run: |
@@ -153,9 +151,9 @@ jobs:
id: build
uses: docker/build-push-action@v6
with:
- 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
+ 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
@@ -170,33 +168,31 @@ jobs:
- 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
+ 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
+ - backend # Wait for client before running the merge job
+ - client # Wait for client before running the merge job
permissions:
- contents: read # Allows reading repository contents
- packages: write # Required to push images to GitHub Container Registry (GHCR)
+ contents: read # Allows reading repository contents
+ packages: write # Required to push images to GitHub Container Registry (GHCR)
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
+ 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: |
@@ -206,12 +202,12 @@ jobs:
- 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
+ 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
+ uses: docker/setup-buildx-action@v3 # Set up Docker Buildx for multi-platform builds
- name: Extract client metadata (tags, labels)
id: client-meta
@@ -221,21 +217,24 @@ jobs:
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) || '' }}
-
+
+ # For pull requests, add PR number tag
+ ${{ github.event_name == 'pull_request' && format('type=raw,value=pr-{0},priority=850', github.event.number) || '' }}
+
# Always add 'edge' tag for build on latest commit indicator
type=edge,priority=800
-
+
# Always add short SHA tag for traceability
type=sha,priority=700
- name: Create manifest list and push client images
- working-directory: /tmp/digests # Change working directory to /tmp/digests
+ 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")
@@ -255,21 +254,24 @@ jobs:
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) || '' }}
-
+
+ # For pull requests, add PR number tag
+ ${{ github.event_name == 'pull_request' && format('type=raw,value=pr-{0},priority=850', github.event.number) || '' }}
+
# Always add 'edge' tag for build on latest commit indicator
type=edge,priority=800
-
+
# Always add short SHA tag for traceability
type=sha,priority=700
- name: Create manifest list and push backend images
- working-directory: /tmp/digests # Change working directory to /tmp/digests
+ 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")