|
| 1 | +name: CI/CD Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] # Trigger the pipeline on pushes to the main branch |
| 6 | + pull_request: |
| 7 | + branches: [ "main" ] |
| 8 | + |
| 9 | +env: |
| 10 | + # GHCR image name: ghcr.io/owner/repo-name |
| 11 | + IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/simple-rag |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-push: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + contents: read |
| 18 | + packages: write # Required for pushing to GHCR |
| 19 | + steps: |
| 20 | + - name: Check out the repo |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Log in to GitHub Container Registry |
| 24 | + uses: docker/login-action@v3 |
| 25 | + with: |
| 26 | + registry: ghcr.io |
| 27 | + username: ${{ github.actor }} |
| 28 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + |
| 30 | + - name: Build and push Docker image |
| 31 | + uses: docker/build-push-action@v5 |
| 32 | + with: |
| 33 | + context: . |
| 34 | + push: ${{ github.event_name != 'pull_request' }} |
| 35 | + tags: | |
| 36 | + ${{ env.IMAGE_NAME }}:latest |
| 37 | + ${{ env.IMAGE_NAME }}:${{ github.sha }} |
| 38 | + # Ensure image is lowered for GHCR if repository name contains uppercase |
| 39 | + labels: | |
| 40 | + org.opencontainers.image.source=https://github.com/${{ github.repository }} |
| 41 | +
|
| 42 | + # Optional job to automatically update kubernetes deployment. |
| 43 | + # This requires a kubernetes cluster setup and kubeconfig secret. |
| 44 | + deploy: |
| 45 | + needs: build-and-push |
| 46 | + if: github.event_name == 'push' |
| 47 | + runs-on: ubuntu-latest |
| 48 | + steps: |
| 49 | + - name: Check out the repo |
| 50 | + uses: actions/checkout@v4 |
| 51 | + |
| 52 | + # Example step using an external tool to deploy, or setup kubectl |
| 53 | + - name: Set up kubectl |
| 54 | + uses: azure/setup-kubectl@v3 |
| 55 | + with: |
| 56 | + version: 'latest' |
| 57 | + |
| 58 | + - name: Configure Kubernetes context |
| 59 | + uses: azure/k8s-set-context@v3 |
| 60 | + with: |
| 61 | + method: kubeconfig |
| 62 | + kubeconfig: ${{ secrets.KUBECONFIG }} |
| 63 | + |
| 64 | + - name: Update deployment image |
| 65 | + run: | |
| 66 | + kubectl set image deployment/simple-rag-deployment simple-rag=${{ env.IMAGE_NAME }}:${{ github.sha }} |
| 67 | + kubectl rollout status deployment/simple-rag-deployment |
0 commit comments