|
| 1 | +name: Container Build and Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ['main', 'develop'] |
| 6 | + tags: ['v*'] |
| 7 | + pull_request: |
| 8 | + branches: ['main'] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +env: |
| 12 | + REGISTRY: ghcr.io |
| 13 | + IMAGE_NAME: ${{ github.repository }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + # Security and code quality |
| 17 | + security-scan: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Run Trivy vulnerability scanner in filesystem mode |
| 24 | + uses: aquasecurity/trivy-action@master |
| 25 | + with: |
| 26 | + scan-type: 'fs' |
| 27 | + scan-ref: '.' |
| 28 | + format: 'sarif' |
| 29 | + output: 'trivy-results.sarif' |
| 30 | + severity: 'CRITICAL,HIGH' |
| 31 | + |
| 32 | + - name: Upload Trivy scan results to GitHub Security |
| 33 | + uses: github/codeql-action/upload-sarif@v3 |
| 34 | + if: always() |
| 35 | + with: |
| 36 | + sarif_file: 'trivy-results.sarif' |
| 37 | + |
| 38 | + # Build and test |
| 39 | + build-and-test: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + needs: security-scan |
| 42 | + steps: |
| 43 | + - name: Checkout code |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Set up Go |
| 47 | + uses: actions/setup-go@v5 |
| 48 | + with: |
| 49 | + go-version: '1.21' |
| 50 | + cache: true |
| 51 | + |
| 52 | + - name: Download dependencies |
| 53 | + run: go mod download |
| 54 | + |
| 55 | + - name: Run unit tests |
| 56 | + run: go test -v -race -coverprofile=coverage.out ./... |
| 57 | + |
| 58 | + - name: Upload coverage reports |
| 59 | + uses: codecov/codecov-action@v4 |
| 60 | + if: github.event_name == 'push' |
| 61 | + with: |
| 62 | + file: ./coverage.out |
| 63 | + flags: unittests |
| 64 | + name: codecov-umbrella |
| 65 | + continue-on-error: true |
| 66 | + |
| 67 | + - name: Build all components |
| 68 | + run: | |
| 69 | + echo "Building web-dashboard..." |
| 70 | + go build -v -o bin/web-dashboard ./examples/demo/web-dashboard/main.go |
| 71 | + echo "Building k8s-scheduler..." |
| 72 | + go build -v -o bin/k8s-scheduler ./cmd/k8s-gpu-scheduler/main.go |
| 73 | + echo "Building prometheus-demo..." |
| 74 | + go build -v -o bin/prometheus-demo ./examples/demo/prometheus-grafana/main.go |
| 75 | +
|
| 76 | + # Container build and publish |
| 77 | + container-publish: |
| 78 | + runs-on: ubuntu-latest |
| 79 | + needs: build-and-test |
| 80 | + if: github.event_name != 'pull_request' |
| 81 | + permissions: |
| 82 | + contents: read |
| 83 | + packages: write |
| 84 | + id-token: write |
| 85 | + strategy: |
| 86 | + matrix: |
| 87 | + component: |
| 88 | + - web-dashboard |
| 89 | + - k8s-scheduler |
| 90 | + - prometheus-demo |
| 91 | + steps: |
| 92 | + - name: Checkout code |
| 93 | + uses: actions/checkout@v4 |
| 94 | + |
| 95 | + - name: Set up Docker Buildx |
| 96 | + uses: docker/setup-buildx-action@v3 |
| 97 | + |
| 98 | + - name: Log in to GitHub Container Registry |
| 99 | + uses: docker/login-action@v3 |
| 100 | + with: |
| 101 | + registry: ${{ env.REGISTRY }} |
| 102 | + username: ${{ github.actor }} |
| 103 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + |
| 105 | + - name: Extract metadata |
| 106 | + id: meta |
| 107 | + uses: docker/metadata-action@v5 |
| 108 | + with: |
| 109 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 110 | + flavor: | |
| 111 | + latest=auto |
| 112 | + prefix=${{ matrix.component }}-,onlatest=true |
| 113 | + tags: | |
| 114 | + type=ref,event=branch |
| 115 | + type=ref,event=pr |
| 116 | + type=semver,pattern={{version}} |
| 117 | + type=semver,pattern={{major}}.{{minor}} |
| 118 | + type=raw,value=latest,enable={{is_default_branch}} |
| 119 | + type=sha,prefix={{branch}}- |
| 120 | + labels: | |
| 121 | + org.opencontainers.image.title=AgentaFlow SRO ${{ matrix.component }} |
| 122 | + org.opencontainers.image.description=AgentaFlow GPU Resource Optimization - ${{ matrix.component }} |
| 123 | + org.opencontainers.image.vendor=Finoptimize |
| 124 | + |
| 125 | + - name: Build and push container image |
| 126 | + id: build-push |
| 127 | + uses: docker/build-push-action@v5 |
| 128 | + with: |
| 129 | + context: . |
| 130 | + file: ./docker/Dockerfile.${{ matrix.component }} |
| 131 | + push: true |
| 132 | + tags: ${{ steps.meta.outputs.tags }} |
| 133 | + labels: ${{ steps.meta.outputs.labels }} |
| 134 | + platforms: linux/amd64,linux/arm64 |
| 135 | + cache-from: type=gha,scope=${{ matrix.component }} |
| 136 | + cache-to: type=gha,mode=max,scope=${{ matrix.component }} |
| 137 | + provenance: true |
| 138 | + sbom: true |
| 139 | + |
| 140 | + - name: Install Cosign |
| 141 | + uses: sigstore/cosign-installer@v3 |
| 142 | + if: github.event_name != 'pull_request' |
| 143 | + |
| 144 | + - name: Sign container image with Cosign |
| 145 | + if: github.event_name != 'pull_request' |
| 146 | + env: |
| 147 | + COSIGN_EXPERIMENTAL: "true" |
| 148 | + run: | |
| 149 | + echo "Signing image with Cosign..." |
| 150 | + cosign sign --yes \ |
| 151 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-push.outputs.digest }} |
| 152 | + |
| 153 | + - name: Run Trivy container scan |
| 154 | + uses: aquasecurity/trivy-action@master |
| 155 | + with: |
| 156 | + image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.component }}-latest |
| 157 | + format: 'sarif' |
| 158 | + output: 'trivy-container-${{ matrix.component }}.sarif' |
| 159 | + severity: 'CRITICAL,HIGH' |
| 160 | + continue-on-error: true |
| 161 | + |
| 162 | + - name: Upload container scan results |
| 163 | + uses: github/codeql-action/upload-sarif@v3 |
| 164 | + if: always() |
| 165 | + with: |
| 166 | + sarif_file: 'trivy-container-${{ matrix.component }}.sarif' |
| 167 | + category: 'container-${{ matrix.component }}' |
| 168 | + continue-on-error: true |
| 169 | + |
| 170 | + |
| 171 | + # Integration testing |
| 172 | + integration-test: |
| 173 | + runs-on: ubuntu-latest |
| 174 | + needs: container-publish |
| 175 | + if: github.event_name != 'pull_request' |
| 176 | + steps: |
| 177 | + - name: Checkout code |
| 178 | + uses: actions/checkout@v4 |
| 179 | + |
| 180 | + - name: Log in to GitHub Container Registry |
| 181 | + uses: docker/login-action@v3 |
| 182 | + with: |
| 183 | + registry: ${{ env.REGISTRY }} |
| 184 | + username: ${{ github.actor }} |
| 185 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 186 | + |
| 187 | + - name: Start containers with test configuration |
| 188 | + run: | |
| 189 | + docker-compose -f docker-compose.test.yml up -d |
| 190 | + echo "Waiting for services to be ready..." |
| 191 | + sleep 45 |
| 192 | + |
| 193 | + - name: Run health checks |
| 194 | + run: | |
| 195 | + echo "Checking web dashboard..." |
| 196 | + curl -f http://localhost:9000/health || exit 1 |
| 197 | + echo "Checking Prometheus metrics endpoint..." |
| 198 | + curl -f http://localhost:9001/metrics || exit 1 |
| 199 | + echo "Checking Prometheus..." |
| 200 | + curl -f http://localhost:9090/-/healthy || exit 1 |
| 201 | + echo "All health checks passed!" |
| 202 | + |
| 203 | + - name: Set up Go for integration tests |
| 204 | + uses: actions/setup-go@v5 |
| 205 | + with: |
| 206 | + go-version: '1.21' |
| 207 | + cache: true |
| 208 | + |
| 209 | + - name: Run integration tests |
| 210 | + run: | |
| 211 | + if [ -d "tests/integration" ]; then |
| 212 | + go test -v -timeout 5m ./tests/integration/... |
| 213 | + else |
| 214 | + echo "Integration tests directory not found, skipping..." |
| 215 | + fi |
| 216 | + continue-on-error: true |
| 217 | + |
| 218 | + - name: Display container logs on failure |
| 219 | + if: failure() |
| 220 | + run: | |
| 221 | + echo "=== Docker Compose Logs ===" |
| 222 | + docker-compose -f docker-compose.test.yml logs |
| 223 | + |
| 224 | + - name: Cleanup |
| 225 | + if: always() |
| 226 | + run: docker-compose -f docker-compose.test.yml down -v |
| 227 | + |
| 228 | + # Release summary |
| 229 | + release-summary: |
| 230 | + runs-on: ubuntu-latest |
| 231 | + needs: [integration-test] |
| 232 | + if: github.event_name != 'pull_request' |
| 233 | + steps: |
| 234 | + - name: Create release summary |
| 235 | + run: | |
| 236 | + echo "## 🎉 Container Build Summary" >> $GITHUB_STEP_SUMMARY |
| 237 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 238 | + echo "### Images Published" >> $GITHUB_STEP_SUMMARY |
| 239 | + echo "- \`ghcr.io/${{ github.repository }}:web-dashboard-latest\`" >> $GITHUB_STEP_SUMMARY |
| 240 | + echo "- \`ghcr.io/${{ github.repository }}:k8s-scheduler-latest\`" >> $GITHUB_STEP_SUMMARY |
| 241 | + echo "- \`ghcr.io/${{ github.repository }}:prometheus-demo-latest\`" >> $GITHUB_STEP_SUMMARY |
| 242 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 243 | + echo "### Quick Start" >> $GITHUB_STEP_SUMMARY |
| 244 | + echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY |
| 245 | + echo "docker run -p 9000:9000 -p 9001:9001 ghcr.io/${{ github.repository }}:web-dashboard-latest" >> $GITHUB_STEP_SUMMARY |
| 246 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
0 commit comments