Skip to content
This repository was archived by the owner on Nov 23, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# .github/workflows/build.yml
name: Build and Package Service
on:
push:
branches:
- 'main'
- 'devOps'
- 'dev'
pull_request:
branches:
- 'main'
- 'devOps'
- 'dev'

permissions:
contents: read
packages: write

jobs:
build-test:
name: Install and Build (Tests Skipped)
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

- name: Build with Maven (Skip Tests)
run: mvn -B clean package -DskipTests --file admin-service/pom.xml

- name: Upload Build Artifact (JAR)
uses: actions/upload-artifact@v4
with:
name: admin-service-jar
path: admin-service/target/*.jar

build-and-push-docker:
name: Build & Push Docker Image
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/devOps' || github.ref == 'refs/heads/dev'
runs-on: ubuntu-latest
needs: build-test

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download JAR Artifact
uses: actions/download-artifact@v4
with:
name: admin-service-jar
path: admin-service/target/

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/techtorque-2025/admin_service
tags: |
type=sha,prefix=
type=raw,value=latest,enable={{is_default_branch}}

- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
60 changes: 60 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Admin_Service/.github/workflows/deploy.yml

name: Deploy Admin Service to Kubernetes

on:
workflow_run:
workflows: ["Build and Package Service"]
types:
- completed
branches:
- 'main'
- 'devOps'

jobs:
deploy:
name: Deploy Admin Service to Kubernetes
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest

steps:
- name: Get Commit SHA
id: get_sha
run: |
echo "sha=$(echo ${{ github.event.workflow_run.head_sha }} | cut -c1-7)" >> $GITHUB_OUTPUT

- name: Checkout K8s Config Repo
uses: actions/checkout@v4
with:
repository: 'TechTorque-2025/k8s-config'
token: ${{ secrets.REPO_ACCESS_TOKEN }}
path: 'config-repo'
ref: 'main'

- name: Install kubectl
uses: azure/setup-kubectl@v3

- name: Install yq
run: |
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
sudo chmod +x /usr/bin/yq

- name: Set Kubernetes context
uses: azure/k8s-set-context@v4
with:
kubeconfig: ${{ secrets.KUBE_CONFIG_DATA }}

- name: Update image tag in YAML
run: |
yq -i '(select(.kind == "Deployment") | .spec.template.spec.containers[0].image) = "ghcr.io/techtorque-2025/admin_service:${{ steps.get_sha.outputs.sha }}"' config-repo/k8s/services/admin-deployment.yaml

- name: Display file contents before apply
run: |
echo "--- Displaying k8s/services/admin-deployment.yaml ---"
cat config-repo/k8s/services/admin-deployment.yaml
echo "------------------------------------------------------"

- name: Deploy to Kubernetes
run: |
kubectl apply -f config-repo/k8s/services/admin-deployment.yaml
kubectl rollout status deployment/admin-deployment
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Dockerfile for admin-service

# --- Build Stage ---
# Use the official Maven image which contains the Java JDK
FROM maven:3.8-eclipse-temurin-17 AS build

# Set the working directory
WORKDIR /app

# Copy the pom.xml and download dependencies
COPY admin-service/pom.xml .
RUN mvn -B dependency:go-offline

# Copy the rest of the source code and build the application
# Note: We copy the pom.xml *first* to leverage Docker layer caching.
COPY admin-service/src ./src
RUN mvn -B clean package -DskipTests

# --- Run Stage ---
# Use a minimal JRE image for the final container
FROM eclipse-temurin:17-jre-jammy

# Set a working directory
WORKDIR /app

# Copy the built JAR from the 'build' stage
# The wildcard is used in case the version number is in the JAR name
COPY --from=build /app/target/*.jar app.jar

# Expose the port your application runs on
EXPOSE 8087

# The command to run your application
ENTRYPOINT ["java", "-jar", "app.jar"]