Skip to content

Commit

Permalink
updates baked as per enterprise
Browse files Browse the repository at this point in the history
  • Loading branch information
Amits64 committed Aug 20, 2024
1 parent 254345f commit 9106574
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 112 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
sonarcloud:
Expand Down Expand Up @@ -47,13 +51,9 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Set current timestamp
id: timestamp
run: echo "TIMESTAMP=$(date +%s)" >> $GITHUB_ENV

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: amits64/crud-app:${{ env.TIMESTAMP }}
tags: amits64/crud-app:${{ github.run_number }}
49 changes: 24 additions & 25 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,41 @@
pipeline {
agent any

parameters {
choice(name: 'NAMESPACE', choices: ['cde', 'ncde'], description: 'Select Namespace')
choice(name: 'ENVIRONMENT', choices: ['dev', 'qa', 'prod'], description: 'Select the deployment environment')
string(name: 'IMAGE_TAG', defaultValue: '', description: 'Docker image tag')
}

environment {
registry = 'amits64'
registryCredential = 'dockerhub'
image = 'crud-app'
tag = "v${BUILD_NUMBER}"
sonarHostUrl = 'http://192.168.2.20:9000/'
repoUrl = 'https://github.com/Amits64/crud-app.git' // Add your repository URL here
tag = "${params.IMAGE_TAG}" // Use IMAGE_TAG parameter
kubeConfigPath = "/etc/kubernetes/${params.ENVIRONMENT}/config" // Adjusted for dynamic environment
}

stages {
stage('CI') {
steps {
// Call the shared library function for CI
ciPipeline(
registry: registry,
registryCredential: registryCredential,
image: image,
tag: tag,
sonarHostUrl: sonarHostUrl,
repoUrl: repoUrl
)
}
}

stage('Deploying Container to Kubernetes') {
steps {
script {
dir('crud-app') {
// Debugging step to print Helm version
sh 'helm version'
sh 'helm version'

def releaseExists = sh(returnStatus: true, script: 'helm ls | grep -q ${image}') == 0
if (releaseExists) {
sh 'helm delete ${image}'
}
def releaseExists = sh(returnStatus: true, script: "helm ls --kubeconfig ${kubeConfigPath} | grep -q ${image}") == 0

sh "helm install ${image} ./ --set appimage=${registry}/${image}:${tag} --set-file ca.crt=/etc/ca-certificates/update.d/jks-keystore"
if (releaseExists) {
echo "Existing Helm release found. Deleting release: ${image}"
sh "helm delete ${image} --kubeconfig ${kubeConfigPath}"
} else {
echo "No existing Helm release found for ${image}. Proceeding with installation."
}

sh """
helm upgrade --install ${image} ./ \
--kubeconfig ${kubeConfigPath} \
--set appimage=${registry}/${image}:${tag} \
--namespace ${params.NAMESPACE}
"""
}
}
}
Expand All @@ -51,6 +48,8 @@ pipeline {
script {
if (currentBuild.result != 'SUCCESS') {
error("Container deployment failed!")
} else {
echo "Container deployment succeeded!"
}
}
}
Expand Down
83 changes: 83 additions & 0 deletions crud-app/values-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Default values for crud-app in the dev environment.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1 # Typically lower for development environments

image:
repository: amits64/crud-app
pullPolicy: IfNotPresent
tag: "dev-${BUILD_NUMBER}" # Use a specific tag for dev

imagePullSecrets:
- name: my-registry-secret # Optional, if you use private registry

nameOverride: "crud-app-dev"
fullnameOverride: "crud-app-dev"

serviceAccount:
create: true
annotations: {}
name: "crud-app-dev-sa" # Specific service account for dev

podAnnotations:
kubernetes.io/cluster-service: "true"

podSecurityContext:
fsGroup: 2000

securityContext:
capabilities:
drop:
- ALL
readOnlyRootFilesystem: false
runAsNonRoot: false
runAsUser: 1000

service:
type: ClusterIP
port: 80

ingress:
enabled: false # Ingress typically not used in dev
className: ""
annotations: {}
hosts:
- host: dev.chart-example.local
paths:
- path: /
pathType: ImplementationSpecific
tls: []

resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 50m
memory: 64Mi

autoscaling:
enabled: false # Autoscaling usually disabled in dev
minReplicas: 1
maxReplicas: 2
targetCPUUtilizationPercentage: 80

nodeSelector:
environment: dev

tolerations:
- key: "environment"
operator: "Equal"
value: "dev"
effect: "NoSchedule"

affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "kubernetes.io/role"
operator: "In"
values:
- "dev"
83 changes: 83 additions & 0 deletions crud-app/values-qa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Default values for crud-app in the qa environment.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1 # Typically lower for development environments

image:
repository: amits64/crud-app
pullPolicy: IfNotPresent
tag: "qa-${BUILD_NUMBER}" # Use a specific tag for qa

imagePullSecrets:
- name: my-registry-secret # Optional, if you use private registry

nameOverride: "crud-app-qa"
fullnameOverride: "crud-app-qa"

serviceAccount:
create: true
annotations: {}
name: "crud-app-qa-sa" # Specific service account for qa

podAnnotations:
kubernetes.io/cluster-service: "true"

podSecurityContext:
fsGroup: 2000

securityContext:
capabilities:
drop:
- ALL
readOnlyRootFilesystem: false
runAsNonRoot: false
runAsUser: 1000

service:
type: ClusterIP
port: 80

ingress:
enabled: false # Ingress typically not used in qa
className: ""
annotations: {}
hosts:
- host: qa.chart-example.local
paths:
- path: /
pathType: ImplementationSpecific
tls: []

resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 50m
memory: 64Mi

autoscaling:
enabled: false # Autoscaling usually disabled in qa
minReplicas: 1
maxReplicas: 2
targetCPUUtilizationPercentage: 80

nodeSelector:
environment: qa

tolerations:
- key: "environment"
operator: "Equal"
value: "qa"
effect: "NoSchedule"

affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "kubernetes.io/role"
operator: "In"
values:
- "qa"
83 changes: 83 additions & 0 deletions crud-app/values.prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Default values for crud-app in the prod environment.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1 # Typically lower for development environments

image:
repository: amits64/crud-app
pullPolicy: IfNotPresent
tag: "prod-${BUILD_NUMBER}" # Use a specific tag for prod

imagePullSecrets:
- name: my-registry-secret # Optional, if you use private registry

nameOverride: "crud-app-prod"
fullnameOverride: "crud-app-prod"

serviceAccount:
create: true
annotations: {}
name: "crud-app-prod-sa" # Specific service account for prod

podAnnotations:
kubernetes.io/cluster-service: "true"

podSecurityContext:
fsGroup: 2000

securityContext:
capabilities:
drop:
- ALL
readOnlyRootFilesystem: false
runAsNonRoot: false
runAsUser: 1000

service:
type: ClusterIP
port: 80

ingress:
enabled: false # Ingress typically not used in prod
className: ""
annotations: {}
hosts:
- host: prod.chart-example.local
paths:
- path: /
pathType: ImplementationSpecific
tls: []

resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 50m
memory: 64Mi

autoscaling:
enabled: false # Autoscaling usually disabled in prod
minReplicas: 1
maxReplicas: 2
targetCPUUtilizationPercentage: 80

nodeSelector:
environment: prod

tolerations:
- key: "environment"
operator: "Equal"
value: "prod"
effect: "NoSchedule"

affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "kubernetes.io/role"
operator: "In"
values:
- "prod"
Loading

0 comments on commit 9106574

Please sign in to comment.