Skip to content

Build and Push Docker Images #5

Build and Push Docker Images

Build and Push Docker Images #5

Workflow file for this run

name: Build and Push Docker 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.0"
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- 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 version from tag
if: github.event_name == 'release'
id: extract_version_release
run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Set version from workflow_dispatch input
if: github.event_name == 'workflow_dispatch'
id: extract_version_dispatch
run: echo "version=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
- name: Set version from branch name
if: github.event_name == 'push'
id: extract_version_push
run: |
if [[ "${GITHUB_REF}" == refs/heads/release-* ]]; then
BRANCH_NAME=${GITHUB_REF#refs/heads/}
VERSION=${BRANCH_NAME#release-}
echo "version=$VERSION" >> $GITHUB_ENV
fi
- 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={{major}}
type=semver,pattern=release-{{raw}}
type=sha
type=raw,value=${{ github.event.inputs.tag }}
- name: Build and push Docker images
run: |
ROOT_DIR="build/images"
for dir in "$ROOT_DIR"/*/; do
Dockerfile=$(ls "$dir" | grep -iE '(^dockerfile$|\.dockerfile$)' | head -n 1)
if [ -f "$dir/$Dockerfile" ]; then
IMAGE_NAME=$(basename "$dir")
echo "Building Docker image for $IMAGE_NAME with tags ${{ steps.meta.outputs.tags }}..."
docker buildx build --platform linux/amd64,linux/arm64 \
--tag ${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME:${{ steps.meta.outputs.tags }} \
--tag ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:${{ steps.meta.outputs.tags }} \
--tag registry.cn-hangzhou.aliyuncs.com/openimsdk/$IMAGE_NAME:${{ steps.meta.outputs.tags }} \
--push "$dir"
else
echo "No .dockerfile found in $dir"
fi
done