/test-ruby-app

Primary LanguageSmartyBSD 2-Clause "Simplified" LicenseBSD-2-Clause

Test ruby application

This repository provides a test Ruby application which will listen on port 80, Helm Chart and CI/CD to build and deploy it to minikube. Application is located in the app folder; check out Application Readme for more information

GitHub Super-Linter

Prerequisites

To reproduce the setup, following tools are required:

Architecture

Application is packed into Docker container and intended to be installed into Kubernetes via Helm Chart. Helm chart installs following Kubernetes resources:

  • Deployment
  • Service (for minikube I use NodePort type)
  • Ingress (if enabled)

High Availability is reached by putting application pods behind the load balancer(in our case Kubernetes Service and/or Ingress) and scaling them to the desired amount(i.e. 3 replicas)

Security is achieved by running the application as a non-root user and enforcing containers to be immutable.

Continous Integration

Docker images are built automatically, via GitHub Action 'Build docker image' This workflow is triggered on the following events:

  • Push to master when a file in app folder is modified
  • Push of new tags
  • Push to pull request to master, when a file in app folder is modified

CI workflow uses SEMVER approach for tagging Docker images. Tags will be assigned in the following way:

Event Ref Docker Tags
pull_request refs/pull/2/merge pr-2
push refs/heads/master master
push refs/heads/releases/v1 releases-v1
push tag refs/tags/v1.2.3 1.2.3, 1.2, latest
push tag refs/tags/v2.0.8-beta.67 2.0.8-beta.67

Also on each push GitHub Action 'Lint Codebase' will be triggered. This action uses GitHub Super-Linter under the hood and will run a set of linters against detected languages.

Continous Deployment

Since this is a test application, intended to be deployed to minikube, it's not possible to realize automated deployment. In real life, I would use GitHub Actions/ Jenkins/Terraform or other tools, depending on requirements.

Helm chart can be deployed manually via:

# Verify that Helm Chart renders correctly:
helm install --dry-run http-server helm/chart
# Install the chart
helm install http-server helm/chart

Steps to reproduce the setup

  1. Install Prerequisites
  2. Fork my github repo https://github.com/sbulav/test-ruby-app
  3. Create new Personal Access Token
  4. Create 2 repository secrets:
  • DOCKERHUB_USERNAME - Username of Docker hub user
  • DOCKERHUB_TOKEN - Personal Access Token of Docker Hub user
  1. Start minikube by running following command:
minikube start
  1. Enable minikube Ingress:
minikube addons enable ingress
  1. Clone repository to your local development machine:
git clone git@github.com:<USERNAME>/test-ruby-app.git
  1. Amend Helm values helm/chart/values.yaml to your need
  2. Issue a new tag:
git tag v1.0.0
git push --tags

Check out repository Github Actions and make sure that new Docker image is built and pushed to docker hub. 10. Install Helm chart.

# Verify that Helm Chart renders correctly:
helm install --dry-run http-server helm/chart
# Install the chart
helm install http-server helm/chart

Or install specific Image tag:

helm install http-server helm/chart --set tag=1.0.0
  1. Wait until the application is up and running and open web page in browser:
minikube service http-server
  1. (Optional) Access application via Ingress:
# Create DNS entry OR entry in /etc/hosts
sudo echo "$(minikube ip) http-server.local" >> /etc/hosts

Access application via browser or curl:

$ curl http-server.local.
Well, hello there!