|
| 1 | +name: Build Chatbot image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'chatbot-*' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + packages: write |
| 12 | + security-events: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + get-tag: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + version: ${{ steps.extract-chatbot-version.outputs.version }} |
| 19 | + steps: |
| 20 | + - name: Extract version from tag |
| 21 | + id: extract-chatbot-version |
| 22 | + run: | |
| 23 | + TAG_NAME="${{ github.ref_name }}" |
| 24 | + VERSION=${TAG_NAME#chatbot-} |
| 25 | + PATTERN="^([0-9]+\.[0-9]+(\.[0-9]+)?)(-[A-Za-z0-9\.]+)*$" |
| 26 | + if [[ ! "$VERSION" =~ $PATTERN ]]; then |
| 27 | + echo "Invalid version number: $VERSION" |
| 28 | + exit 1 |
| 29 | + fi |
| 30 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 31 | +
|
| 32 | + build-image: |
| 33 | + needs: get-tag |
| 34 | + runs-on: ubuntu-latest |
| 35 | + steps: |
| 36 | + - name: Checkout |
| 37 | + uses: actions/checkout@v5 |
| 38 | + |
| 39 | + - name: Set up Docker Buildx |
| 40 | + uses: docker/setup-buildx-action@v3 |
| 41 | + |
| 42 | + - name: Login to Docker Hardened Images |
| 43 | + uses: docker/login-action@v3 |
| 44 | + with: |
| 45 | + registry: dhi.io |
| 46 | + username: ${{ secrets.DHI_USERNAME }} |
| 47 | + password: ${{ secrets.DHI_PASSWORD }} |
| 48 | + |
| 49 | + - name: Login to Container Registry |
| 50 | + uses: docker/login-action@v3 |
| 51 | + with: |
| 52 | + registry: ghcr.io |
| 53 | + username: ${{ github.actor }} |
| 54 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + - name: Build and push Docker image |
| 57 | + uses: docker/build-push-action@v6 |
| 58 | + with: |
| 59 | + push: true |
| 60 | + platforms: linux/amd64 |
| 61 | + tags: ghcr.io/${{ github.repository_owner }}/hub-chatbot:${{ needs.get-tag.outputs.version }} |
| 62 | + context: ./tools/chatbot |
| 63 | + cache-from: type=gha |
| 64 | + cache-to: type=gha,mode=max |
| 65 | + |
| 66 | + image-security-scan: |
| 67 | + name: Scan Chatbot Image |
| 68 | + needs: [get-tag, build-image] |
| 69 | + runs-on: ubuntu-latest |
| 70 | + continue-on-error: true |
| 71 | + steps: |
| 72 | + - name: Checkout |
| 73 | + uses: actions/checkout@v5 |
| 74 | + |
| 75 | + - name: Login to Container Registry |
| 76 | + uses: docker/login-action@v3 |
| 77 | + with: |
| 78 | + registry: ghcr.io |
| 79 | + username: ${{ github.actor }} |
| 80 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + |
| 82 | + - name: Scan Docker image |
| 83 | + uses: aquasecurity/trivy-action@0.33.1 |
| 84 | + with: |
| 85 | + image-ref: ghcr.io/${{ github.repository_owner }}/hub-chatbot:${{ needs.get-tag.outputs.version }} |
| 86 | + format: 'sarif' |
| 87 | + output: 'trivy-chatbot-image.sarif' |
| 88 | + severity: 'HIGH,CRITICAL' |
| 89 | + exit-code: '1' |
| 90 | + trivyignores: 'tools/chatbot/.trivyignore' |
| 91 | + |
| 92 | + - name: Upload image scan results to GitHub Security tab |
| 93 | + if: always() |
| 94 | + uses: github/codeql-action/upload-sarif@v3 |
| 95 | + with: |
| 96 | + sarif_file: 'trivy-chatbot-image.sarif' |
| 97 | + category: 'trivy-chatbot-image' |
| 98 | + |
| 99 | + - name: Upload image scan reports as artifacts |
| 100 | + if: always() |
| 101 | + uses: actions/upload-artifact@v4 |
| 102 | + with: |
| 103 | + name: trivy-reports-chatbot |
| 104 | + path: '*.sarif' |
| 105 | + retention-days: 30 |
0 commit comments