Go - Setup simple gofiber server.

Gofiber is a fast lightweight web framework with simple api, inspired by expressjs. The simplicity of the api makes it easy to get started with. It’s also fast and has a lot of features. Setup Create a new project Create a new directory and initialize a go module. go mod init github.com/adharshmk96/gofiber-init Install gofiber go get -u github.com/gofiber/fiber/v2 a main.go with hello world touch main.go package main import "github.com/gofiber/fiber/v2" func main() { // gofiber with default settings app := fiber.New() // handler for root path app.Get("/", func(c *fiber.Ctx) error { return c.SendString("Hello, World πŸ‘‹!") }) // start server on port 3000 app.Listen(":3000") fmt.Println("Server started on port 3000") } Dockerfile for building the app ...

CI/CD Setup

Steps I follow to setup a CI CD workflow. Write Dockerfile in the code repo. Write a k8s Manifest file using kustomize template. Following this tree structure. β”œβ”€β”€ base β”‚ └── app β”‚ β”œβ”€β”€ deployment.yaml β”‚ β”œβ”€β”€ kustomization.yaml β”‚ └── service.yaml └── overlay β”œβ”€β”€ production β”‚ └── kustomization.yaml └── staging └── kustomization.yaml Write a skaffold file ( skaffold init will auto initialize itself ). Build Docker image and Render the k8s manifest using skaffold. skaffold build && \ skaffold render --digest-source='tag' -p staging -o ../path-to/manifest.yml Manually push the rendered k8s to the manifest repository. Setup the k8s to access the private repository kubectl create secret generic <secret-name> \ --from-file=.dockerconfigjson=~/.docker/config.json \ --type=kubernetes.io/dockerconfigjson Update the K8s manifest with spec: template: spec: imagePullSecrets: - name: <secret-name> Setup argo cd in the target k8s cluster. ArgoCD Getting Started kubectl create namespace argocd kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}' kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo Login and Link repository to argocd. Create an app in argocd and configure to access the repository and the cluster to deploy.

Docker - Docker Compose

Docker-compose is a tool that helps us define and run multiple services together. We declare the services and their attributes in a configuration file and the docker-compose tool reads it and issues the command to docker CLI in order to start and run the services. It helps us abstract all the creation of different components, building or pulling images etc… To run multiple services for a project. Once a compose-file is declared, we can run everything all at once with a single run command, we can also manage them via the docker-compose interface. ...

Docker - Building an image

Docker images are built from a Dockerfile, which is a blueprint for how to prepare a ready-to-run image. We can relate it to steps we perform in a computer to get something installed and running. We can start with a base image that corresponds to an OS (like ubuntu, alpine, Debian etc…) or we can even start from essentials installed in an OS. Basic steps are Start from the base image Run commands Specify default run command Here’s a basic example from nodejs ...

Docker - Overview

Docker is a platform that provides lightweight isolated runtimes for software. It helps us to package the software and its dependencies in a ready to run format. We can say its sort of works like VMs except, docker uses the kernel of our base OS. This is achieved by few techniques done with docker, File system snapshot - Dockerfile is used to build a filesystem snapshot that contains all the required files to run the software. Namespacing - Docker isolates the resources for the running processes using the Namespacing feature. It is a linux feature which partitions resources and control access between processes on resources. Control groups - The volume of resources used by a process can also be limited by docker. It is achieved by cgroups features which is another linux feature that helps define resource limits for a process. Why use Docker? As docker enables packaging and running software in a lightweight way, It solves the problem of setting up and configuring an environment to run the software. ...