Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM golang:1.22 AS base
WORKDIR /app

COPY go.mod .
RUN go mod download
COPY . .
RUN go build -o main .

## Final stage with distroless image ##
FROM gcr.io/distroless/base:nonroot
WORKDIR /app
COPY --from=base /app/main .
COPY --from=base /app/static ./static
EXPOSE 8080
CMD ["./main"]
91 changes: 91 additions & 0 deletions k8s/manifests/.github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# CICD using GitHub actions

name: CI/CD

# Exclude the workflow to run on changes to the helm chart
on:
push:
branches:
- main

jobs:

build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go 1.22
uses: actions/setup-go@v4
with:
go-version: 1.22

- name: Build
run: go build -o go-web-app

- name: Test
run: go test ./...

code-quality:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.56.2

push:
runs-on: ubuntu-latest

needs: build

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and Push action
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/go-web-app:${{github.run_id}}

update-newtag-in-helm-chart:
runs-on: ubuntu-latest

needs: push

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.TOKEN }}

- name: Update tag in Helm chart
run: |
sed -i 's/tag: .*/tag: "${{github.run_id}}"/' helm/go-web-app-chart/values.yaml

- name: Commit and push changes
run: |
git config --global user.email "abhishek@gmail.com"
git config --global user.name "Abhishek Veeramalla"
git add helm/go-web-app-chart/values.yaml
git commit -m "Update tag in Helm chart"
git push

Binary file added k8s/manifests/.service.yaml.un~
Binary file not shown.
22 changes: 22 additions & 0 deletions k8s/manifests/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion : apps/v1
kind : Deployment
metadata:
name : go-web-app
labels:
app : go-web-app
spec:
replicas: 2
selector:
matchLabels:
app: go-web-app
template:
metadata:
labels:
app: go-web-app
spec:
containers:
- name: go-web-app
image: c5375391/go-web-app:v5
ports:
- containerPort: 8080

23 changes: 23 additions & 0 deletions k8s/manifests/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 k8s/manifests/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"
22 changes: 22 additions & 0 deletions k8s/manifests/helm/go-web-app-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion : apps/v1
kind : Deployment
metadata:
name : go-web-app
labels:
app : go-web-app
spec:
replicas: 2
selector:
matchLabels:
app: go-web-app
template:
metadata:
labels:
app: go-web-app
spec:
containers:
- name: go-web-app
image: c5375391/go-web-app:{{ .Values.image.tag }}
ports:
- containerPort: 8080

21 changes: 21 additions & 0 deletions k8s/manifests/helm/go-web-app-chart/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: go-web-app
labels:
app: go-web-app
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
ingressClassName: nginx
rules:
- host: go-web-app.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: go-web-app
port:
number: 8080
15 changes: 15 additions & 0 deletions k8s/manifests/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:
type: NodePort
selector:
app: go-web-app
ports:
- port: 8080
targetPort: 8080


23 changes: 23 additions & 0 deletions k8s/manifests/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: c5375391/go-web-app
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "v5"

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 k8s/manifests/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: go-web-app
labels:
app: go-web-app
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
ingressClassName: nginx
rules:
- host: go-web-app.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: go-web-app
port:
number: 8080
15 changes: 15 additions & 0 deletions k8s/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:
type: NodePort
selector:
app: go-web-app
ports:
- port: 8080
targetPort: 8080


15 changes: 15 additions & 0 deletions k8s/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:
type: ClusterIP
selector:
app: go-web-app
ports:
- port: 8080
targetPort: 8080