name: Docker Image CI on: push: tags: - 'v*.*.*' # Semver tags only, e.g. v1.0.0 workflow_dispatch: workflow_run: workflows: ["Build Base Image"] types: - completed jobs: version: name: Resolve version runs-on: ubuntu-latest outputs: version: ${{ steps.meta.outputs.version }} is_version: ${{ steps.meta.outputs.is_version }} steps: - id: meta run: | if [[ "$GITHUB_REF" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then echo "version=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT" echo "is_version=true" >> "$GITHUB_OUTPUT" else echo "version=latest" >> "$GITHUB_OUTPUT" echo "is_version=false" >> "$GITHUB_OUTPUT" fi release: name: Build and push ${{ matrix.name }} needs: version runs-on: ubuntu-latest strategy: fail-fast: false matrix: include: - name: xiaozhi-server file: Dockerfile-server tag_prefix: server cache_scope: docker-server - name: manager-web file: Dockerfile-web tag_prefix: web cache_scope: docker-web permissions: packages: write contents: write id-token: write issues: write steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 with: driver-opts: | network=host - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ github.token }} # linux/arm64 was slow under QEMU; add native ARM runners or restore: platforms: linux/amd64,linux/arm64 - name: Build and push ${{ matrix.name }} uses: docker/build-push-action@v6 with: context: . file: ${{ matrix.file }} push: true tags: ${{ needs.version.outputs.is_version == 'true' && format('ghcr.io/{0}:{1}_{2},ghcr.io/{0}:{1}_latest', github.repository, matrix.tag_prefix, needs.version.outputs.version) || format('ghcr.io/{0}:{1}_latest', github.repository, matrix.tag_prefix) }} platforms: linux/amd64 cache-from: type=gha,scope=${{ matrix.cache_scope }} cache-to: type=gha,mode=max,scope=${{ matrix.cache_scope }} build-args: | BUILDKIT_PROGRESS=plain SERVER_BASE_IMAGE=ghcr.io/${{ github.repository }}:server-base