Web App

App Details

A sample appliccation to demo CI/CD of an application with autoscaling using CirlceCI, ArgoCD and Kubernetes

.

Proposed Stack

Golang

Top-level directory layout

📦netguruTask
    📦.circleci
        ┗ 📜config.yml
    ┣ 📜deployment.yaml
    ┣ 📜.gitignore
    ┣ 📜Dockerfile
    ┣ 📜go.mod
    ┣ 📜main_test.go
    ┣ 📜main.go
    ┣ 📜README.md

Folder structure

  1. .circleci: Contains configuration for deployment

How to setup project and run locally

Fork the repository

git clone https://github.com/{github_username}/netguruTask.git

Checking Out

The App is deployed on the main branch you will need to checkout to the app branch using:

git checkout main

Connect your repository to CircleCI

  • To run the CI part of the application you will need to link your repository with CircleCI by creating an account and connecting your repo.
  • To add the environment variables. Click on Dashboard, Select your pipeline, on the far right of your screen go to Project Settings -> Environment variables. Add DOCKER_PASSWORD, DOCKER_USERNAME and GITHUB_PERSONAL_TOKEN.
  • Update the .circleci/config.yml from line 32 to line 53 to reflect yur changes and your docker image.
  • Update deployment.yaml on line 39 of the CI part and line 39 of the CD task to reflect your container image

Run the application

  1. Run the the application using
go run main.go
  1. In your browser, navigate to
http://localhost:3000/

How to setup project using docker

    1. Create the Docker image
    docker build -t your-username/appdemo:v1 .
    

    Example

    docker build -t adefemi171/appdemo:v1 .
    
  1. Run the docker file

    docker run -p 3000:3000 --name appdemo: YOURNAME/appdemo:v1
    

    Example

    docker run -p 3000:3000 --name appdemo adefemi171/appdemo:v1
    
  2. To confirm if your container was built, run:

    docker ps -a
    
  3. View the image in your localhost port 8888 by typing localhost:3000 in your browser

How to run application using ArgoCD

  1. Once you have successfully installed ArgoCD and all neccessary components
  2. Link your projects with the repository as stated here
  3. Create a new application as stated here
  4. Once your application is created and synced, check to see if you have your pods running by using the command
kubectl get po --all-namespaces

You should see a pod called app-demo-deployment-**** 5. Get the current svc that the application is running on by using

kubectl get svc --all-namespaces
  1. Do a port forward to be able to access the container o your browser, run
kubectl port-forward svc/app-demo -n app-demo 3000:3000

And visit the endpoint in your browser as specified above

Note: app-demo can be any name you gave your service in the deployment.yaml file.

NOTE: Docker, Golang, and Kubernetes needs to be installed to run this application