|
| 1 | +name: Build and Push Docker Images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - staging |
| 8 | + tags: |
| 9 | + - 'v*' |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - main |
| 13 | + - staging |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +env: |
| 17 | + REGISTRY_GHCR: ghcr.io |
| 18 | + REGISTRY_DOCKERHUB: docker.io |
| 19 | + IMAGE_NAME: tealtiger/python-sdk |
| 20 | + |
| 21 | +jobs: |
| 22 | + build-and-push: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + contents: read |
| 26 | + packages: write |
| 27 | + |
| 28 | + strategy: |
| 29 | + matrix: |
| 30 | + variant: |
| 31 | + - name: production |
| 32 | + dockerfile: Dockerfile |
| 33 | + suffix: '' |
| 34 | + - name: dev |
| 35 | + dockerfile: Dockerfile.dev |
| 36 | + suffix: '-dev' |
| 37 | + - name: alpine |
| 38 | + dockerfile: Dockerfile.alpine |
| 39 | + suffix: '-alpine' |
| 40 | + - name: jupyter |
| 41 | + dockerfile: Dockerfile.jupyter |
| 42 | + suffix: '-jupyter' |
| 43 | + |
| 44 | + steps: |
| 45 | + - name: Checkout code |
| 46 | + uses: actions/checkout@v4 |
| 47 | + |
| 48 | + - name: Set up Docker Buildx |
| 49 | + uses: docker/setup-buildx-action@v3 |
| 50 | + |
| 51 | + - name: Log in to GitHub Container Registry |
| 52 | + if: github.event_name != 'pull_request' |
| 53 | + uses: docker/login-action@v3 |
| 54 | + with: |
| 55 | + registry: ${{ env.REGISTRY_GHCR }} |
| 56 | + username: ${{ github.actor }} |
| 57 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + |
| 59 | + - name: Log in to Docker Hub |
| 60 | + if: github.event_name != 'pull_request' |
| 61 | + uses: docker/login-action@v3 |
| 62 | + with: |
| 63 | + registry: ${{ env.REGISTRY_DOCKERHUB }} |
| 64 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 65 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 66 | + |
| 67 | + - name: Extract metadata |
| 68 | + id: meta |
| 69 | + uses: docker/metadata-action@v5 |
| 70 | + with: |
| 71 | + images: | |
| 72 | + ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }} |
| 73 | + ${{ env.REGISTRY_DOCKERHUB }}/${{ env.IMAGE_NAME }} |
| 74 | + tags: | |
| 75 | + type=ref,event=branch,suffix=${{ matrix.variant.suffix }} |
| 76 | + type=ref,event=pr,suffix=${{ matrix.variant.suffix }} |
| 77 | + type=semver,pattern={{version}},suffix=${{ matrix.variant.suffix }} |
| 78 | + type=semver,pattern={{major}}.{{minor}},suffix=${{ matrix.variant.suffix }} |
| 79 | + type=semver,pattern={{major}},suffix=${{ matrix.variant.suffix }} |
| 80 | + type=sha,suffix=${{ matrix.variant.suffix }} |
| 81 | + type=raw,value=latest,suffix=${{ matrix.variant.suffix }},enable={{is_default_branch}} |
| 82 | + labels: | |
| 83 | + org.opencontainers.image.title=TealTiger Python SDK (${{ matrix.variant.name }}) |
| 84 | + org.opencontainers.image.description=AI agent security with guardrails and cost tracking |
| 85 | + org.opencontainers.image.vendor=TealTiger |
| 86 | + |
| 87 | + - name: Build and push Docker image |
| 88 | + uses: docker/build-push-action@v5 |
| 89 | + with: |
| 90 | + context: . |
| 91 | + file: ${{ matrix.variant.dockerfile }} |
| 92 | + push: ${{ github.event_name != 'pull_request' }} |
| 93 | + tags: ${{ steps.meta.outputs.tags }} |
| 94 | + labels: ${{ steps.meta.outputs.labels }} |
| 95 | + cache-from: type=gha |
| 96 | + cache-to: type=gha,mode=max |
| 97 | + platforms: linux/amd64,linux/arm64 |
| 98 | + |
| 99 | + - name: Run Trivy vulnerability scanner |
| 100 | + if: github.event_name != 'pull_request' |
| 101 | + uses: aquasecurity/trivy-action@master |
| 102 | + with: |
| 103 | + image-ref: ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }}:${{ github.sha }}${{ matrix.variant.suffix }} |
| 104 | + format: 'sarif' |
| 105 | + output: 'trivy-results-${{ matrix.variant.name }}.sarif' |
| 106 | + |
| 107 | + - name: Upload Trivy results to GitHub Security |
| 108 | + if: github.event_name != 'pull_request' |
| 109 | + uses: github/codeql-action/upload-sarif@v3 |
| 110 | + with: |
| 111 | + sarif_file: 'trivy-results-${{ matrix.variant.name }}.sarif' |
| 112 | + category: 'container-${{ matrix.variant.name }}' |
| 113 | + |
| 114 | + test-images: |
| 115 | + needs: build-and-push |
| 116 | + runs-on: ubuntu-latest |
| 117 | + if: github.event_name != 'pull_request' |
| 118 | + |
| 119 | + strategy: |
| 120 | + matrix: |
| 121 | + variant: [production, dev, alpine] |
| 122 | + |
| 123 | + steps: |
| 124 | + - name: Checkout code |
| 125 | + uses: actions/checkout@v4 |
| 126 | + |
| 127 | + - name: Pull image |
| 128 | + run: | |
| 129 | + docker pull ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-${{ matrix.variant }} |
| 130 | + |
| 131 | + - name: Test image |
| 132 | + run: | |
| 133 | + docker run --rm ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-${{ matrix.variant }} \ |
| 134 | + python -c "import tealtiger; print(f'TealTiger version: {tealtiger.__version__}')" |
| 135 | + |
| 136 | + - name: Test examples |
| 137 | + run: | |
| 138 | + docker run --rm ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-${{ matrix.variant }} \ |
| 139 | + python -c "from tealtiger import TealOpenAI, GuardrailEngine; print('Imports successful')" |
0 commit comments