From 4b086e7ac92a855ea244f953bd8a130b375a3345 Mon Sep 17 00:00:00 2001 From: surya Date: Wed, 20 Nov 2024 10:58:04 +0530 Subject: [PATCH 1/3] pipeline-1 --- .../continuous-integration-build.yml | 96 +++++++++++++++++-- Docker file | 8 ++ deployment-k8/deployment.yaml | 71 ++++++++++++++ 3 files changed, 166 insertions(+), 9 deletions(-) create mode 100644 Docker file create mode 100644 deployment-k8/deployment.yaml diff --git a/.github/workflows/continuous-integration-build.yml b/.github/workflows/continuous-integration-build.yml index 57061db9..daaaa377 100644 --- a/.github/workflows/continuous-integration-build.yml +++ b/.github/workflows/continuous-integration-build.yml @@ -1,13 +1,91 @@ -name: CI Build +name: gs-spring-boot-suriya on: - push: - branches: - - main - pull_request: - branches: - - main + workflow_dispatch: + push: + branches: + -main jobs: - build: - uses: spring-guides/getting-started-macros/.github/workflows/build_initial_complete_maven_gradle.yml@main + deploy-gs-spring-boot-suriya: + runs-on: ubuntu-latest + steps: + - name: "checkout to branch" + uses: actions/checkout@v4 + + - name: "setting up java 17" + uses: actions/checkout@v4 + with: + distribution: "Spring Boot" + java-version: "17" + + - name: "set up Maven" + uses: actions/setup-java@v4 + with: + maven-version: 3.8.2 + + - name: "build jar with maven" + run: | + #!/bin/bash + + mvn package --file pom.xml + shell: bash + + - name: "Building docker image" + run: | + #!/bin/bash + + docker build -t spring-boot . + shell: bash + + - name: "Setup GCP SDK" + uses: google-github-actions/setup-gcloud@v2 + + - name: "Configure Service Account" + uses: google-github-actions/auth@v2 + with: + credentials_json: "${{ secrets.SERVICE_ACCOUNT_CREDS }}" + + - name: "Configure k8 component" + run: | + #!/bin/bash + + gcloud components install kubectl gke-gcloud-auth-plugin + + gcloud config set project prefab-icon-441814-j7 + + gcloud config set compute/region us-central1 + + gcloud container clusters get-credentials surya-gke-cluster --region=us-central1 + + kubectl version --client + shell: bash + + - name: "Setting up Docker Credentials" + run: | + #!/bin/bash + + gcloud auth configure-docker us-central1-docker.pkg.dev + shell: bash + + - name: "Upload image to gcp artifacts" + run: | + #!/bin/bash + + docker tag spring-boot:latest us-central1-docker.pkg.dev/prefab-icon-441814-j7/surya-artifact/spring-boot:latest + + docker push us-central1-docker.pkg.dev/prefab-icon-441814-j7/surya-artifact/spring-boot:latest + + - name: "Create spring-boot stream deployment" + run: | + #!/bin/bash + + kubectl apply -f deployment.yml --validate=false + kubectl rollout restart deployment + + shell: bash + working-directory: deployment-k8 + + + + diff --git a/Docker file b/Docker file new file mode 100644 index 00000000..c0548aa3 --- /dev/null +++ b/Docker file @@ -0,0 +1,8 @@ +# Use an official openjdk image to run your application +FROM openjdk:17-jdk-slim + +# Copy the JAR file from the current directory to the container +COPY target/myapp.jar /app.jar + +# Set the command to run the application +ENTRYPOINT ["java", "-jar", "/app.jar"] \ No newline at end of file diff --git a/deployment-k8/deployment.yaml b/deployment-k8/deployment.yaml new file mode 100644 index 00000000..226d1148 --- /dev/null +++ b/deployment-k8/deployment.yaml @@ -0,0 +1,71 @@ +kind: Deployment +apiVersion: apps/v1 +metadata: + name: springboot-deployment + namespace: surya-namespace +spec: + replicas: 15 + revisionHistoryLimit: 5 + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + type: RollingUpdate + selector: + matchLabels: + run: springboot-deployment + template: + metadata: + labels: + run: springboot-deployment + spec: + containers: + - name: springboot-deployment + image: us-central1-docker.pkg.dev/prefab-icon-441814-j7/surya-artifact/spring-boot:latest + imagePullPolicy: Always + ports: + - containerPort: 8080 + protocol: TCP + env: + - name: APP_NAME + value: surya-gcp-streams + - name: ENV_PROFILE + value: TEST + resources: + limits: + cpu: 600m + memory: 2Gi + requests: + cpu: 90m + memory: 1Gi + livenessProbe: + exec: + command: + - /bin/true + initial Delay Seconds: 120 + periodSeconds: 30 + successThreshold: 1 + failureThreshold: 5 + timeoutSeconds: 30 + readinessProbe: + exec: + command: + - /bin/true + initialDelaySeconds: 120 + periodSeconds: 30 + successThreshold: 1 + failureThreshold: 5 + timeoutSeconds: 30 + securityContext: + runAsUser: 1005 + capabilities: + drop: + - KILL + - MKNOD + - SYS_CHROOT + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + restartPolicy: Always + terminationGracePeriodSeconds: 30 + dnsPolicy: ClusterFirst + schedulerName: default-scheduler \ No newline at end of file From 6bfea1956299f22aff43e2402fd29a6503f1ddf0 Mon Sep 17 00:00:00 2001 From: surya Date: Wed, 20 Nov 2024 11:12:52 +0530 Subject: [PATCH 2/3] pipeline-1 --- .github/workflows/continuous-integration-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration-build.yml b/.github/workflows/continuous-integration-build.yml index daaaa377..b48d68d4 100644 --- a/.github/workflows/continuous-integration-build.yml +++ b/.github/workflows/continuous-integration-build.yml @@ -22,7 +22,7 @@ jobs: - name: "set up Maven" uses: actions/setup-java@v4 with: - maven-version: 3.8.2 + maven-version: 4.0.0 - name: "build jar with maven" run: | From 3d89aabb63422895d4b44a32efb27495839b2aa3 Mon Sep 17 00:00:00 2001 From: surya Date: Wed, 20 Nov 2024 11:18:18 +0530 Subject: [PATCH 3/3] pipeline-1 --- .github/workflows/continuous-integration-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration-build.yml b/.github/workflows/continuous-integration-build.yml index b48d68d4..85c81ec5 100644 --- a/.github/workflows/continuous-integration-build.yml +++ b/.github/workflows/continuous-integration-build.yml @@ -1,4 +1,4 @@ -name: gs-spring-boot-suriya +name: gs-spring-boot-suriya #suriya-main on: workflow_dispatch: