Skip to content

Build Docker Images #351

Build Docker Images

Build Docker Images #351

Workflow file for this run

name: Build Docker Images
on:
workflow_dispatch:
inputs:
tag:
description: 'tag for the Docker image'
required: true
default: 'latest'
push:
branches:
- 'main'
jobs:
define-matrix:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.set_tag.outputs.tag }}
tag_cn: ${{ steps.set_tag.outputs.tag_cn }}
build_targets: ${{ steps.get_build_matrix.outputs.build_targets }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up tag
id: set_tag
run: |
if [ -n "${{ inputs.tag }}" ]; then
tag=${{ inputs.tag }}
else
tag=${{ github.sha }}::6
fi
tag_cn=$tag-cn
echo "tag=$tag" >> $GITHUB_OUTPUT
echo "tag_cn=$tag_cn" >> $GITHUB_OUTPUT
- name: Get build matrix
id: get_build_matrix
run: |
if [ -n "${{ inputs.tag }}" ]; then
build_targets=$(bash script/get_all_dockerfile.sh)
else
build_targets=$(bash script/get_changed_dockerfile.sh ${{ github.event.before }} ${{ github.sha }})
fi
echo "build_targets=$build_targets" >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: define-matrix
strategy:
fail-fast: false
matrix:
build_target: ${{ fromJson(needs.define-matrix.outputs.build_targets) }}
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
run: |
echo "build_target=${{ matrix.build_target }}"
echo "tag=${{ needs.define-matrix.outputs.tag }}"
echo "tag_cn=${{ needs.define-matrix.outputs.tag_cn }}"
image_name=$(bash script/get_image_name.sh ${{ github.repository_owner }} "${{ matrix.build_target }}" "${{ needs.define-matrix.outputs.tag }}")
image_name_cn=$(bash script/get_image_name.sh ${{ github.repository_owner }} "${{ matrix.build_target }}" "${{ needs.define-matrix.outputs.tag_cn }}")
echo "image_name=$image_name" >> $GITHUB_OUTPUT
echo "image_name_cn=$image_name_cn" >> $GITHUB_OUTPUT
echo "building image $image_name"
is_cn="0" bash script/build_and_push_images.sh "${{ matrix.build_target }}" "$image_name" $is_cn
echo "building image $image_name_cn"
is_cn="1" bash script/build_and_push_images.sh "${{ matrix.build_target }}" "$image_name_cn" $is_cn
# TODO: generate runtime yaml and json