From 64d520090492d7a398f06ec8b0a438911892f699 Mon Sep 17 00:00:00 2001 From: Sowmya Date: Sat, 16 May 2026 16:11:03 +0530 Subject: [PATCH 1/5] Added Docker Kubernetes Helm and CI pipeline --- .github/workflows/ci-crewmeister.yaml | 36 +++++++++++++++++++++++++++ Dockerfile | 9 +++++++ K8s/deployment.yaml | 35 ++++++++++++++++++++++++++ K8s/mysql-deployment.yaml | 32 ++++++++++++++++++++++++ K8s/mysql-service.yaml | 14 +++++++++++ K8s/service.yaml | 16 ++++++++++++ docker-compose.yaml | 24 ++++++++++++++++++ helm/Chart.yaml | 6 +++++ helm/templates/deployment.yaml | 35 ++++++++++++++++++++++++++ helm/templates/mysql-deployment.yaml | 32 ++++++++++++++++++++++++ helm/templates/mysql-service.yaml | 14 +++++++++++ helm/templates/service.yaml | 16 ++++++++++++ helm/values.yaml | 15 +++++++++++ 13 files changed, 284 insertions(+) create mode 100644 .github/workflows/ci-crewmeister.yaml create mode 100644 Dockerfile create mode 100644 K8s/deployment.yaml create mode 100644 K8s/mysql-deployment.yaml create mode 100644 K8s/mysql-service.yaml create mode 100644 K8s/service.yaml create mode 100644 docker-compose.yaml create mode 100644 helm/Chart.yaml create mode 100644 helm/templates/deployment.yaml create mode 100644 helm/templates/mysql-deployment.yaml create mode 100644 helm/templates/mysql-service.yaml create mode 100644 helm/templates/service.yaml create mode 100644 helm/values.yaml diff --git a/.github/workflows/ci-crewmeister.yaml b/.github/workflows/ci-crewmeister.yaml new file mode 100644 index 0000000..786e36c --- /dev/null +++ b/.github/workflows/ci-crewmeister.yaml @@ -0,0 +1,36 @@ +name: Crewmeister CI Pipeline + +on: + push: + branches: + - main + - feature/* + + pull_request: + branches: + - main + +jobs: + + build: + runs-on: ubuntu-latest + + steps: + + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Setup Java 17 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + + - name: Build Application + run: ./mvnw clean package -DskipTests + + - name: Build Docker Image + run: docker build -t crewmeister-app . + + - name: Verify Docker Image + run: docker images \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..516b42f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM eclipse-temurin:17-jdk-alpine + +WORKDIR /app + +COPY target/*.jar app.jar + +EXPOSE 8080 + +ENTRYPOINT ["java","-jar","app.jar"] \ No newline at end of file diff --git a/K8s/deployment.yaml b/K8s/deployment.yaml new file mode 100644 index 0000000..94c6911 --- /dev/null +++ b/K8s/deployment.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: Deployment + +metadata: + name: crewmeister-app + +spec: + replicas: 1 + + selector: + matchLabels: + app: crewmeister-app + + template: + metadata: + labels: + app: crewmeister-app + + spec: + containers: + - name: crewmeister-app + image: devops-coding-challenge-app:latest + + ports: + - containerPort: 8080 + + env: + - name: SPRING_DATASOURCE_URL + value: jdbc:mysql://mysql:3306/challenge?createDatabaseIfNotExist=true + + - name: SPRING_DATASOURCE_USERNAME + value: root + + - name: SPRING_DATASOURCE_PASSWORD + value: dev \ No newline at end of file diff --git a/K8s/mysql-deployment.yaml b/K8s/mysql-deployment.yaml new file mode 100644 index 0000000..a4e3e1f --- /dev/null +++ b/K8s/mysql-deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment + +metadata: + name: mysql + +spec: + replicas: 1 + + selector: + matchLabels: + app: mysql + + template: + metadata: + labels: + app: mysql + + spec: + containers: + - name: mysql + image: mysql:8 + + ports: + - containerPort: 3306 + + env: + - name: MYSQL_ROOT_PASSWORD + value: dev + + - name: MYSQL_DATABASE + value: challenge \ No newline at end of file diff --git a/K8s/mysql-service.yaml b/K8s/mysql-service.yaml new file mode 100644 index 0000000..aabaecc --- /dev/null +++ b/K8s/mysql-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service + +metadata: + name: mysql + +spec: + selector: + app: mysql + + ports: + - protocol: TCP + port: 3306 + targetPort: 3306 \ No newline at end of file diff --git a/K8s/service.yaml b/K8s/service.yaml new file mode 100644 index 0000000..a51fa21 --- /dev/null +++ b/K8s/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service + +metadata: + name: crewmeister-service + +spec: + selector: + app: crewmeister-app + + ports: + - protocol: TCP + port: 80 + targetPort: 8080 + + type: LoadBalancer \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..c1c131a --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,24 @@ +version: '3.8' + +services: + + mysql: + image: mysql:8 + container_name: mysql + environment: + MYSQL_ROOT_PASSWORD: dev + MYSQL_DATABASE: challenge + ports: + - "3306:3306" + + app: + build: . + container_name: crewmeister-app + depends_on: + - mysql + ports: + - "8080:8080" + environment: + SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/challenge?createDatabaseIfNotExist=true + SPRING_DATASOURCE_USERNAME: root + SPRING_DATASOURCE_PASSWORD: dev \ No newline at end of file diff --git a/helm/Chart.yaml b/helm/Chart.yaml new file mode 100644 index 0000000..2beb463 --- /dev/null +++ b/helm/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: crewmeister-app +description: Crewmeister DevOps Challenge +type: application +version: 1.0.0 +appVersion: "1.0" \ No newline at end of file diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml new file mode 100644 index 0000000..a376c00 --- /dev/null +++ b/helm/templates/deployment.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: Deployment + +metadata: + name: crewmeister-app + +spec: + replicas: {{ .Values.replicaCount }} + + selector: + matchLabels: + app: crewmeister-app + + template: + metadata: + labels: + app: crewmeister-app + + spec: + containers: + - name: crewmeister-app + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + + ports: + - containerPort: 8080 + + env: + - name: SPRING_DATASOURCE_URL + value: jdbc:mysql://mysql:3306/challenge?createDatabaseIfNotExist=true + + - name: SPRING_DATASOURCE_USERNAME + value: {{ .Values.mysql.username }} + + - name: SPRING_DATASOURCE_PASSWORD + value: {{ .Values.mysql.password }} \ No newline at end of file diff --git a/helm/templates/mysql-deployment.yaml b/helm/templates/mysql-deployment.yaml new file mode 100644 index 0000000..a4e3e1f --- /dev/null +++ b/helm/templates/mysql-deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment + +metadata: + name: mysql + +spec: + replicas: 1 + + selector: + matchLabels: + app: mysql + + template: + metadata: + labels: + app: mysql + + spec: + containers: + - name: mysql + image: mysql:8 + + ports: + - containerPort: 3306 + + env: + - name: MYSQL_ROOT_PASSWORD + value: dev + + - name: MYSQL_DATABASE + value: challenge \ No newline at end of file diff --git a/helm/templates/mysql-service.yaml b/helm/templates/mysql-service.yaml new file mode 100644 index 0000000..aabaecc --- /dev/null +++ b/helm/templates/mysql-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service + +metadata: + name: mysql + +spec: + selector: + app: mysql + + ports: + - protocol: TCP + port: 3306 + targetPort: 3306 \ No newline at end of file diff --git a/helm/templates/service.yaml b/helm/templates/service.yaml new file mode 100644 index 0000000..3e87ce2 --- /dev/null +++ b/helm/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service + +metadata: + name: crewmeister-service + +spec: + selector: + app: crewmeister-app + + ports: + - protocol: TCP + port: {{ .Values.service.port }} + targetPort: 8080 + + type: {{ .Values.service.type }} \ No newline at end of file diff --git a/helm/values.yaml b/helm/values.yaml new file mode 100644 index 0000000..58ddb87 --- /dev/null +++ b/helm/values.yaml @@ -0,0 +1,15 @@ +replicaCount: 1 + +image: + repository: devops-coding-challenge-app + tag: latest + +service: + type: LoadBalancer + port: 80 + +mysql: + host: mysql + database: challenge + username: root + password: dev \ No newline at end of file From 3c1a6f0ab91cefcd0bb7fee2e2e482c7ad211542 Mon Sep 17 00:00:00 2001 From: Sowmya Date: Sat, 16 May 2026 16:14:46 +0530 Subject: [PATCH 2/5] pipeline test --- .github/workflows/ci-crewmeister.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci-crewmeister.yaml b/.github/workflows/ci-crewmeister.yaml index 786e36c..bca7109 100644 --- a/.github/workflows/ci-crewmeister.yaml +++ b/.github/workflows/ci-crewmeister.yaml @@ -3,8 +3,7 @@ name: Crewmeister CI Pipeline on: push: branches: - - main - - feature/* + - sowmya-crewmeister-challenge pull_request: branches: From 725397c2f367b8b02d159c3e5c47b8a6a03e598d Mon Sep 17 00:00:00 2001 From: Sowmya Date: Sat, 16 May 2026 16:39:16 +0530 Subject: [PATCH 3/5] ci pipeline run --- .github/workflows/{ci-crewmeister.yaml => ci.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{ci-crewmeister.yaml => ci.yaml} (100%) diff --git a/.github/workflows/ci-crewmeister.yaml b/.github/workflows/ci.yaml similarity index 100% rename from .github/workflows/ci-crewmeister.yaml rename to .github/workflows/ci.yaml From 419571eff6fbf53a1649cb8c9a521b27ad67a197 Mon Sep 17 00:00:00 2001 From: Sowmya Date: Sat, 16 May 2026 16:45:11 +0530 Subject: [PATCH 4/5] ci pipeline run --- .github/workflows/ci.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bca7109..649671a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -10,7 +10,6 @@ on: - main jobs: - build: runs-on: ubuntu-latest From f520266f01a4a995e96660e9bc6bd33ef377a6d0 Mon Sep 17 00:00:00 2001 From: Sowmya Date: Sat, 16 May 2026 17:15:34 +0530 Subject: [PATCH 5/5] updated the tf code --- K8s/deployment.yaml | 15 +++++++- helm/templates/deployment.yaml | 15 +++++++- terraform/main.tf | 65 ++++++++++++++++++++++++++++++++++ terraform/outputs.tf | 3 ++ terraform/provider.tf | 12 +++++++ terraform/variables.tf | 3 ++ 6 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 terraform/main.tf create mode 100644 terraform/outputs.tf create mode 100644 terraform/provider.tf create mode 100644 terraform/variables.tf diff --git a/K8s/deployment.yaml b/K8s/deployment.yaml index 94c6911..e51ecbe 100644 --- a/K8s/deployment.yaml +++ b/K8s/deployment.yaml @@ -32,4 +32,17 @@ spec: value: root - name: SPRING_DATASOURCE_PASSWORD - value: dev \ No newline at end of file + value: dev + livenessProbe: + httpGet: + path: /actuator/health + port: 8080 + initialDelaySeconds: 30 + periodSeconds: 10 + + readinessProbe: + httpGet: + path: /actuator/health + port: 8080 + initialDelaySeconds: 10 + periodSeconds: 5 \ No newline at end of file diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml index a376c00..74da573 100644 --- a/helm/templates/deployment.yaml +++ b/helm/templates/deployment.yaml @@ -32,4 +32,17 @@ spec: value: {{ .Values.mysql.username }} - name: SPRING_DATASOURCE_PASSWORD - value: {{ .Values.mysql.password }} \ No newline at end of file + value: {{ .Values.mysql.password }} + livenessProbe: + httpGet: + path: /actuator/health + port: 8080 + initialDelaySeconds: 30 + periodSeconds: 10 + + readinessProbe: + httpGet: + path: /actuator/health + port: 8080 + initialDelaySeconds: 10 + periodSeconds: 5 \ No newline at end of file diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000..9350c09 --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,65 @@ +resource "kubernetes_namespace" "crewmeister" { + metadata { + name = var.namespace + } +} + +resource "kubernetes_deployment" "app" { + + metadata { + name = "crewmeister-app" + namespace = kubernetes_namespace.crewmeister.metadata[0].name + + labels = { + app = "crewmeister-app" + } + } + + spec { + + replicas = 1 + + selector { + match_labels = { + app = "crewmeister-app" + } + } + + template { + + metadata { + labels = { + app = "crewmeister-app" + } + } + + spec { + + container { + + image = "devops-coding-challenge-app:latest" + name = "crewmeister-app" + + port { + container_port = 8080 + } + + env { + name = "SPRING_DATASOURCE_URL" + value = "jdbc:mysql://mysql:3306/challenge?createDatabaseIfNotExist=true" + } + + env { + name = "SPRING_DATASOURCE_USERNAME" + value = "root" + } + + env { + name = "SPRING_DATASOURCE_PASSWORD" + value = "dev" + } + } + } + } + } +} \ No newline at end of file diff --git a/terraform/outputs.tf b/terraform/outputs.tf new file mode 100644 index 0000000..e38f48f --- /dev/null +++ b/terraform/outputs.tf @@ -0,0 +1,3 @@ +output "namespace" { + value = kubernetes_namespace.crewmeister.metadata[0].name +} \ No newline at end of file diff --git a/terraform/provider.tf b/terraform/provider.tf new file mode 100644 index 0000000..72c69fb --- /dev/null +++ b/terraform/provider.tf @@ -0,0 +1,12 @@ +terraform { + required_providers { + kubernetes = { + source = "hashicorp/kubernetes" + version = "~> 2.0" + } + } +} + +provider "kubernetes" { + config_path = "~/.kube/config" +} \ No newline at end of file diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 0000000..1f33dbd --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,3 @@ +variable "namespace" { + default = "crewmeister" +} \ No newline at end of file