diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 000000000..7c7b26b4f --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,90 @@ +name: CI + +on: + push: + branches: + - main + paths-ignore: + - 'README.md' + - 'helm/**' + +jobs: + + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go 1.22 + uses: actions/setup-go@v2 + 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 "shravankumarh96@gmail.com" + git config --global user.name "Shravan-kumar00" + git add helm/go-web-app-chart/values.yaml + git commit -m "Update tag in Helm chart" + git pushupdate-newtag-in-helm-chart: + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..c5b3802b2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM golang:1.22 AS base + +WORKDIR /app + +COPY go.mod . + +RUN go mod download + +COPY . . + +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main . + +FROM gcr.io/distroless/base-debian11 + +COPY --from=base /app/main . + +COPY --from=base /app/static ./static + +EXPOSE 8080 + +CMD [ "./main" ] + diff --git a/helm/go-web-app-chart/.helmignore b/helm/go-web-app-chart/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/helm/go-web-app-chart/.helmignore @@ -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/ diff --git a/helm/go-web-app-chart/Chart.yaml b/helm/go-web-app-chart/Chart.yaml new file mode 100644 index 000000000..5d5e4a81b --- /dev/null +++ b/helm/go-web-app-chart/Chart.yaml @@ -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" diff --git a/helm/go-web-app-chart/templates/deployment.yaml b/helm/go-web-app-chart/templates/deployment.yaml new file mode 100644 index 000000000..c0f96ce56 --- /dev/null +++ b/helm/go-web-app-chart/templates/deployment.yaml @@ -0,0 +1,22 @@ +# This is a sample deployment manifest file for a simple web application. +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: shravan001/go-web-app:{{ .Values.image.tag }} + ports: + - containerPort: 8080 \ No newline at end of file diff --git a/helm/go-web-app-chart/templates/ingress.yaml b/helm/go-web-app-chart/templates/ingress.yaml new file mode 100644 index 000000000..39122ef40 --- /dev/null +++ b/helm/go-web-app-chart/templates/ingress.yaml @@ -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 diff --git a/helm/go-web-app-chart/templates/service.yaml b/helm/go-web-app-chart/templates/service.yaml new file mode 100644 index 000000000..e242e6e14 --- /dev/null +++ b/helm/go-web-app-chart/templates/service.yaml @@ -0,0 +1,15 @@ +# Service for the application +apiVersion: v1 +kind: Service +metadata: + name: go-web-app + labels: + app: go-web-app +spec: + ports: + - port: 80 + targetPort: 8080 + protocol: TCP + selector: + app: go-web-app + type: ClusterIP \ No newline at end of file diff --git a/helm/go-web-app-chart/values.yaml b/helm/go-web-app-chart/values.yaml new file mode 100644 index 000000000..e23765b58 --- /dev/null +++ b/helm/go-web-app-chart/values.yaml @@ -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: shravan001/go-web-app + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "v3" + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific diff --git a/k8s/manifests/deployment.yaml b/k8s/manifests/deployment.yaml new file mode 100644 index 000000000..af373c161 --- /dev/null +++ b/k8s/manifests/deployment.yaml @@ -0,0 +1,22 @@ +# This is a sample deployment manifest file for a simple web application. +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: shravan001/go-web-app:v3 + ports: + - containerPort: 8080 \ No newline at end of file diff --git a/k8s/manifests/ingress.yaml b/k8s/manifests/ingress.yaml new file mode 100644 index 000000000..39122ef40 --- /dev/null +++ b/k8s/manifests/ingress.yaml @@ -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 diff --git a/k8s/manifests/service.yaml b/k8s/manifests/service.yaml new file mode 100644 index 000000000..e242e6e14 --- /dev/null +++ b/k8s/manifests/service.yaml @@ -0,0 +1,15 @@ +# Service for the application +apiVersion: v1 +kind: Service +metadata: + name: go-web-app + labels: + app: go-web-app +spec: + ports: + - port: 80 + targetPort: 8080 + protocol: TCP + selector: + app: go-web-app + type: ClusterIP \ No newline at end of file diff --git a/main b/main new file mode 100644 index 000000000..e38398fa2 Binary files /dev/null and b/main differ