From 13afb0e166893581b1cec1eda52906a4d3834028 Mon Sep 17 00:00:00 2001 From: RandithaK Date: Sat, 8 Nov 2025 16:30:17 +0530 Subject: [PATCH 1/2] feat: Add GitHub Actions workflows for building, packaging, and deploying the Admin Service to Kubernetes --- .github/workflows/build.yaml | 90 +++++++++++++++++++++++++++++++++++ .github/workflows/deploy.yaml | 60 +++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..e71c76b --- /dev/null +++ b/.github/workflows/build.yaml @@ -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 }} diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..22dc98d --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -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 From e39724c1d2253feff6300f7070df0804e874fce7 Mon Sep 17 00:00:00 2001 From: RandithaK Date: Sat, 8 Nov 2025 16:40:18 +0530 Subject: [PATCH 2/2] feat: Add Dockerfile for building and running the microservice --- Dockerfile | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..46cd3bf --- /dev/null +++ b/Dockerfile @@ -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"]