|
| 1 | +# -------------------------------------------------------------------- |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | +# contributor license agreements. See the NOTICE file distributed |
| 5 | +# with this work for additional information regarding copyright |
| 6 | +# ownership. The ASF licenses this file to You under the Apache |
| 7 | +# License, Version 2.0 (the "License"); you may not use this file |
| 8 | +# except in compliance with the License. You may obtain a copy of the |
| 9 | +# License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 16 | +# implied. See the License for the specific language governing |
| 17 | +# permissions and limitations under the License. |
| 18 | +# |
| 19 | +# -------------------------------------------------------------------- |
| 20 | +# |
| 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 |
| 23 | +# |
| 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} |
| 29 | +# |
| 30 | +# Features: |
| 31 | +# - Matrix build for multiple platforms |
| 32 | +# - Caching strategy for efficient builds |
| 33 | +# - Path filtering to only build changed platforms |
| 34 | +# - Comprehensive build summary and metadata |
| 35 | +# - Container testing with TestInfra |
| 36 | + |
| 37 | +name: docker-cbdb-build-containers |
| 38 | + |
| 39 | +# Trigger on pushes to docker-images branch when relevant paths change |
| 40 | +# Also allows manual triggering via GitHub UI |
| 41 | +on: |
| 42 | + push: |
| 43 | + branches: |
| 44 | + - main |
| 45 | + paths: |
| 46 | + - 'images/docker/cbdb/build/rocky8/**' |
| 47 | + - 'images/docker/cbdb/build/rocky9/**' |
| 48 | + workflow_dispatch: # Manual trigger |
| 49 | + |
| 50 | +# Prevent multiple workflow runs from interfering with each other |
| 51 | +concurrency: |
| 52 | + group: docker-build-${{ github.ref }} |
| 53 | + cancel-in-progress: true |
| 54 | + |
| 55 | +jobs: |
| 56 | + build-and-push: |
| 57 | + timeout-minutes: 60 # Prevent hanging builds |
| 58 | + runs-on: ubuntu-latest |
| 59 | + strategy: |
| 60 | + matrix: |
| 61 | + # Build for both Rocky Linux 8 and 9 |
| 62 | + platform: ['rocky8', 'rocky9'] |
| 63 | + |
| 64 | + steps: |
| 65 | + # Checkout repository code |
| 66 | + - name: Checkout code |
| 67 | + uses: actions/checkout@v4 |
| 68 | + |
| 69 | + # Generate version information for image tags |
| 70 | + - name: Set version |
| 71 | + id: version |
| 72 | + run: | |
| 73 | + echo "BUILD_DATE=$(date -u +'%Y%m%d')" >> $GITHUB_OUTPUT |
| 74 | + echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 75 | +
|
| 76 | + # Determine if the current platform's files have changed |
| 77 | + - name: Determine if platform changed |
| 78 | + id: platform-filter |
| 79 | + uses: dorny/paths-filter@v3 |
| 80 | + with: |
| 81 | + filters: | |
| 82 | + rocky8: |
| 83 | + - 'images/docker/cbdb/build/rocky8/**' |
| 84 | + rocky9: |
| 85 | + - 'images/docker/cbdb/build/rocky9/**' |
| 86 | +
|
| 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" |
| 91 | + |
| 92 | + # Login to DockerHub for pushing images |
| 93 | + - name: Login to Docker Hub |
| 94 | + if: ${{ steps.platform-filter.outputs[matrix.platform] == 'true' }} |
| 95 | + uses: docker/login-action@v3 |
| 96 | + with: |
| 97 | + username: ${{ secrets.DOCKERHUB_USER }} |
| 98 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 99 | + |
| 100 | + # Setup Docker Buildx for efficient builds |
| 101 | + - name: Set up Docker Buildx |
| 102 | + if: ${{ steps.platform-filter.outputs[matrix.platform] == 'true' }} |
| 103 | + uses: docker/setup-buildx-action@v3 |
| 104 | + with: |
| 105 | + buildkitd-flags: --debug |
| 106 | + |
| 107 | + # Build the Docker image locally for testing |
| 108 | + - name: Build Docker image for cbdb-build-${{ matrix.platform }} |
| 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=${{ secrets.DOCKERHUB_USER }}/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 | + 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 |
| 136 | + if: ${{ steps.platform-filter.outputs[matrix.platform] == 'true' }} |
| 137 | + id: test |
| 138 | + run: | |
| 139 | + docker run -d \ |
| 140 | + -h cdw \ |
| 141 | + --name cbdb-build-${{ matrix.platform }}-test \ |
| 142 | + 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' |
| 169 | + uses: docker/build-push-action@v6 |
| 170 | + with: |
| 171 | + context: ./images/docker/cbdb/build/${{ matrix.platform }} |
| 172 | + push: true |
| 173 | + cache-from: | |
| 174 | + type=registry,ref=${{ secrets.DOCKERHUB_USER }}/cbdb-build-${{ matrix.platform }}:latest |
| 175 | + type=gha,scope=docker-cbdb-build-${{ matrix.platform }} |
| 176 | + tags: | |
| 177 | + ${{ secrets.DOCKERHUB_USER }}/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-latest |
| 178 | + ${{ secrets.DOCKERHUB_USER }}/incubator-cloudberry:cbdb-build-${{ matrix.platform }}-${{ steps.version.outputs.BUILD_DATE }}-${{ steps.version.outputs.SHA_SHORT }} |
| 179 | + labels: | |
| 180 | + org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} |
| 181 | + org.opencontainers.image.revision=${{ github.sha }} |
| 182 | + org.opencontainers.image.created=${{ steps.version.outputs.BUILD_DATE }} |
| 183 | + org.opencontainers.image.version=${{ steps.version.outputs.BUILD_DATE }}-${{ steps.version.outputs.SHA_SHORT }} |
| 184 | +
|
| 185 | + # Generate build summary |
| 186 | + - name: Build Summary |
| 187 | + if: always() |
| 188 | + run: | |
| 189 | + echo "### Build Summary for ${{ matrix.platform }} 🚀" >> $GITHUB_STEP_SUMMARY |
| 190 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 191 | +
|
| 192 | + echo "#### 🔍 Build Information" >> $GITHUB_STEP_SUMMARY |
| 193 | + echo "- **Build Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY |
| 194 | + echo "- **Platform**: ${{ matrix.platform }}" >> $GITHUB_STEP_SUMMARY |
| 195 | + 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 |
| 198 | + 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 |
| 200 | + 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**: [\`${{ secrets.DOCKERHUB_USER }}/cbdb-build-${{ matrix.platform }}\`](https://hub.docker.com/r/${{ secrets.DOCKERHUB_USER }}/cbdb-build-${{ matrix.platform }})" >> $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 ${{ secrets.DOCKERHUB_USER }}/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 ${{ secrets.DOCKERHUB_USER }}/cbdb-build-${{ matrix.platform }}:${{ steps.version.outputs.BUILD_DATE }}-${{ steps.version.outputs.SHA_SHORT }}" >> $GITHUB_STEP_SUMMARY |
| 217 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 218 | + fi |
0 commit comments