[mlir-tensorrt] Update GitHub actions MLIR-TRT container build logic #15
Workflow file for this run
This file contains hidden or 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: Post-merge container update mlir-tensorrt | |
| # This workflow builds and pushes Docker dev containers for mlir-tensorrt | |
| # based on the build.json configurations in .devcontainer directories. | |
| on: | |
| push: | |
| branches: ["main", "mlir-trt-container-build-updates"] | |
| paths: | |
| - "mlir-tensorrt/.devcontainer/**/build.json" | |
| - "mlir-tensorrt/.devcontainer/**/devcontainer.json" | |
| - "mlir-tensorrt/build_tools/docker/Dockerfile" | |
| - "mlir-tensorrt/build_tools/scripts/*.sh" | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_PREFIX: ghcr.io/nvidia/tensorrt-incubator/mlir-tensorrt | |
| jobs: | |
| # First job: discover all build.json files and create a matrix | |
| discover-containers: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Discover container configurations | |
| id: set-matrix | |
| run: | | |
| # Find all build.json files under mlir-tensorrt/.devcontainer | |
| configs=() | |
| for file in mlir-tensorrt/.devcontainer/**/build.json; do | |
| if [[ -f "$file" ]]; then | |
| # Extract configuration from build.json | |
| name=$(jq -r '.name' "$file") | |
| base_image=$(jq -r '.build.args.BASE_IMAGE' "$file") | |
| username=$(jq -r '.build.args.USERNAME' "$file") | |
| linux_distro=$(jq -r '.build.args.LINUX_DISTRO' "$file") | |
| llvm_version=$(jq -r '.build.args.LLVM_VERSION' "$file") | |
| dockerfile=$(jq -r '.build.dockerfile' "$file" | sed 's|\${localWorkspaceFolder}|mlir-tensorrt|g') | |
| # Create JSON object for this configuration (compact, single-line) | |
| config=$(jq -cn \ | |
| --arg name "$name" \ | |
| --arg base_image "$base_image" \ | |
| --arg username "$username" \ | |
| --arg linux_distro "$linux_distro" \ | |
| --arg llvm_version "$llvm_version" \ | |
| --arg dockerfile "$dockerfile" \ | |
| --arg build_json "$file" \ | |
| '{name: $name, base_image: $base_image, username: $username, linux_distro: $linux_distro, llvm_version: $llvm_version, dockerfile: $dockerfile, build_json: $build_json}') | |
| configs+=("$config") | |
| fi | |
| done | |
| # Create the matrix JSON (compact output for GITHUB_OUTPUT compatibility) | |
| if [[ ${#configs[@]} -eq 0 ]]; then | |
| echo "No build.json files found" | |
| echo "matrix={\"include\":[]}" >> $GITHUB_OUTPUT | |
| else | |
| matrix=$(printf '%s\n' "${configs[@]}" | jq -sc '{include: .}') | |
| echo "matrix=$matrix" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Display matrix | |
| run: | | |
| echo "Container build matrix:" | |
| echo '${{ steps.set-matrix.outputs.matrix }}' | jq . | |
| # Second job: build and push containers based on the matrix | |
| build-and-push: | |
| needs: discover-containers | |
| if: ${{ needs.discover-containers.outputs.matrix != '{"include":[]}' && fromJson(needs.discover-containers.outputs.matrix).include[0] != null }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJson(needs.discover-containers.outputs.matrix) }} | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| steps: | |
| # Based on https://stackoverflow.com/q/75536771 | |
| - name: Free disk space | |
| run: | | |
| sudo docker system prune -a -f | |
| sudo rm -rf \ | |
| /usr/share/dotnet "$AGENT_TOOLSDIRECTORY" /usr/local/lib/android /opt/ghc \ | |
| /usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \ | |
| /usr/lib/jvm | |
| sudo apt-get purge microsoft-edge-stable || true | |
| sudo apt-get purge google-cloud-cli || true | |
| sudo apt-get purge dotnet-sdk-* || true | |
| sudo apt-get purge google-chrome-stable || true | |
| sudo apt-get autoremove -y | |
| sudo apt-get autoclean -y | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| - name: Show disk usage | |
| run: df . -h | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log into registry ${{ env.REGISTRY }} | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.IMAGE_PREFIX }} | |
| - name: Build and push Docker image - ${{ matrix.name }} | |
| id: build-and-push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: mlir-tensorrt/ | |
| file: ${{ matrix.dockerfile }} | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: ${{ env.IMAGE_PREFIX }}:${{ matrix.name }}-latest | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| BASE_IMAGE=${{ matrix.base_image }} | |
| USERNAME=${{ matrix.username }} | |
| LINUX_DISTRO=${{ matrix.linux_distro }} | |
| LLVM_VERSION=${{ matrix.llvm_version }} |