This file contains 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 release services Images | |
on: | |
push: | |
branches: | |
- release-* | |
release: | |
types: [published] | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: "Tag version to be used for Docker image" | |
required: true | |
default: "v3.8.3" | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3.8.0 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3.3.0 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Log in to Aliyun Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: registry.cn-hangzhou.aliyuncs.com | |
username: ${{ secrets.ALIREGISTRY_USERNAME }} | |
password: ${{ secrets.ALIREGISTRY_TOKEN }} | |
- name: Extract metadata for Docker (tags, labels) | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
tags: | | |
type=ref,event=tag | |
type=schedule | |
type=ref,event=branch | |
type=semver,pattern={{version}} | |
type=semver,pattern=v{{version}} | |
# type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern=release-{{raw}} | |
type=sha | |
type=raw,value=${{ github.event.inputs.tag }} | |
- name: Build and push Docker images | |
run: | | |
IMG_DIR="build/images" | |
for dir in "$IMG_DIR"/*/; do | |
# Find Dockerfile or *.dockerfile in a case-insensitive manner | |
dockerfile=$(find "$dir" -maxdepth 1 -type f \( -iname 'dockerfile' -o -iname '*.dockerfile' \) | head -n 1) | |
if [ -n "$dockerfile" ] && [ -f "$dockerfile" ]; then | |
IMAGE_NAME=$(basename "$dir") | |
echo "Building Docker image for $IMAGE_NAME with tags:" | |
# Initialize tag arguments | |
tag_args=() | |
# Read each tag and append --tag arguments | |
while IFS= read -r tag; do | |
tag_args+=(--tag "${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME:$tag") | |
tag_args+=(--tag "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$tag") | |
tag_args+=(--tag "registry.cn-hangzhou.aliyuncs.com/openimsdk/$IMAGE_NAME:$tag") | |
done <<< "${{ steps.meta.outputs.tags }}" | |
# Build and push the Docker image with all tags | |
docker buildx build --platform linux/amd64,linux/arm64\ | |
--file "$dockerfile" \ | |
"${tag_args[@]}" \ | |
--push \ | |
"." | |
else | |
echo "No valid Dockerfile found in $dir" | |
fi | |
done | |
- name: Verify multi-platform support | |
run: | | |
MAX_RETRIES=2 | |
RETRY_DELAY=6 | |
for dir in build/images/*/; do | |
IMAGE_NAME=$(basename "$dir" | tr '[:upper:]' '[:lower:]') | |
for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n'); do | |
manifest=$(docker manifest inspect "${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME:$tag" || echo "error") | |
if [[ "$manifest" == "error" ]]; then | |
echo "Manifest not found for $IMAGE_NAME:$tag" | |
exit 1 | |
fi | |
amd64_found=$(echo "$manifest" | jq '.manifests[] | select(.platform.architecture == "amd64")') | |
arm64_found=$(echo "$manifest" | jq '.manifests[] | select(.platform.architecture == "arm64")') | |
echo "amd64_found is: $amd64_found" | |
echo "arm64_found is: $arm64_found" | |
if [[ -z "$amd64_found" ]]; then | |
echo "Multi-platform support check failed for $IMAGE_NAME:$tag - missing amd64" | |
# exit 1 | |
fi | |
# else | |
echo "Multi-platform support for $IMAGE_NAME:$tag - have amd64" | |
done | |
done | |
# build-and-arm: | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Checkout repository | |
# uses: actions/checkout@v4 | |
# - name: Set up Docker Buildx | |
# uses: docker/setup-buildx-action@v2 | |
# - name: set up qemu | |
# uses: docker/setup-qemu-action@v3.3.0 | |
# with: | |
# platforms: linux/arm64 | |
# - name: Log in to Docker Hub | |
# uses: docker/login-action@v2 | |
# with: | |
# username: ${{ secrets.DOCKER_USERNAME }} | |
# password: ${{ secrets.DOCKER_PASSWORD }} | |
# - name: Log in to GitHub Container Registry | |
# uses: docker/login-action@v2 | |
# with: | |
# registry: ghcr.io | |
# username: ${{ github.repository_owner }} | |
# password: ${{ secrets.GITHUB_TOKEN }} | |
# - name: Log in to Aliyun Container Registry | |
# uses: docker/login-action@v2 | |
# with: | |
# registry: registry.cn-hangzhou.aliyuncs.com | |
# username: ${{ secrets.ALIREGISTRY_USERNAME }} | |
# password: ${{ secrets.ALIREGISTRY_TOKEN }} | |
# - name: Extract metadata for Docker (tags, labels) | |
# id: meta | |
# uses: docker/metadata-action@v5 | |
# with: | |
# tags: | | |
# type=ref,event=tag | |
# type=schedule | |
# type=ref,event=branch | |
# type=semver,pattern={{version}} | |
# type=semver,pattern=v{{version}} | |
# type=semver,pattern=release-{{raw}} | |
# type=sha | |
# type=raw,value=${{ github.event.inputs.tag }} | |
# - name: Build and push Docker images | |
# run: | | |
# IMG_DIR="build/images" | |
# for dir in "$IMG_DIR"/*/; do | |
# # Find Dockerfile or *.dockerfile in a case-insensitive manner | |
# dockerfile=$(find "$dir" -maxdepth 1 -type f \( -iname 'dockerfile' -o -iname '*.dockerfile' \) | head -n 1) | |
# if [ -n "$dockerfile" ] && [ -f "$dockerfile" ]; then | |
# IMAGE_NAME=$(basename "$dir") | |
# echo "Building Docker image for $IMAGE_NAME with tags:" | |
# # Initialize tag arguments | |
# tag_args=() | |
# # Read each tag and append --tag arguments | |
# while IFS= read -r tag; do | |
# tag_args+=(--tag "${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME:$tag") | |
# # tag_args+=(--tag "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$tag") | |
# # tag_args+=(--tag "registry.cn-hangzhou.aliyuncs.com/openimsdk/$IMAGE_NAME:$tag") | |
# done <<< "${{ steps.meta.outputs.tags }}" | |
# # Build and push the Docker image with all tags | |
# docker buildx build --platform linux/arm64 \ | |
# --file "$dockerfile" \ | |
# "${tag_args[@]}" \ | |
# --push \ | |
# "." | |
# else | |
# echo "No valid Dockerfile found in $dir" | |
# fi | |
# done | |
# - name: Verify multi-platform support | |
# run: | | |
# MAX_RETRIES=6 | |
# RETRY_DELAY=10 | |
# for ((i=1; i<=MAX_RETRIES; i++)); do | |
# manifest=$(docker manifest inspect "${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME:$tag" || echo "error") | |
# if [[ "$manifest" != "error" ]]; then | |
# break | |
# fi | |
# if [[ $i -eq $MAX_RETRIES ]]; then | |
# echo "Manifest not found for $IMAGE_NAME:$tag after $MAX_RETRIES retries" | |
# exit 1 | |
# fi | |
# echo "Retry $i/$MAX_RETRIES: Manifest not found for $IMAGE_NAME:$tag, retrying in $RETRY_DELAY seconds..." | |
# sleep $RETRY_DELAY | |
# done | |
# for dir in build/images/*/; do | |
# IMAGE_NAME=$(basename "$dir" | tr '[:upper:]' '[:lower:]') | |
# for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n'); do | |
# manifest=$(docker manifest inspect "${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME:$tag" || echo "error") | |
# if [[ "$manifest" == "error" ]]; then | |
# echo "Manifest not found for $IMAGE_NAME:$tag" | |
# exit 1 | |
# fi | |
# arm64_found=$(echo "$manifest" | jq '.manifests[] | select(.platform.architecture == "arm64")') | |
# echo "arm64_found is: $arm64_found" | |
# if [[ -z "$arm64_found" ]]; then | |
# echo "Multi-platform support check failed for $IMAGE_NAME:$tag - missing arm64" | |
# exit 1 | |
# fi | |
# # else | |
# echo "Multi-platform support for $IMAGE_NAME:$tag - have arm64" | |
# done | |
# done |