Skip to content
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

Head #9

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.22.5 as base

WORKDIR /app

COPY go.mod ./

RUN go mod download

COPY . .

RUN go build -o main .


FROM gcr.io/distroless/base

COPY --from=base /app/main .

COPY --from=base /app/static ./static

EXPOSE 8080

CMD [ "./main" ]
105 changes: 105 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
pipeline {
agent any

tools {
go 'go-1.22.5'
}

environment {
SCANNER_HOME = tool 'sonar-scanner'
SONAR_TOKEN = credentials('sonar-cred')
GITHUB_TOKEN = credentials('git-cred') // GitHub token
DOCKER_CRED = credentials('docker-cred') // Docker credentials
}

stages {
stage('Checkout Code') {
steps {
script {
// Checkout the repository
checkout scm

// Set the remote URL to HTTPS and use the GitHub token
sh """
git remote set-url origin https://vinnu2251:${GITHUB_TOKEN}@github.com/vinnu2251/go-web-app.git
git config --global user.email "vinaychowdarychitturi@gmail.com"
git config --global user.name "vinay chitturi"
"""
}
}
}

stage('Build') {
steps {
sh "go build -o go-web-app"
}
}

stage('Unit Test') {
steps {
sh "go test ./..."
}
}

stage('Run SonarQube Analysis') {
steps {
withSonarQubeEnv('sonar') {
sh "${SCANNER_HOME}/bin/sonar-scanner -Dsonar.projectKey=gowebapp -Dsonar.projectName=gowebapp"
}
}
}

stage('Docker Build & Tag') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh 'docker build -t vinay7944/go-web-app:v1 .'
}
}
}
}

stage('Docker Push Image') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh 'docker push vinay7944/go-web-app:v1'
}
}
}
}

stage('Update Helm Chart Tag') {
steps {
script {
// Get the commit ID
def commitId = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
echo "Current commit ID: ${commitId}"

// Get the current branch name
def branchName = sh(script: 'git rev-parse --abbrev-ref HEAD', returnStdout: true).trim()
echo "Current branch: ${branchName}"

// Update the Helm chart with the new tag
sh """
sed -i 's/tag: .*/tag: "${commitId}"/' helm/go-web-app-chart/values.yaml
"""

// Add, commit, and push the changes using the GitHub token
sh """
git add helm/go-web-app-chart/values.yaml
git commit -m "Update tag in Helm chart with commit ID ${commitId}"
git push https://vinnu2251:${GITHUB_TOKEN}@github.com/vinnu2251/go-web-app.git HEAD:refs/heads/${branchName}
"""
}
}
}
}

post {
always {
echo "Pipeline complete"
cleanWs() // Clean workspace after the build
}
}
}
23 changes: 23 additions & 0 deletions helm/go-web-app-chart/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions helm/go-web-app-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: go-web-app-chart
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
21 changes: 21 additions & 0 deletions helm/go-web-app-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: go-web-app
labels:
app: go-web-app
spec:
replicas: 1
selector:
matchLabels:
app: go-web-app
template:
metadata:
labels:
app: go-web-app
spec:
containers:
- name: go-web-app
image: vinay7944/go-web-app:v1
ports:
- containerPort: 8080
20 changes: 20 additions & 0 deletions helm/go-web-app-chart/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Ingress resource for the application
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: go-web-app
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- host: go-web-app.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: go-web-app
port:
number: 80
15 changes: 15 additions & 0 deletions helm/go-web-app-chart/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: go-web-app
labels:
app: go-web-app
spec:
selector:
app: go-web-app
type: ClusterIP
ports:
- port: 80
targetPort: 8080
protocol: TCP

23 changes: 23 additions & 0 deletions helm/go-web-app-chart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Default values for go-web-app-chart.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
repository: vinay7944/go-web-app
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "820de59"

ingress:
enabled: false
className: ""
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths:
- path: /
pathType: ImplementationSpecific
21 changes: 21 additions & 0 deletions k8/manifests/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: go-web-app
labels:
app: go-web-app
spec:
replicas: 1
selector:
matchLabels:
app: go-web-app
template:
metadata:
labels:
app: go-web-app
spec:
containers:
- name: go-web-app
image: vinay7944/go-web-app:{{ .Values.image.tag }}
ports:
- containerPort: 8080
20 changes: 20 additions & 0 deletions k8/manifests/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Ingress resource for the application
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: go-web-app
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- host: go-web-app.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: go-web-app
port:
number: 80
15 changes: 15 additions & 0 deletions k8/manifests/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: go-web-app
labels:
app: go-web-app
spec:
selector:
app: go-web-app
type: ClusterIP
ports:
- port: 80
targetPort: 8080
protocol: TCP

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func homePage(w http.ResponseWriter, r *http.Request) {
}

func coursePage(w http.ResponseWriter, r *http.Request) {
// Render the course html page
// Render the course html page of the chaneg by vinay
http.ServeFile(w, r, "static/courses.html")
}

Expand Down