|
1 | | -name: Build and Package Agent Bot Service |
| 1 | +name: Build and Push Docker Image |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - 'main' |
7 | | - - 'devOps' |
8 | | - - 'dev' |
9 | | - pull_request: |
10 | | - branches: |
11 | | - - 'main' |
12 | | - - 'devOps' |
13 | 7 | - 'dev' |
14 | 8 |
|
15 | | -# Permissions needed to push Docker images to your org's GitHub packages |
16 | 9 | permissions: |
17 | 10 | contents: read |
18 | | - packages: write |
| 11 | + packages: write |
19 | 12 |
|
20 | 13 | jobs: |
21 | | - # JOB 1: Test the Python application |
22 | | - build-test: |
23 | | - name: Install Dependencies and Test |
| 14 | + build-and-push: |
| 15 | + name: Build & Push Docker Image |
24 | 16 | runs-on: ubuntu-latest |
25 | 17 |
|
26 | 18 | steps: |
27 | 19 | - name: Checkout code |
28 | 20 | uses: actions/checkout@v4 |
29 | 21 |
|
30 | | - - name: Set up Python 3.11 |
31 | | - uses: actions/setup-python@v5 |
32 | | - with: |
33 | | - python-version: '3.11' |
34 | | - cache: 'pip' |
35 | | - |
36 | | - - name: Cache pip packages |
37 | | - uses: actions/cache@v4 |
38 | | - with: |
39 | | - path: ~/.cache/pip |
40 | | - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} |
41 | | - restore-keys: | |
42 | | - ${{ runner.os }}-pip- |
43 | | -
|
44 | | - - name: Install dependencies |
45 | | - run: | |
46 | | - python -m pip install --upgrade pip |
47 | | - pip install -r requirements.txt |
48 | | -
|
49 | | - - name: Lint with flake8 (optional) |
| 22 | + - name: Extract branch name |
| 23 | + id: branch |
50 | 24 | run: | |
51 | | - pip install flake8 |
52 | | - # Stop the build if there are Python syntax errors or undefined names |
53 | | - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
54 | | - # Exit-zero treats all errors as warnings |
55 | | - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
56 | | - continue-on-error: true |
| 25 | + BRANCH_NAME=${GITHUB_REF#refs/heads/} |
| 26 | + echo "name=${BRANCH_NAME}" >> $GITHUB_OUTPUT |
| 27 | + echo "📍 Building for branch: ${BRANCH_NAME}" |
57 | 28 |
|
58 | | - # Removed: Test import of main module |
59 | | - # This step was causing failures because it tries to initialize the application |
60 | | - # without environment variables (GOOGLE_API_KEY, PINECONE_API_KEY). |
61 | | - # These variables are only available in the K3S cluster, not in GitHub Actions. |
62 | | - # The flake8 linting step above is sufficient to catch syntax errors. |
63 | | - |
64 | | - # JOB 2: Build and push Docker image |
65 | | - build-and-push-docker: |
66 | | - name: Build & Push Docker Image |
67 | | - # This job only runs on pushes to 'main', 'devOps', or 'dev', not on PRs |
68 | | - if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/devOps' || github.ref == 'refs/heads/dev' |
69 | | - runs-on: ubuntu-latest |
70 | | - # This job runs *after* the build-test job succeeds |
71 | | - needs: build-test |
72 | | - |
73 | | - steps: |
74 | | - - name: Checkout code |
75 | | - uses: actions/checkout@v4 |
76 | | - |
77 | | - # This action generates smart tags for your Docker image |
78 | | - - name: Docker meta |
| 29 | + - name: Docker meta (with branch-aware tags) |
79 | 30 | id: meta |
80 | 31 | uses: docker/metadata-action@v5 |
81 | 32 | with: |
82 | | - images: ghcr.io/${{ github.repository }} # e.g., ghcr.io/TechTorque-2025/Agent_Bot |
| 33 | + images: ghcr.io/techtorque-2025/agent_bot |
83 | 34 | tags: | |
84 | | - type=sha,prefix= |
| 35 | + type=raw,value=${{ steps.branch.outputs.name }}-{{sha}},enable=true |
85 | 36 | type=raw,value=latest,enable={{is_default_branch}} |
| 37 | + flavor: | |
| 38 | + latest=false |
86 | 39 |
|
87 | | - # Logs you into the GitHub Container Registry (GHCR) |
88 | 40 | - name: Log in to GHCR |
89 | 41 | uses: docker/login-action@v3 |
90 | 42 | with: |
91 | 43 | registry: ghcr.io |
92 | 44 | username: ${{ github.actor }} |
93 | | - password: ${{ secrets.GITHUB_TOKEN }} # This token is auto-generated |
| 45 | + password: ${{ secrets.GITHUB_TOKEN }} |
94 | 46 |
|
95 | | - # Builds the Docker image and pushes it to GHCR |
96 | 47 | - name: Build and push Docker image |
97 | 48 | uses: docker/build-push-action@v5 |
98 | 49 | with: |
99 | | - context: . # Dockerfile is in the root of this repo |
| 50 | + context: . |
100 | 51 | push: true |
101 | 52 | tags: ${{ steps.meta.outputs.tags }} |
102 | 53 | labels: ${{ steps.meta.outputs.labels }} |
| 54 | + |
| 55 | + - name: Image Summary |
| 56 | + run: | |
| 57 | + echo "### 🐳 Docker Image Built" >> $GITHUB_STEP_SUMMARY |
| 58 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 59 | + echo "**Tags pushed:**" >> $GITHUB_STEP_SUMMARY |
| 60 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 61 | + echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY |
| 62 | + echo '```' >> $GITHUB_STEP_SUMMARY |
0 commit comments