# README
Simple calculator application written in Go lang. The purpose is to demonstrate variety of ways for CICD.
- Introduction
- Build
2.1. Exec
2.2. Docker - Deploy
3.1. Kubernetes
3.2. AWS ECS - Usage
- 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
- SUM
- (x int64, y int64)
- http://localhost:8888/sum
- JSON: {"num1":"2","num2":"4"}
- curl:
curl --location --request POST "http://localhost:8888/sum" \
--header "Content-Type: application/json" \
--data "{\"num1\":\"2\",
\"num2\":\"4\"}"
- SQRT
- (x float64)
- http://localhost:8888/sqrt
- JSON: {"number":"144"}
- curl:
curl --location --request POST "http://localhost:8888/sqrt" \
--header "Content-Type: application/json" \
--data "{\"number\":\"144\"}"
- FACTORIAL
- (n uint64)
- http://localhost:8888/factorial
- JSON: {"number":"6"}
- curl:
curl --location --request POST "http://localhost:8888/factorial" \
--header "Content-Type: application/json" \
--data "{\"number\":\"6\"}"
- 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\"}"
- LOG
- (n float64)
- http://localhost:8888/log
- JSON: {"number":"6"}
- curl:
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