Categorygithub.com/ds4tech/simple-calculator

# README

Simple calculator application written in Go lang. The purpose is to demonstrate variety of ways for CICD.

  1. Introduction
  2. Build
    2.1. Exec
    2.2. Docker
  3. Deploy
    3.1. Kubernetes
    3.2. AWS ECS
  4. Usage
  5. Continous Integration

Introduction

Simple Go Calculator project with some math function:

  • Sum
  • Sqrt
  • Factorial
  • IsPrime
  • Log

BUILD

Executable

go build -o main cmd/calculator/main.go
./main

http://localhost:8888/

Docker container

docker build -t go-calc -f build/package/Dockerfile .
docker run -d -p 80:8888 go-calc

http://localhost/

DEPLOY

Kubernetes

kubectl create -f deployments/kubernetes/k8s-replicaSet.yml

http://192.168.99.100:30000/

AWS ECS

cd deployments/aws/ecs
terraform init
terraform apply
//copy output: repository url
cd ../../../
$(aws ecr get-login --no-include-email --region eu-west-1)
docker build -t go-calc .
docker tag go-calc:latest 311744426619.dkr.ecr.eu-west-1.amazonaws.com/go-calc:latest
docker push 311744426619.dkr.ecr.eu-west-1.amazonaws.com/go-calc:latest

USEAGE

  1. SUM
curl --location --request POST "http://localhost:8888/sum" \
--header "Content-Type: application/json" \
--data "{\"num1\":\"2\",
\"num2\":\"4\"}"
  1. SQRT
curl --location --request POST "http://localhost:8888/sqrt" \
--header "Content-Type: application/json" \
--data "{\"number\":\"144\"}"
  1. FACTORIAL
curl --location --request POST "http://localhost:8888/factorial" \
--header "Content-Type: application/json" \
--data "{\"number\":\"6\"}"
  1. ISPRIME
  • (n int)
  • Function IsPrime returns bool, according to provided number (if it's prime or not).
  • http://localhost:8888/isPrime
  • JSON: {"number":"6"}
  • curl:
curl --location --request POST "http://localhost:8888/isPrime" \
--header "Content-Type: application/json" \
--data "{\"number\":\"6\"}"
  1. LOG
curl --location --request POST "http://localhost:8888/log" \
--header "Content-Type: application/json" \
--data "{\"number\":\"6\"}"

Continous Integration

Pipeline script written in Groovy is placed in build/ci directory. It is dedicated for Jenkins Pipeline JOB.
To run Jenkins on AWS, run terraform scripts in deployments/aws/jenkins-ec2_instance

# Packages

No description provided by the author
No description provided by the author