- Install and configure Docker
- Create a Docker Hub account: https://hub.docker.com/signup
- Pull Jenkins docker image:
-
docker pull jenkins/jenkins:lts
-
- Create a Jenkins volume:
-
docker volume create jenkins_home
-
- Run the Jenkins container:
-
docker run --name jenkins -p 8282:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):$(which docker) jenkins/jenkins:lts
-
- Give permission so that the container terminal can run docker commands
- Access the container terminal
-
docker exec -u root -it jenkins bash
-
- Give permission
-
chmod 666 /var/run/docker.sock
-
- Access the container terminal
- Access Jenkins: http://localhost:8282/
- Install suggested plugins -> Skip and continue as admin -> Verify the URL, finish and start
- Click on admin in the top of the page -> Configure -> Change the password -> Go back to Dashboard
- Create credentials: Go to
Manage Jenkins
->Manage Credentials
->Stores scoped to Jenkins
-> Jenkins -> Global credentials -> Add Credentials- Select kind Username with password and fill with you Docker Hub credentials (username and password)
- Click Add Credentials again. Select kind Secret text and write your Docker Hub repository name
- Install Packer plugin: Go to
Manage Jenkins
->Manage Plugins
->Available
-> Search and Install Packer - Configuring Packer:
- Go to
Manage Jenkins
->Global Tool Configuration
-> Packer ->Add Packer
- Name: Packer_Go-Calculator_linux_amd64 -> Install automatically -> Choose a version compatible with your S.O. E.g.: linux (amd64) -> Save
- Go to
- On Dashboard click in
New Item
- Set the name, choose
Pipeline
and clickOK
Choose appropriated names: BAKE for job 01 and LAUNCH for job 02.
- Go to
Pipeline
->Definition
-> Pipeline script from SCM ->SCM
-> Git -> Paste https://github.com/Gabriely-get/Go-Calculator.git - Change the branch */master to */main
- Choose the Jenkinsfile path. The steps to create the 02 jobs are the same, the only thing that will change is the path:
- ./job1/Jenkinsfile
- ./job2/Jenkinsfile
- Run both jobs
- ps: Launch job only stops if you abort it manually
- Open the project folder on terminal and type: ./scripts/smoke-test-calculator.sh to execute the test
Endpoints and examples of appropriate response
- Addition: http://localhost:8000/calc/sum/{value1}/{value2}
{ "result": "10" }
- Subtraction: http://localhost:8000/calc/sub/{value1}/{value2}
{ "result": "5" }
- Division: http://localhost:8000/calc/div/{value1}/{value2}
{ "result": "7" }
- Multiplication: http://localhost:8000/calc/mult/{value1}/{value2}
{ "result": "30" }
- History: http://localhost:8000/calc/history
[ { "time": "2022-08-19T02:13:52.853500749-03:00", "result": "6.00 - 6.00 = 0.00", "operation": "SUBTRACTION" }, { "time": "2022-08-19T02:13:52.859714718-03:00", "result": "6.00 + 6.00 = 12.00", "operation": "ADDITION" } ]