Skip to content

Commit 9b84324

Browse files
authored
CI: support run docker build/test on PR
Enable both docker-cbdb-build-containers and docker-cbdb-test-containers workflows to run on pull_request when files under their respective Docker paths change. Main changes: * Add pull_request triggers with path filters: - build: devops/deploy/docker/build/** - test: devops/deploy/docker/test/** Guard Docker hub login and multi-arch push steps so they run only push to refs/heads/main.
1 parent da0b9d4 commit 9b84324

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

.github/workflows/docker-cbdb-build-containers.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ on:
6161
- 'devops/deploy/docker/build/rocky8/**'
6262
- 'devops/deploy/docker/build/rocky9/**'
6363
- 'devops/deploy/docker/build/ubuntu22.04/**'
64+
pull_request:
65+
paths:
66+
- 'devops/deploy/docker/build/**'
6467
workflow_dispatch: # Manual trigger
6568

6669
# Prevent multiple workflow runs from interfering with each other
@@ -116,7 +119,7 @@ jobs:
116119
# Login to DockerHub for pushing images
117120
# Requires DOCKERHUB_USER and DOCKERHUB_TOKEN secrets to be set
118121
- name: Login to Docker Hub
119-
if: ${{ steps.platform-filter.outputs[matrix.platform] == 'true' }}
122+
if: ${{ steps.platform-filter.outputs[matrix.platform] == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
120123
uses: docker/login-action@v3
121124
with:
122125
username: ${{ secrets.DOCKERHUB_USER }}
@@ -165,7 +168,7 @@ jobs:
165168
# Build and push multi-architecture images
166169
# This creates a manifest list that supports both architectures
167170
- name: Build and Push Multi-arch Docker images
168-
if: ${{ steps.platform-filter.outputs[matrix.platform] == 'true' }}
171+
if: ${{ steps.platform-filter.outputs[matrix.platform] == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
169172
uses: docker/build-push-action@v6
170173
with:
171174
context: ./devops/deploy/docker/build/${{ matrix.platform }}
@@ -187,6 +190,18 @@ jobs:
187190
- name: Build Summary
188191
if: always()
189192
run: |
193+
# Add PR context notification
194+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
195+
echo "#### ℹ️ Pull Request Build" >> $GITHUB_STEP_SUMMARY
196+
echo "This is a validation build. Images are built and tested locally but **not pushed to Docker Hub** for security." >> $GITHUB_STEP_SUMMARY
197+
echo "" >> $GITHUB_STEP_SUMMARY
198+
echo "- ✅ Dockerfile syntax validated" >> $GITHUB_STEP_SUMMARY
199+
echo "- ✅ Multi-architecture builds tested" >> $GITHUB_STEP_SUMMARY
200+
echo "- ✅ TestInfra tests executed" >> $GITHUB_STEP_SUMMARY
201+
echo "- ⏭️ Docker Hub push skipped (requires main branch)" >> $GITHUB_STEP_SUMMARY
202+
echo "" >> $GITHUB_STEP_SUMMARY
203+
fi
204+
190205
echo "### Build Summary for ${{ matrix.platform }} 🚀" >> $GITHUB_STEP_SUMMARY
191206
echo "" >> $GITHUB_STEP_SUMMARY
192207
echo "#### 🔍 Build Information" >> $GITHUB_STEP_SUMMARY

.github/workflows/docker-cbdb-test-containers.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ on:
5050
- 'devops/deploy/docker/test/rocky8/**'
5151
- 'devops/deploy/docker/test/rocky9/**'
5252
- 'devops/deploy/docker/test/ubuntu22.04/**'
53+
pull_request:
54+
paths:
55+
- 'devops/deploy/docker/test/**'
5356
workflow_dispatch: # Manual trigger
5457

5558
# Prevent multiple workflow runs from interfering with each other
@@ -104,7 +107,7 @@ jobs:
104107

105108
# Login to DockerHub for pushing images
106109
- name: Login to Docker Hub
107-
if: ${{ steps.platform-filter.outputs[matrix.platform] == 'true' }}
110+
if: ${{ steps.platform-filter.outputs[matrix.platform] == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
108111
uses: docker/login-action@v3
109112
with:
110113
username: ${{ secrets.DOCKERHUB_USER }}
@@ -135,7 +138,7 @@ jobs:
135138
# Build and push multi-architecture images
136139
# Creates a manifest list that supports both architectures
137140
- name: Build and Push Multi-arch Docker images
138-
if: ${{ steps.platform-filter.outputs[matrix.platform] == 'true' }}
141+
if: ${{ steps.platform-filter.outputs[matrix.platform] == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
139142
uses: docker/build-push-action@v6
140143
with:
141144
context: ./devops/deploy/docker/test/${{ matrix.platform }}
@@ -161,6 +164,17 @@ jobs:
161164
- name: Build Summary
162165
if: always()
163166
run: |
167+
# Add PR context notification
168+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
169+
echo "#### ℹ️ Pull Request Build" >> $GITHUB_STEP_SUMMARY
170+
echo "This is a validation build. Images are built and tested locally but **not pushed to Docker Hub** for security." >> $GITHUB_STEP_SUMMARY
171+
echo "" >> $GITHUB_STEP_SUMMARY
172+
echo "- ✅ Dockerfile syntax validated" >> $GITHUB_STEP_SUMMARY
173+
echo "- ✅ Multi-architecture builds tested" >> $GITHUB_STEP_SUMMARY
174+
echo "- ⏭️ Docker Hub push skipped (requires main branch)" >> $GITHUB_STEP_SUMMARY
175+
echo "" >> $GITHUB_STEP_SUMMARY
176+
fi
177+
164178
echo "### Build Summary for ${{ matrix.platform }} 🚀" >> $GITHUB_STEP_SUMMARY
165179
echo "" >> $GITHUB_STEP_SUMMARY
166180
echo "#### 🔍 Build Information" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)