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

Commit 1aabdb6

Browse files
authored
Merge pull request #11 from TechTorque-2025/feat/gitops-workflow
chore: sync gitops workflow updates
2 parents 8f9cbfc + 110eeb6 commit 1aabdb6

4 files changed

Lines changed: 114 additions & 34 deletions

File tree

.github/workflows/build.yaml

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
name: Build and Package Service
1+
name: Build and Push Docker Image
2+
23
on:
34
push:
45
branches:
56
- 'main'
6-
- 'devOps'
7-
- 'dev'
8-
pull_request:
9-
branches:
10-
- 'main'
11-
- 'devOps'
127
- 'dev'
138

149
permissions:
1510
contents: read
16-
packages: write
11+
packages: write
1712

1813
jobs:
19-
build-test:
20-
name: Install and Build (Tests Skipped)
14+
build-and-push:
15+
name: Build & Push Docker Image
2116
runs-on: ubuntu-latest
2217

2318
steps:
@@ -39,39 +34,26 @@ jobs:
3934
restore-keys: |
4035
${{ runner.os }}-maven-
4136
42-
- name: Build with Maven (Skip Tests)
37+
- name: Build with Maven
4338
run: mvn -B clean package -DskipTests --file time-logging-service/pom.xml
4439

45-
- name: Upload Build Artifact (JAR)
46-
uses: actions/upload-artifact@v4
47-
with:
48-
name: time-logging-service-jar
49-
path: time-logging-service/target/*.jar
40+
- name: Extract branch name
41+
id: branch
42+
run: |
43+
BRANCH_NAME=${GITHUB_REF#refs/heads/}
44+
echo "name=${BRANCH_NAME}" >> $GITHUB_OUTPUT
45+
echo "📍 Building for branch: ${BRANCH_NAME}"
5046
51-
build-and-push-docker:
52-
name: Build & Push Docker Image
53-
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/devOps' || github.ref == 'refs/heads/dev'
54-
runs-on: ubuntu-latest
55-
needs: build-test
56-
57-
steps:
58-
- name: Checkout code
59-
uses: actions/checkout@v4
60-
61-
- name: Download JAR Artifact
62-
uses: actions/download-artifact@v4
63-
with:
64-
name: time-logging-service-jar
65-
path: time-logging-service/target/
66-
67-
- name: Docker meta
47+
- name: Docker meta (with branch-aware tags)
6848
id: meta
6949
uses: docker/metadata-action@v5
7050
with:
7151
images: ghcr.io/techtorque-2025/timelogging_service
7252
tags: |
73-
type=sha,prefix=
53+
type=raw,value=${{ steps.branch.outputs.name }}-{{sha}},enable=true
7454
type=raw,value=latest,enable={{is_default_branch}}
55+
flavor: |
56+
latest=false
7557
7658
- name: Log in to GHCR
7759
uses: docker/login-action@v3
@@ -87,3 +69,12 @@ jobs:
8769
push: true
8870
tags: ${{ steps.meta.outputs.tags }}
8971
labels: ${{ steps.meta.outputs.labels }}
72+
73+
- name: Image Summary
74+
run: |
75+
echo "### 🐳 Docker Image Built" >> $GITHUB_STEP_SUMMARY
76+
echo "" >> $GITHUB_STEP_SUMMARY
77+
echo "**Tags pushed:**" >> $GITHUB_STEP_SUMMARY
78+
echo '```' >> $GITHUB_STEP_SUMMARY
79+
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
80+
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"] # Or "Build, Test, and Package Frontend" for Frontend_Web
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: "time_logging_service" # e.g., "timelogging_service", "frontend_web", "authentication"
44+
DEPLOYMENT_FILE: "timelogging-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: "timelogging_service"
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/timelogging-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)