-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathpost-merge-container-update-mlir-tensorrt.yml
More file actions
140 lines (121 loc) · 5.07 KB
/
Copy pathpost-merge-container-update-mlir-tensorrt.yml
File metadata and controls
140 lines (121 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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"]
paths:
- "mlir-tensorrt/.devcontainer/**/devcontainer.json"
- "mlir-tensorrt/.devcontainer/generate.py"
- "mlir-tensorrt/build_tools/docker/*"
env:
REGISTRY: ghcr.io
IMAGE_PREFIX: ghcr.io/nvidia/tensorrt-incubator/mlir-tensorrt
VERSION_SUFFIX: "0.1"
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@v6
- name: Discover container configurations
id: set-matrix
run: |
# Find all build.json files under mlir-tensorrt/.devcontainer
configs=()
for file in mlir-tensorrt/.devcontainer/*/devcontainer.json; do
# Skip files where the directory contains the suffix "-prebuilt"
if [[ -f "$file" && ! "$(dirname "$file")" =~ -prebuilt$ ]]; then
# Extract configuration from build.json
name=$(jq -r '.name' "$file")
base_image=$(jq -r '.build.args.BASE_IMAGE' "$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 linux_distro "$linux_distro" \
--arg llvm_version "$llvm_version" \
--arg dockerfile "$dockerfile" \
--arg build_json "$file" \
'{name: $name, base_image: $base_image, 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@v6
- 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/build_tools/docker
file: ${{ matrix.dockerfile }}
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ env.IMAGE_PREFIX }}:${{ matrix.name }}-${{ env.VERSION_SUFFIX }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BASE_IMAGE=${{ matrix.base_image }}
LINUX_DISTRO=${{ matrix.linux_distro }}
LLVM_VERSION=${{ matrix.llvm_version }}