-
Notifications
You must be signed in to change notification settings - Fork 377
Final #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: DevOps
Are you sure you want to change the base?
Final #31
Changes from all commits
0977b7e
157c4f6
df53f74
3eb7751
43b6b2a
a291f89
6837bfe
96ef1f2
a71528a
e9d9390
3ff137e
1574abe
7f3a681
c540fd6
b5e8149
e6c9727
6e8aee2
86ad8bd
d0a31ff
502420f
02d37d5
dfdfd18
c56bbe9
ddcb169
15d0f21
37b6c4e
e0b3c45
cb930ce
ccff992
d0b6471
64223fb
5f2c13e
7d724c0
b02e0a8
1bc0ed5
f3357df
1b5fc72
f241fe1
c0fcac6
8be0234
37f9e69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,12 @@ | ||
| #---------------------------------- | ||
| # Stage 1 | ||
| #---------------------------------- | ||
|
|
||
| # Import docker image with maven installed | ||
| FROM maven:3.8.3-openjdk-17 as builder | ||
|
|
||
| # Add maintainer, so that new user will understand who had written this Dockerfile | ||
| MAINTAINER Madhup Pandey<madhuppandey2908@gmail.com> | ||
|
|
||
| # Add labels to the image to filter out if we have multiple application running | ||
| LABEL app=bankapp | ||
|
|
||
| # Set working directory | ||
| WORKDIR /src | ||
|
|
||
| # Copy source code from local to container | ||
| COPY . /src | ||
|
|
||
| # Build application and skip test cases | ||
| #---------------------------------stage1----------------------------------------- | ||
| FROM maven:3.9.6-eclipse-temurin-17-alpine AS builder | ||
| WORKDIR /app | ||
| COPY . . | ||
| RUN mvn clean install -DskipTests=true | ||
|
|
||
| #-------------------------------------- | ||
| # Stage 2 | ||
| #-------------------------------------- | ||
|
|
||
| # Import small size java image | ||
| FROM openjdk:17-alpine as deployer | ||
|
|
||
| # Copy build from stage 1 (builder) | ||
| COPY --from=builder /src/target/*.jar /src/target/bankapp.jar | ||
|
|
||
| # Expose application port | ||
| EXPOSE 8080 | ||
|
|
||
| # Start the application | ||
| ENTRYPOINT ["java", "-jar", "/src/target/bankapp.jar"] | ||
|
|
||
| #---------------------------------stage2----------------------------------------- | ||
| FROM openjdk:17-slim | ||
| WORKDIR /app | ||
| COPY --from=builder /app/target/*.jar /app/target/bank.jar | ||
| EXPOSE 8081 | ||
| CMD ["java","-jar","/app/target/bank.jar"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,43 +4,34 @@ services: | |
| image: mysql:latest | ||
| container_name: mysql | ||
| environment: | ||
| - MYSQL_ROOT_PASSWORD=Test@123 | ||
| - MYSQL_DATABASE=BankDB | ||
| MYSQL_ROOT_PASSWORD: Test@123 | ||
| MYSQL_DATABASE: bankappdb | ||
| ports: | ||
|
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quote environment variable values. MYSQL_ROOT_PASSWORD: "Test@123"
SPRING_DATASOURCE_URL: "jdbc:mysql://mysql:3306/bankappdb?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC" |
||
| - "3306:3306" | ||
| volumes: | ||
| - bankapp-volume:/var/lib/mysql | ||
| networks: | ||
| - bankapp | ||
| healthcheck: | ||
| test: ["CMD", "mysqladmin", "ping", "-h", "localhost"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 3 | ||
| start_period: 30s | ||
|
|
||
|
|
||
| mainapp: | ||
| image: ${DUSER}/${IMAGE} | ||
| container_name: Bankapp | ||
| image: bankapp:latest | ||
| container_name: "Bankapp" | ||
| environment: | ||
| - SPRING_DATASOURCE_USERNAME=root | ||
| - SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/BankDB?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC | ||
| - SPRING_DATASOURCE_PASSWORD=Test@123 | ||
| SPRING_DATASOURCE_USERNAME: root | ||
| SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/bankappdb?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC | ||
| SPRING_DATASOURCE_PASSWORD: Test@123 | ||
|
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure port mapping matches the app’s exposed port. - - "8080:8080"
+ - "8081:8081"
|
||
| ports: | ||
| - "8080:8080" | ||
| depends_on: | ||
| mysql: | ||
| condition: service_healthy | ||
| - mysql | ||
| networks: | ||
| - bankapp | ||
| restart: always | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "curl -f http://localhost:8080/actuator/health || exit 1"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
| start_period: 30s | ||
|
|
||
|
|
||
| networks: | ||
| bankapp: | ||
|
|
||
| volumes: | ||
| bankapp-volume: | ||
| bankapp-volume: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| kind: Namespace | ||
| apiVersion: v1 | ||
| metadata: | ||
| name: bank | ||
|
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consolidate duplicate Namespace manifests |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| kind: Deployment | ||
| apiVersion: apps/v1 | ||
| metadata: | ||
| name: bank-deployment | ||
| namespace: bank | ||
| labels: | ||
| app: app | ||
|
Comment on lines
+1
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the misnamed file and unify resource naming. |
||
| spec: | ||
| replicas: 3 | ||
| selector: | ||
| matchLabels: | ||
| app: app | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: app | ||
| spec: | ||
| containers: | ||
| - name: bank-cont | ||
| image: swayamnakshane/mybank:latest | ||
| ports: | ||
| - containerPort: 8081 | ||
| env: | ||
| - name: SPRING_DATASOURCE_USERNAME | ||
| valueFrom: | ||
| configMapKeyRef: | ||
| name: bank-configmap | ||
| key: SPRING_DATASOURCE_USERNAME | ||
| - name: SPRING_DATASOURCE_URL | ||
| valueFrom: | ||
| configMapKeyRef: | ||
| name: bank-configmap | ||
| key: SPRING_DATASOURCE_URL | ||
| - name: SPRING_DATASOURCE_PASSWORD | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: bank-secret | ||
| key: SPRING_DATASOURCE_PASSWORD | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||||||||||||||||||||
| kind: Service | ||||||||||||||||||||||||
| apiVersion: v1 | ||||||||||||||||||||||||
| metadata: | ||||||||||||||||||||||||
| name: bank-svc | ||||||||||||||||||||||||
| namespace: bank | ||||||||||||||||||||||||
| labels: | ||||||||||||||||||||||||
| app: app | ||||||||||||||||||||||||
| spec: | ||||||||||||||||||||||||
| type: NodePort | ||||||||||||||||||||||||
| selector: | ||||||||||||||||||||||||
| app: app | ||||||||||||||||||||||||
| ports: | ||||||||||||||||||||||||
| - protocol: TCP | ||||||||||||||||||||||||
| targetPort: 8080 | ||||||||||||||||||||||||
| port: 8081 | ||||||||||||||||||||||||
| nodePort: 30080 | ||||||||||||||||||||||||
|
Comment on lines
+12
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent target port vs. container port Please verify the container port in spec:
ports:
- protocol: TCP
- targetPort: 8080
+ targetPort: 8081
port: 8081
nodePort: 30080📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| kind: Cluster | ||
| apiVersion: kind.x-k8s.io/v1alpha4 | ||
| nodes: | ||
| - role: control-plane | ||
| image: kindest/node:v1.31.2 | ||
| - role: worker | ||
| image: kindest/node:v1.31.2 | ||
| - role: worker | ||
| image: kindest/node:v1.31.2 | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: bank-configmap | ||
| namespace: bank | ||
| data: | ||
| MYSQL_DATABASE: bankappdb | ||
| SPRING_DATASOURCE_USERNAME: root | ||
| SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/bankappdb?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| apiVersion: apps/v1 | ||
| kind: StatefulSet | ||
| metadata: | ||
| name: mysql-deployment | ||
| namespace: bank | ||
| labels: | ||
| app: bankapp | ||
| annotations: | ||
| argocd.argoproj.io/sync-options: Replace=true | ||
| spec: | ||
| serviceName: mysql | ||
| replicas: 2 | ||
| selector: | ||
| matchLabels: | ||
| app: bankapp | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: bankapp | ||
| spec: | ||
| containers: | ||
| - name: mysql | ||
| image: mysql:latest | ||
| ports: | ||
|
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid using the |
||
| - containerPort: 3306 | ||
| env: | ||
| - name: MYSQL_ROOT_PASSWORD | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: bank-secret | ||
| key: MYSQL_ROOT_PASSWORD | ||
| - name: MYSQL_DATABASE | ||
| valueFrom: | ||
| configMapKeyRef: | ||
| name: bank-configmap | ||
| key: MYSQL_DATABASE | ||
| volumeMounts: | ||
| - name: mysql | ||
| mountPath: /var/lib/mysql | ||
|
|
||
| volumes: | ||
| - name: mysql-persistent-storage | ||
| persistentVolumeClaim: | ||
| claimName: mysql-pvc | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: mysql | ||
| namespace: bank | ||
| labels: | ||
| app: bankapp | ||
|
|
||
| spec: | ||
| clusterIP: None | ||
| selector: | ||
| app: bankapp | ||
| ports: | ||
| - protocol: TCP | ||
| port: 3306 | ||
| targetPort: 3306 | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| apiVersion: v1 | ||
| kind: PersistentVolume | ||
| metadata: | ||
| name: mysql-pv | ||
| namespace: bank | ||
| labels: | ||
|
Comment on lines
+4
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent ❓ Verification inconclusiveRemove unsupported namespace and add reclaim policy Proposed diff: metadata:
name: mysql-pv
- namespace: bank
labels:
app: bankapp
spec:
+ persistentVolumeReclaimPolicy: Retain
storageClassName: standard
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data/mysql"
+ type: DirectoryOrCreateAlso applies to: 14-15 Remove unsupported namespace and explicitly set reclaim policy & hostPath type PersistentVolumes are cluster-scoped, so Locations to update:
Proposed diff: metadata:
name: mysql-pv
- namespace: bank
labels:
app: bankapp
spec:
+ persistentVolumeReclaimPolicy: Retain
storageClassName: standard
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data/mysql"
+ type: DirectoryOrCreate |
||
| app: bankapp | ||
| spec: | ||
| storageClassName: standard | ||
| capacity: | ||
| storage: 5Gi | ||
| accessModes: | ||
| - ReadWriteOnce | ||
| hostPath: | ||
| path: "/mnt/data/mysql" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| apiVersion: v1 | ||
| kind: PersistentVolumeClaim | ||
| metadata: | ||
| name: mysql-pvc | ||
| namespace: bank | ||
| labels: | ||
| app: bankapp | ||
| spec: | ||
| storageClassName: standard | ||
| accessModes: | ||
| - ReadWriteOnce | ||
| resources: | ||
| requests: | ||
| storage: 5Gi | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| apiVersion: v1 | ||
| kind: Secret | ||
| metadata: | ||
| name: bank-secret | ||
| namespace: bank | ||
| type: opaque | ||
| data: | ||
| MYSQL_ROOT_PASSWORD: VGVzdEAxMjM= | ||
| SPRING_DATASOURCE_PASSWORD: VGVzdEAxMjM= | ||
|
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid committing plaintext credentials |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| kind: Namespace | ||
| apiVersion: v1 | ||
| metadata: | ||
| name: bank |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| kind: Deployment | ||
| apiVersion: apps/v1 | ||
| metadata: | ||
| name: bank-deployment | ||
| namespace: bank | ||
|
Comment on lines
+1
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix filename and resource naming typo. |
||
| labels: | ||
| app: app | ||
| spec: | ||
| replicas: 3 | ||
| selector: | ||
| matchLabels: | ||
| app: app | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: app | ||
| spec: | ||
| containers: | ||
| - name: bank-cont | ||
| image: swayamnakshane/mybank:latest | ||
| ports: | ||
| - containerPort: 8081 | ||
| env: | ||
| - name: SPRING_DATASOURCE_USERNAME | ||
| valueFrom: | ||
| configMapKeyRef: | ||
| name: bank-configmap | ||
| key: SPRING_DATASOURCE_USERNAME | ||
| - name: SPRING_DATASOURCE_URL | ||
| valueFrom: | ||
| configMapKeyRef: | ||
| name: bank-configmap | ||
| key: SPRING_DATASOURCE_URL | ||
| - name: SPRING_DATASOURCE_PASSWORD | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: bank-secret | ||
| key: SPRING_DATASOURCE_PASSWORD | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||||||||||||||||||||||||
| kind: Service | ||||||||||||||||||||||||||||
| apiVersion: v1 | ||||||||||||||||||||||||||||
| metadata: | ||||||||||||||||||||||||||||
| name: bank-svc | ||||||||||||||||||||||||||||
| namespace: bank | ||||||||||||||||||||||||||||
| labels: | ||||||||||||||||||||||||||||
| app: app | ||||||||||||||||||||||||||||
| spec: | ||||||||||||||||||||||||||||
| type: NodePort | ||||||||||||||||||||||||||||
| selector: | ||||||||||||||||||||||||||||
| app: app | ||||||||||||||||||||||||||||
| ports: | ||||||||||||||||||||||||||||
| - protocol: TCP | ||||||||||||||||||||||||||||
| targetPort: 8080 | ||||||||||||||||||||||||||||
| port: 8081 | ||||||||||||||||||||||||||||
| nodePort: 30080 | ||||||||||||||||||||||||||||
|
Comment on lines
+13
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Service targetPort mismatch with container port. Apply this diff to correct it: spec:
type: NodePort
selector:
app: app
ports:
- protocol: TCP
- targetPort: 8080
+ targetPort: 8081
port: 8081
nodePort: 30080📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Pin Docker image versions for stability.
Using
mysql:latestandbankapp:latestmay introduce breaking changes when upstream images update. Specify exact tags (e.g.,mysql:8.0.33,bankapp:1.2.0) to ensure reproducible builds.Also applies to: 18-18