11name : Build Docker
22
33on :
4+ workflow_dispatch :
45 push :
5- branches : [ amd-staging, amd-mainline, release/** ]
6+ branches : [ amd-staging ]
67 paths :
78 - ' Dockerfiles/**'
8- - ' .github/workflows/** '
9+ - ' .github/workflows/build_docker.yml '
910 pull_request :
1011 branches : [ amd-staging, amd-mainline, release/** ]
1112 paths :
1213 - ' Dockerfiles/**'
13- - ' .github/workflows/** '
14+ - ' .github/workflows/build_docker.yml '
1415
1516permissions :
1617 contents : read
2526 IMAGE_PREFIX : ${{ github.repository }}
2627
2728jobs :
28- find-dockerfiles :
29+ find-dockerfiles :
2930 name : Find Dockerfiles
3031 runs-on : ubuntu-latest
31- outputs :
32+ outputs :
3233 files : ${{ steps.find-files.outputs.files }}
33- steps :
34- - name : Checkout repository
35- uses : actions/checkout@v4
36- - name : Find Dockerfiles
37- id : find-files
38- run : |
39- echo "## Finding all Dockerfiles in the 'Dockerfiles/' directory"
40- FILES=$(find Dockerfiles/ -type f -printf "%f\n" | grep .*Dockerfile)
41- echo "Found Dockerfiles:"
42- echo "$FILES"
43- # Convert the array to JSON array
44- JSON_ARRAY=$(printf '%s\n' "${FILES[@]}" | jq -R . | jq -s . | jq -c .)
34+ steps :
35+ - name : Checkout repository
36+ uses : actions/checkout@v4
37+ - name : Find Dockerfiles
38+ id : find-files
39+ run : |
40+ echo "## Finding all Dockerfiles in the 'Dockerfiles/' directory"
41+ FILES=$(find Dockerfiles/ -type f -printf "%f\n" | grep .*Dockerfile)
42+ echo "Found Dockerfiles:"
43+ echo "${ FILES}"
44+ # Convert the array to JSON array
45+ JSON_ARRAY=$(printf '%s\n' "${FILES[@]}" | jq -R . | jq -s . | jq -c .)
4546 echo "JSON_ARRAY is"
46- echo $JSON_ARRAY
47- echo "files=$JSON_ARRAY" >> $GITHUB_OUTPUT
48-
49- # Clean the workspace here since other jobs may not have the permissions to do so later
50- # (needed for self-hosted runners)
51- - name : Clean the workspace
52- run : find $GITHUB_WORKSPACE -mindepth 1 -delete
47+ echo "${JSON_ARRAY}"
48+ echo "files=${JSON_ARRAY}" >> $GITHUB_OUTPUT
5349
5450 build :
5551 name : Build Docker Images
56- runs-on : self-hosted
52+ runs-on : ubuntu-latest
5753 needs : find-dockerfiles
5854 strategy :
55+ fail-fast : false
5956 matrix :
6057 file : ${{fromJson(needs.find-dockerfiles.outputs.files)}}
6158 steps :
62- - name : Checkout repository
63- uses : actions/checkout@v4
59+ - name : Checkout repository
60+ uses : actions/checkout@v4
6461
65- - name : Set up Docker Buildx
66- uses : docker/setup-buildx-action@v3
62+ - name : Set up Docker Buildx
63+ uses : docker/setup-buildx-action@v3
6764
6865 - name : Generate image tag
6966 id : image-tag
7067 run : |
71- # Extract image name from Dockerfile name (e.g., "ubuntu-22.04-rocm .Dockerfile" -> "ubuntu-22.04-rocm ")
68+ # Extract image name from Dockerfile name (e.g., "ubuntu-22.04.Dockerfile" -> "ubuntu-22.04")
7269 IMAGE_NAME=$(echo "${{ matrix.file }}" | sed 's/\.Dockerfile$//' | tr '[:upper:]' '[:lower:]')
73- echo "name=$IMAGE_NAME" >> $GITHUB_OUTPUT
74- echo "Image name: $IMAGE_NAME"
70+ echo "name=${ IMAGE_NAME} " >> $GITHUB_OUTPUT
71+ echo "Image name: ${ IMAGE_NAME} "
7572
7673 - name : Log in to GHCR
7774 if : github.event_name == 'push'
@@ -81,18 +78,19 @@ jobs:
8178 username : ${{ github.actor }}
8279 password : ${{ secrets.GITHUB_TOKEN }}
8380
81+ - name : Extract metadata (tags, labels) for Docker
82+ id : meta
83+ uses : docker/metadata-action@v5
84+ with :
85+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}-${{ steps.image-tag.outputs.name }}
86+ tags : |
87+ type=raw,value=latest,enable={{is_default_branch}}
88+
8489 - name : Build and push Docker image for ${{ matrix.file }}
8590 uses : docker/build-push-action@v5
86- with :
91+ with :
8792 context : Dockerfiles/
8893 file : Dockerfiles/${{ matrix.file }}
8994 push : ${{ github.event_name == 'push' }}
90- tags : |
91- ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}:${{ steps.image-tag.outputs.name }}
92- ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}:${{ steps.image-tag.outputs.name }}-${{ github.sha }}
93-
94- # Clean the workspace here since other jobs may not have the permissions to do so later
95- # (needed for self-hosted runners)
96- - name : Clean the workspace
97- if : always()
98- run : find "$GITHUB_WORKSPACE" -mindepth 1 -delete
95+ tags : ${{ steps.meta.outputs.tags }}
96+ labels : ${{ steps.meta.outputs.labels }}
0 commit comments