Skip to content
This repository was archived by the owner on Nov 23, 2025. It is now read-only.

Commit d7a7915

Browse files
authored
Merge pull request #9 from TechTorque-2025/feat/gitops-workflow
chore: sync gitops workflow updates
2 parents 3c34eff + 9c68cc0 commit d7a7915

4 files changed

Lines changed: 150 additions & 65 deletions

File tree

.github/workflows/build-test.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build and Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- 'main'
7+
- 'dev'
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build-test:
14+
name: Build and Test
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.11'
25+
cache: 'pip'
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install -r requirements.txt
31+
32+
- name: Test Summary
33+
run: |
34+
echo "### ✅ Build Successful" >> $GITHUB_STEP_SUMMARY
35+
echo "Python dependencies installed successfully" >> $GITHUB_STEP_SUMMARY
36+
echo "Ready for review and merge" >> $GITHUB_STEP_SUMMARY

.github/workflows/build.yaml

Lines changed: 25 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,62 @@
1-
name: Build and Package Agent Bot Service
1+
name: Build and Push Docker Image
22

33
on:
44
push:
55
branches:
66
- 'main'
7-
- 'devOps'
8-
- 'dev'
9-
pull_request:
10-
branches:
11-
- 'main'
12-
- 'devOps'
137
- 'dev'
148

15-
# Permissions needed to push Docker images to your org's GitHub packages
169
permissions:
1710
contents: read
18-
packages: write
11+
packages: write
1912

2013
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
2416
runs-on: ubuntu-latest
2517

2618
steps:
2719
- name: Checkout code
2820
uses: actions/checkout@v4
2921

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
5024
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}"
5728
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)
7930
id: meta
8031
uses: docker/metadata-action@v5
8132
with:
82-
images: ghcr.io/${{ github.repository }} # e.g., ghcr.io/TechTorque-2025/Agent_Bot
33+
images: ghcr.io/techtorque-2025/agent_bot
8334
tags: |
84-
type=sha,prefix=
35+
type=raw,value=${{ steps.branch.outputs.name }}-{{sha}},enable=true
8536
type=raw,value=latest,enable={{is_default_branch}}
37+
flavor: |
38+
latest=false
8639
87-
# Logs you into the GitHub Container Registry (GHCR)
8840
- name: Log in to GHCR
8941
uses: docker/login-action@v3
9042
with:
9143
registry: ghcr.io
9244
username: ${{ github.actor }}
93-
password: ${{ secrets.GITHUB_TOKEN }} # This token is auto-generated
45+
password: ${{ secrets.GITHUB_TOKEN }}
9446

95-
# Builds the Docker image and pushes it to GHCR
9647
- name: Build and push Docker image
9748
uses: docker/build-push-action@v5
9849
with:
99-
context: . # Dockerfile is in the root of this repo
50+
context: .
10051
push: true
10152
tags: ${{ steps.meta.outputs.tags }}
10253
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
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# GitHub Actions Workflow Template for GitOps with ArgoCD
2+
# This workflow should replace the old deploy.yaml in each microservice repo
3+
4+
name: Update K8s Manifest
5+
6+
on:
7+
workflow_run:
8+
workflows: ["Build and Push Docker Image"]
9+
types: [completed]
10+
branches: ['main', 'dev']
11+
12+
jobs:
13+
update-manifest:
14+
name: Update Image Tag in k8s-config
15+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Get branch and SHA info
20+
id: info
21+
run: |
22+
BRANCH="${{ github.event.workflow_run.head_branch }}"
23+
SHORT_SHA="$(echo ${{ github.event.workflow_run.head_sha }} | cut -c1-7)"
24+
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
25+
echo "sha=${SHORT_SHA}" >> $GITHUB_OUTPUT
26+
echo "📍 Branch: ${BRANCH}, SHA: ${SHORT_SHA}"
27+
28+
- name: Checkout k8s-config repo (matching branch)
29+
uses: actions/checkout@v4
30+
with:
31+
repository: 'TechTorque-2025/k8s-config'
32+
token: ${{ secrets.REPO_ACCESS_TOKEN }}
33+
ref: ${{ steps.info.outputs.branch }} # Checkout dev or main to match microservice branch
34+
path: 'k8s-config'
35+
36+
- name: Install yq (YAML processor)
37+
run: |
38+
sudo wget -qO /usr/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
39+
sudo chmod +x /usr/bin/yq
40+
41+
- name: Update image tag in deployment manifest
42+
env:
43+
SERVICE_NAME: "agent_bot" # e.g., "timelogging_service", "frontend_web", "authentication"
44+
DEPLOYMENT_FILE: "agent-bot-deployment.yaml" # e.g., "timelogging-deployment.yaml", "frontend-deployment.yaml"
45+
run: |
46+
cd k8s-config
47+
NEW_IMAGE="ghcr.io/techtorque-2025/${SERVICE_NAME}:${{ steps.info.outputs.branch }}-${{ steps.info.outputs.sha }}"
48+
export NEW_IMAGE
49+
50+
echo "🔄 Updating ${DEPLOYMENT_FILE} to use image: ${NEW_IMAGE}"
51+
52+
yq eval -i \
53+
'(select(.kind == "Deployment") | .spec.template.spec.containers[0].image) = env(NEW_IMAGE)' \
54+
k8s/services/${DEPLOYMENT_FILE}
55+
56+
echo "✅ Updated manifest:"
57+
yq eval 'select(.kind == "Deployment") | .spec.template.spec.containers[0].image' k8s/services/${DEPLOYMENT_FILE}
58+
59+
- name: Commit and push changes
60+
env:
61+
SERVICE_NAME: "agent_bot"
62+
run: |
63+
cd k8s-config
64+
git config user.name "github-actions[bot]"
65+
git config user.email "github-actions[bot]@users.noreply.github.com"
66+
67+
git add k8s/services/
68+
69+
if git diff --cached --quiet; then
70+
echo "⚠️ No changes detected, skipping commit"
71+
exit 0
72+
fi
73+
74+
git commit -m "chore(${SERVICE_NAME}): update image to ${{ steps.info.outputs.branch }}-${{ steps.info.outputs.sha }}" \
75+
-m "Triggered by: ${{ github.event.workflow_run.html_url }}"
76+
77+
git push origin ${{ steps.info.outputs.branch }}
78+
79+
echo "✅ Pushed manifest update to k8s-config/${{ steps.info.outputs.branch }}"
80+
echo "🚀 ArgoCD will automatically deploy this change"
81+
82+
- name: Summary
83+
run: |
84+
echo "### 🎉 Manifest Update Complete" >> $GITHUB_STEP_SUMMARY
85+
echo "" >> $GITHUB_STEP_SUMMARY
86+
echo "- **Branch**: ${{ steps.info.outputs.branch }}" >> $GITHUB_STEP_SUMMARY
87+
echo "- **Image Tag**: ${{ steps.info.outputs.branch }}-${{ steps.info.outputs.sha }}" >> $GITHUB_STEP_SUMMARY
88+
echo "- **Manifest Updated**: k8s/services/agent-bot-deployment.yaml" >> $GITHUB_STEP_SUMMARY
89+
echo "- **Next Step**: ArgoCD will sync this change to the cluster" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)