Skip to content

Commit f56fb4b

Browse files
Nidhi GuptaNidhi Gupta
authored andcommitted
code added for helm
1 parent bdba025 commit f56fb4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3350
-3
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: "Client Build and Terraform Deployment"
2+
on:
3+
# Manual trigger
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- 'microservices/HelloWorldClient/**'
10+
pull_request:
11+
branches: [ main ]
12+
paths:
13+
- 'HelloWorldClient/**'
14+
jobs:
15+
build:
16+
defaults:
17+
run:
18+
working-directory: ./HelloWorldClient
19+
name: Maven Build
20+
runs-on: [ ubuntu-latest ]
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Set up JDK 11
24+
uses: actions/setup-java@v2
25+
with:
26+
java-version: '11'
27+
distribution: 'adopt'
28+
- name: Build with Maven
29+
run: mvn package
30+
- name: Upload Artifact
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: app.jar
34+
path: HelloWorldClient/target/hello-world-client-1.jar
35+
- name: Configure AWS credentials
36+
uses: aws-actions/configure-aws-credentials@v1
37+
with:
38+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
39+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
40+
aws-region: us-east-1
41+
42+
- name: Login to Public ECR
43+
uses: docker/login-action@v1
44+
with:
45+
registry: public.ecr.aws
46+
47+
- name: Download Artifact
48+
uses: actions/download-artifact@v4
49+
with:
50+
name: app.jar
51+
52+
- name: Build, tag, and push image to Amazon ECR
53+
id: build-image
54+
env:
55+
ECR_REGISTRY: public.ecr.aws/w0f5g4k6
56+
ECR_REPOSITORY: client-svc
57+
IMAGE_TAG: ${{ github.sha }}
58+
run: |
59+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
60+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
61+
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
62+
63+
64+
65+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Terraform Deployment
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- 'terraform/automode/**'
8+
pull_request:
9+
branches:
10+
- main
11+
paths:
12+
- 'terraform/automode/**'
13+
workflow_dispatch:
14+
inputs:
15+
action:
16+
description: "Specify the Terraform action: apply or destroy"
17+
required: true
18+
default: "apply"
19+
20+
env:
21+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
22+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
23+
AWS_DEFAULT_REGION: us-east-1
24+
25+
jobs:
26+
terraform:
27+
runs-on: ubuntu-latest
28+
defaults:
29+
run:
30+
working-directory: terraform/automode
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v2
34+
35+
- name: Configure AWS credentials
36+
uses: aws-actions/configure-aws-credentials@v1
37+
with:
38+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
39+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
40+
aws-region: us-east-1
41+
42+
- name: Set up Terraform
43+
uses: hashicorp/setup-terraform@v1
44+
with:
45+
terraform_wrapper: true
46+
47+
- name: Initialize Terraform
48+
run: terraform init
49+
50+
- name: Validate Terraform
51+
run: terraform validate
52+
53+
- name: Terraform Plan
54+
run: terraform plan
55+
56+
- name: Execute Terraform Action
57+
run: |
58+
if [ "${{ github.event.inputs.action }}" == "destroy" ]; then
59+
terraform destroy -auto-approve
60+
else
61+
terraform apply -auto-approve
62+
fi
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: Terraform Deployment
2-
32
on:
43
push:
54
branches:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Crash log files
66
crash.log
7-
7+
.DS_Store
88
# Terraform variables files
99
*.tfvars
1010
*.tfvars.json

helm-chart/springboot/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

helm-chart/springboot/Chart.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: springboot
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "latest"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
{{- range $host := .Values.ingress.hosts }}
4+
{{- range .paths }}
5+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
6+
{{- end }}
7+
{{- end }}
8+
{{- else if contains "NodePort" .Values.service.type }}
9+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "springboot.fullname" . }})
10+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
11+
echo http://$NODE_IP:$NODE_PORT
12+
{{- else if contains "LoadBalancer" .Values.service.type }}
13+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
14+
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "springboot.fullname" . }}'
15+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "springboot.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
16+
echo http://$SERVICE_IP:{{ .Values.service.port }}
17+
{{- else if contains "ClusterIP" .Values.service.type }}
18+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "springboot.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
19+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
20+
echo "Visit http://127.0.0.1:8080 to use your application"
21+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
22+
{{- end }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "springboot.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "springboot.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "springboot.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "springboot.labels" -}}
37+
helm.sh/chart: {{ include "springboot.chart" . }}
38+
{{ include "springboot.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "springboot.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "springboot.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "springboot.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "springboot.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "springboot.fullname" . }}
5+
labels:
6+
{{- include "springboot.labels" . | nindent 4 }}
7+
spec:
8+
{{- if not .Values.autoscaling.enabled }}
9+
replicas: {{ .Values.replicaCount }}
10+
{{- end }}
11+
selector:
12+
matchLabels:
13+
{{- include "springboot.selectorLabels" . | nindent 6 }}
14+
template:
15+
metadata:
16+
{{- with .Values.podAnnotations }}
17+
annotations:
18+
{{- toYaml . | nindent 8 }}
19+
{{- end }}
20+
labels:
21+
{{- include "springboot.labels" . | nindent 8 }}
22+
{{- with .Values.podLabels }}
23+
{{- toYaml . | nindent 8 }}
24+
{{- end }}
25+
spec:
26+
{{- with .Values.imagePullSecrets }}
27+
imagePullSecrets:
28+
{{- toYaml . | nindent 8 }}
29+
{{- end }}
30+
serviceAccountName: {{ include "springboot.serviceAccountName" . }}
31+
{{- with .Values.podSecurityContext }}
32+
securityContext:
33+
{{- toYaml . | nindent 8 }}
34+
{{- end }}
35+
containers:
36+
- name: {{ .Chart.Name }}
37+
{{- with .Values.securityContext }}
38+
securityContext:
39+
{{- toYaml . | nindent 12 }}
40+
{{- end }}
41+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
42+
imagePullPolicy: {{ .Values.image.pullPolicy }}
43+
ports:
44+
- name: http
45+
containerPort: {{ .Values.service.port }}
46+
protocol: TCP
47+
{{- with .Values.livenessProbe }}
48+
livenessProbe:
49+
{{- toYaml . | nindent 12 }}
50+
{{- end }}
51+
{{- with .Values.readinessProbe }}
52+
readinessProbe:
53+
{{- toYaml . | nindent 12 }}
54+
{{- end }}
55+
{{- with .Values.resources }}
56+
resources:
57+
{{- toYaml . | nindent 12 }}
58+
{{- end }}
59+
{{- with .Values.volumeMounts }}
60+
volumeMounts:
61+
{{- toYaml . | nindent 12 }}
62+
{{- end }}
63+
env:
64+
{{- range $key, $value := .Values.env }}
65+
- name: {{ $key }}
66+
value: "{{ $value }}"
67+
{{- end }}
68+
{{- with .Values.volumes }}
69+
volumes:
70+
{{- toYaml . | nindent 8 }}
71+
{{- end }}
72+
{{- with .Values.nodeSelector }}
73+
nodeSelector:
74+
{{- toYaml . | nindent 8 }}
75+
{{- end }}
76+
{{- with .Values.affinity }}
77+
affinity:
78+
{{- toYaml . | nindent 8 }}
79+
{{- end }}
80+
{{- with .Values.tolerations }}
81+
tolerations:
82+
{{- toYaml . | nindent 8 }}
83+
{{- end }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{- if .Values.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "springboot.fullname" . }}
6+
labels:
7+
{{- include "springboot.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "springboot.fullname" . }}
13+
minReplicas: {{ .Values.autoscaling.minReplicas }}
14+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15+
metrics:
16+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
target:
21+
type: Utilization
22+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
23+
{{- end }}
24+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
25+
- type: Resource
26+
resource:
27+
name: memory
28+
target:
29+
type: Utilization
30+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
31+
{{- end }}
32+
{{- end }}

0 commit comments

Comments
 (0)