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

Commit 3755542

Browse files
authored
Merge pull request #8 from TechTorque-2025/dev
Dev
2 parents b487baf + e654da1 commit 3755542

4 files changed

Lines changed: 156 additions & 35 deletions

File tree

.github/workflows/build-test.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 JDK 17
22+
uses: actions/setup-java@v4
23+
with:
24+
java-version: '17'
25+
distribution: 'temurin'
26+
cache: maven
27+
28+
- name: Cache Maven packages
29+
uses: actions/cache@v4
30+
with:
31+
path: ~/.m2/repository
32+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
33+
restore-keys: |
34+
${{ runner.os }}-maven-
35+
36+
- name: Build with Maven
37+
run: mvn -B clean package -DskipTests --file admin-service/pom.xml
38+
39+
- name: Test Summary
40+
run: |
41+
echo "### ✅ Build Successful" >> $GITHUB_STEP_SUMMARY
42+
echo "Ready for review and merge" >> $GITHUB_STEP_SUMMARY

.github/workflows/build.yaml

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
# .github/workflows/build.yml
2-
name: Build and Package Service
1+
name: Build and Push Docker Image
2+
33
on:
44
push:
55
branches:
66
- 'main'
7-
- 'devOps'
8-
- 'dev'
9-
pull_request:
10-
branches:
11-
- 'main'
12-
- 'devOps'
137
- 'dev'
148

159
permissions:
1610
contents: read
17-
packages: write
11+
packages: write
1812

1913
jobs:
20-
build-test:
21-
name: Install and Build (Tests Skipped)
14+
build-and-push:
15+
name: Build & Push Docker Image
2216
runs-on: ubuntu-latest
2317

2418
steps:
@@ -40,39 +34,26 @@ jobs:
4034
restore-keys: |
4135
${{ runner.os }}-maven-
4236
43-
- name: Build with Maven (Skip Tests)
37+
- name: Build with Maven
4438
run: mvn -B clean package -DskipTests --file admin-service/pom.xml
4539

46-
- name: Upload Build Artifact (JAR)
47-
uses: actions/upload-artifact@v4
48-
with:
49-
name: admin-service-jar
50-
path: admin-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}"
5146
52-
build-and-push-docker:
53-
name: Build & Push Docker Image
54-
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/devOps' || github.ref == 'refs/heads/dev'
55-
runs-on: ubuntu-latest
56-
needs: build-test
57-
58-
steps:
59-
- name: Checkout code
60-
uses: actions/checkout@v4
61-
62-
- name: Download JAR Artifact
63-
uses: actions/download-artifact@v4
64-
with:
65-
name: admin-service-jar
66-
path: admin-service/target/
67-
68-
- name: Docker meta
47+
- name: Docker meta (with branch-aware tags)
6948
id: meta
7049
uses: docker/metadata-action@v5
7150
with:
7251
images: ghcr.io/techtorque-2025/admin_service
7352
tags: |
74-
type=sha,prefix=
53+
type=raw,value=${{ steps.branch.outputs.name }}-{{sha}},enable=true
7554
type=raw,value=latest,enable={{is_default_branch}}
55+
flavor: |
56+
latest=false
7657
7758
- name: Log in to GHCR
7859
uses: docker/login-action@v3
@@ -88,3 +69,12 @@ jobs:
8869
push: true
8970
tags: ${{ steps.meta.outputs.tags }}
9071
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"]
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: "admin_service" # e.g., "timelogging_service", "frontend_web", "authentication"
44+
DEPLOYMENT_FILE: "admin-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: "admin_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/admin-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)