1717# permissions and limitations under the License.
1818#
1919# --------------------------------------------------------------------
20+ # GitHub Actions Workflow for Apache Cloudberry Build Environments
21+ # --------------------------------------------------------------------
22+ # Purpose:
23+ # Builds, tests, and publishes multi-architecture Docker images for
24+ # Apache Cloudberry DB build environments. Images are built for both
25+ # Rocky Linux 8 and 9, tested with TestInfra, and pushed to DockerHub.
2026#
21- # Purpose: Builds, tests and pushes Docker images for Apache Cloudberry DB build environments
22- # Images are built for Rocky Linux 8 and 9, tested with TestInfra, and pushed to DockerHub
27+ # Multi-Architecture Support:
28+ # - Builds images for both AMD64 and ARM64 architectures
29+ # - Creates and pushes multi-arch manifests
30+ # - Uses QEMU for cross-platform builds
31+ # - Automated testing for all architectures
2332#
24- # Images are tagged with:
25- # - cbdb-build-rocky8-latest
26- # - cbdb-build-rocky8-{YYYYMMDD}-{git-short-sha}
27- # - cbdb-build-rocky9-latest
28- # - cbdb-build-rocky9-{YYYYMMDD}-{git-short-sha}
33+ # Image Tags:
34+ # - Latest: cbdb-build-{platform}-latest
35+ # - Versioned: cbdb-build-{platform}-{YYYYMMDD}-{git-short-sha}
2936#
3037# Features:
3138# - Matrix build for multiple platforms
32- # - Caching strategy for efficient builds
39+ # - Parallel architecture builds
40+ # - Build caching strategy
3341# - Path filtering to only build changed platforms
3442# - Comprehensive build summary and metadata
3543# - Container testing with TestInfra
44+ # - Multi-arch manifest creation
45+ #
46+ # Requirements:
47+ # - DockerHub credentials in GitHub secrets
48+ # - DOCKERHUB_USER
49+ # - DOCKERHUB_TOKEN
50+ # --------------------------------------------------------------------
3651
3752name : docker-cbdb-build-containers
3853
39- # Trigger on pushes to docker-images branch when relevant paths change
54+ # Trigger workflow on pushes to main when relevant paths change
4055# Also allows manual triggering via GitHub UI
4156on :
4257 push :
@@ -54,26 +69,31 @@ concurrency:
5469
5570jobs :
5671 build-and-push :
57- timeout-minutes : 60 # Prevent hanging builds
72+ # Set timeout to prevent hanging builds
73+ timeout-minutes : 60
5874 runs-on : ubuntu-latest
75+
76+ # Matrix strategy to build for both Rocky Linux 8 and 9
5977 strategy :
6078 matrix :
61- # Build for both Rocky Linux 8 and 9
6279 platform : ['rocky8', 'rocky9']
6380
6481 steps :
65- # Checkout repository code
82+ # Checkout repository code with full history
6683 - name : Checkout code
6784 uses : actions/checkout@v4
6885
6986 # Generate version information for image tags
87+ # - BUILD_DATE: Current date in YYYYMMDD format
88+ # - SHA_SHORT: Short form of the git commit SHA
7089 - name : Set version
7190 id : version
7291 run : |
7392 echo "BUILD_DATE=$(date -u +'%Y%m%d')" >> $GITHUB_OUTPUT
7493 echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
7594
7695 # Determine if the current platform's files have changed
96+ # This prevents unnecessary builds if only one platform was modified
7797 - name : Determine if platform changed
7898 id : platform-filter
7999 uses : dorny/paths-filter@v3
@@ -84,12 +104,14 @@ jobs:
84104 rocky9:
85105 - 'images/docker/cbdb/build/rocky9/**'
86106
87- # Skip if no changes for current platform
88- - name : Skip if not relevant
89- if : ${{ steps.platform-filter.outputs[matrix.platform] != 'true' }}
90- run : echo "Skipping because the changes do not affect this platform"
107+ # Set up QEMU for multi-architecture support
108+ # This allows building ARM64 images on AMD64 infrastructure and vice versa
109+ - name : Set up QEMU
110+ if : ${{ steps.platform-filter.outputs[matrix.platform] == 'true' }}
111+ uses : docker/setup-qemu-action@v3
91112
92113 # Login to DockerHub for pushing images
114+ # Requires DOCKERHUB_USER and DOCKERHUB_TOKEN secrets to be set
93115 - name : Login to Docker Hub
94116 if : ${{ steps.platform-filter.outputs[matrix.platform] == 'true' }}
95117 uses : docker/login-action@v3
@@ -98,121 +120,89 @@ jobs:
98120 password : ${{ secrets.DOCKERHUB_TOKEN }}
99121
100122 # Setup Docker Buildx for efficient builds
123+ # Enable debug mode for better troubleshooting
101124 - name : Set up Docker Buildx
102125 if : ${{ steps.platform-filter.outputs[matrix.platform] == 'true' }}
103126 uses : docker/setup-buildx-action@v3
104127 with :
105128 buildkitd-flags : --debug
106129
107- # Build the Docker image locally for testing
108- - name : Build Docker image for incubator-cloudberry:cbdb-build-${{ matrix.platform }}-latest
109- if : ${{ steps.platform-filter.outputs[matrix.platform] == 'true' }}
110- uses : docker/build-push-action@v6
111- with :
112- context : ./images/docker/cbdb/build/${{ matrix.platform }}
113- push : false # Don't push yet, we'll test first
114- load : true # Load into local Docker daemon for testing
115- # Use caching for faster builds
116- cache-from : |
117- type=registry,ref=apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-latest
118- type=gha,scope=docker-cbdb-build-${{ matrix.platform }}
119- cache-to : type=gha,mode=max,scope=docker-cbdb-build-${{ matrix.platform }}
120- tags : |
121- incubator-cloudberry:cbdb-build-${{ matrix.platform }}-latest
122- # Add metadata labels for better image tracking
123- labels : |
124- org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
125- org.opencontainers.image.revision=${{ github.sha }}
126- org.opencontainers.image.created=${{ steps.version.outputs.BUILD_DATE }}
127- org.opencontainers.image.version=${{ steps.version.outputs.BUILD_DATE }}-${{ steps.version.outputs.SHA_SHORT }}
128-
129- # Show available Docker images
130- - name : List Docker images
131- if : ${{ steps.platform-filter.outputs[matrix.platform] == 'true' }}
132- run : docker images
133-
134- # Run TestInfra tests against the built image
135- - name : Run Testinfra Tests
130+ # Build and test images for each architecture
131+ # This ensures both AMD64 and ARM64 variants work correctly
132+ - name : Build and test images
136133 if : ${{ steps.platform-filter.outputs[matrix.platform] == 'true' }}
137- id : test
138134 run : |
139- docker run -d \
140- -h cdw \
141- --name cbdb-build-${{ matrix.platform }}-test \
142- incubator-cloudberry:cbdb-build-${{ matrix.platform }}-latest \
143- bash \
144- -c "sleep 30"
145- docker exec cbdb-build-${{ matrix.platform }}-test pytest \
146- --cache-clear \
147- --disable-warnings \
148- -p no:warnings \
149- /tests/testinfra/test_cloudberry_db_env.py
150-
151- # Save test results as artifacts
152- - name : Save test results
153- if : always() && steps.platform-filter.outputs[matrix.platform] == 'true'
154- uses : actions/upload-artifact@v3
155- with :
156- name : test-results-${{ matrix.platform }}
157- path : |
158- test-results/
159- retention-days : 7
160-
161- # Cleanup test container
162- - name : Remove Test Container
163- if : always() && steps.platform-filter.outputs[matrix.platform] == 'true'
164- run : docker rm -f cbdb-build-${{ matrix.platform }}-test
165-
166- # Push the image to DockerHub if tests passed
167- - name : Retag and Push Docker image to DockerHub
168- if : steps.test.outcome == 'success' && steps.platform-filter.outputs[matrix.platform] == 'true'
135+ # Build for each platform
136+ for arch in amd64 arm64; do
137+ # Build the image for testing
138+ docker buildx build \
139+ --platform linux/$arch \
140+ --load \
141+ -t apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-$arch-test \
142+ ./images/docker/cbdb/build/${{ matrix.platform }}
143+
144+ # Run tests in a container
145+ docker run -d \
146+ -h cdw \
147+ --name cbdb-build-${{ matrix.platform }}-$arch-test \
148+ apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-$arch-test \
149+ bash -c "sleep 30"
150+
151+ # Execute TestInfra tests
152+ docker exec cbdb-build-${{ matrix.platform }}-$arch-test pytest \
153+ --cache-clear \
154+ --disable-warnings \
155+ -p no:warnings \
156+ /tests/testinfra/test_cloudberry_db_env.py
157+
158+ # Cleanup test container
159+ docker rm -f cbdb-build-${{ matrix.platform }}-$arch-test
160+ done
161+
162+ # Build and push multi-architecture images
163+ # This creates a manifest list that supports both architectures
164+ - name : Build and Push Multi-arch Docker images
165+ if : ${{ steps.platform-filter.outputs[matrix.platform] == 'true' }}
169166 uses : docker/build-push-action@v6
170167 with :
171168 context : ./images/docker/cbdb/build/${{ matrix.platform }}
172169 push : true
173- cache-from : |
174- type=registry,ref=apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-latest
175- type=gha,scope=docker-cbdb-build-${{ matrix.platform }}
170+ platforms : linux/amd64,linux/arm64
171+ # Tag with both latest and version-specific tags
176172 tags : |
177173 apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-latest
178174 apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-${{ steps.version.outputs.BUILD_DATE }}-${{ steps.version.outputs.SHA_SHORT }}
175+ # Add standard Open Container Initiative (OCI) labels
179176 labels : |
180177 org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
181178 org.opencontainers.image.revision=${{ github.sha }}
182179 org.opencontainers.image.created=${{ steps.version.outputs.BUILD_DATE }}
183180 org.opencontainers.image.version=${{ steps.version.outputs.BUILD_DATE }}-${{ steps.version.outputs.SHA_SHORT }}
184181
185- # Generate build summary
182+ # Generate a detailed build summary in GitHub Actions UI
183+ # This provides quick access to build information and image usage instructions
186184 - name : Build Summary
187185 if : always()
188186 run : |
189187 echo "### Build Summary for ${{ matrix.platform }} 🚀" >> $GITHUB_STEP_SUMMARY
190188 echo "" >> $GITHUB_STEP_SUMMARY
191-
192189 echo "#### 🔍 Build Information" >> $GITHUB_STEP_SUMMARY
193190 echo "- **Build Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY
194191 echo "- **Platform**: ${{ matrix.platform }}" >> $GITHUB_STEP_SUMMARY
192+ echo "- **Architectures**: amd64, arm64" >> $GITHUB_STEP_SUMMARY
195193 echo "- **Commit SHA**: [\`${{ github.sha }}\`](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})" >> $GITHUB_STEP_SUMMARY
196- echo "- **Trigger**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
197- echo "- **Branch**: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
198194 echo "- **Build Date**: ${{ steps.version.outputs.BUILD_DATE }}" >> $GITHUB_STEP_SUMMARY
199- echo "- **Version Tag**: \`${{ steps.version.outputs.BUILD_DATE }}-${{ steps.version.outputs.SHA_SHORT }}\`" >> $GITHUB_STEP_SUMMARY
200195 echo "" >> $GITHUB_STEP_SUMMARY
201-
202- if [[ "${{ steps.test.outcome }}" == "success" && "${{ steps.platform-filter.outputs[matrix.platform] }}" == "true" ]]; then
203- echo "#### 🐳 Docker Image" >> $GITHUB_STEP_SUMMARY
204- echo "- **Repository**: [\`apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-${{ steps.version.outputs.BUILD_DATE }}-${{ steps.version.outputs.SHA_SHORT }}\`](https://hub.docker.com/r/apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-${{ steps.version.outputs.BUILD_DATE }}-${{ steps.version.outputs.SHA_SHORT }})" >> $GITHUB_STEP_SUMMARY
205- echo "- **Tags Pushed**:" >> $GITHUB_STEP_SUMMARY
206- echo " - \`latest\`" >> $GITHUB_STEP_SUMMARY
207- echo " - \`${{ steps.version.outputs.BUILD_DATE }}-${{ steps.version.outputs.SHA_SHORT }}\`" >> $GITHUB_STEP_SUMMARY
208- echo "" >> $GITHUB_STEP_SUMMARY
209-
210- echo "#### 📋 Quick Reference" >> $GITHUB_STEP_SUMMARY
211- echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
212- echo "# Pull the image" >> $GITHUB_STEP_SUMMARY
213- echo "docker pull apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-${{ steps.version.outputs.BUILD_DATE }}-${{ steps.version.outputs.SHA_SHORT }}" >> $GITHUB_STEP_SUMMARY
214- echo "" >> $GITHUB_STEP_SUMMARY
215- echo "# View image details" >> $GITHUB_STEP_SUMMARY
216- echo "docker inspect apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-${{ steps.version.outputs.BUILD_DATE }}-${{ steps.version.outputs.SHA_SHORT }}" >> $GITHUB_STEP_SUMMARY
217- echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
218- fi
196+ echo "#### 🐳 Docker Images" >> $GITHUB_STEP_SUMMARY
197+ echo "- Latest tag: \`apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-latest\`" >> $GITHUB_STEP_SUMMARY
198+ echo "- Version tag: \`apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-${{ steps.version.outputs.BUILD_DATE }}-${{ steps.version.outputs.SHA_SHORT }}\`" >> $GITHUB_STEP_SUMMARY
199+ echo "" >> $GITHUB_STEP_SUMMARY
200+ echo "#### 📋 Quick Reference" >> $GITHUB_STEP_SUMMARY
201+ echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
202+ echo "# Pull the image (automatically selects correct architecture)" >> $GITHUB_STEP_SUMMARY
203+ echo "docker pull apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-latest" >> $GITHUB_STEP_SUMMARY
204+ echo "" >> $GITHUB_STEP_SUMMARY
205+ echo "# Pull specific architecture if needed" >> $GITHUB_STEP_SUMMARY
206+ echo "docker pull --platform linux/amd64 apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-latest" >> $GITHUB_STEP_SUMMARY
207+ echo "docker pull --platform linux/arm64 apache/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-latest" >> $GITHUB_STEP_SUMMARY
208+ echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
0 commit comments