From 2dd15ddddd48dbeb074a0fd466f71383146014fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20M=C3=A9ndez=20Murias?= Date: Thu, 7 Mar 2024 22:50:24 +0100 Subject: [PATCH 01/10] Timeout changed on question generation tests and .yml files updated --- .github/workflows/build.yml | 4 +++ .github/workflows/release.yml | 35 ++++++++++++++----- .../questionGenerationService.test.js | 6 ++-- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8813691c..f047aef9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,10 +17,14 @@ jobs: - run: npm --prefix users/userservice ci - run: npm --prefix question_generator ci - run: npm --prefix questionservice ci + - run: npm --prefix gameservice ci - run: npm --prefix gatewayservice ci - run: npm --prefix webapp ci - run: npm --prefix users/authservice test -- --coverage - run: npm --prefix users/userservice test -- --coverage + - run: npm --prefix question_generator test + - run: npm --prefix questionservice test -- --coverage + - run: npm --prefix gameservice test -- --coverage - run: npm --prefix gatewayservice test -- --coverage - run: npm --prefix webapp test -- --coverage - name: Analyze with SonarCloud diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 49ffe7c5..e34ea5bb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,10 +16,14 @@ jobs: - run: npm --prefix users/userservice ci - run: npm --prefix question_generator ci - run: npm --prefix questionservice ci + - run: npm --prefix gameservice ci - run: npm --prefix gatewayservice ci - run: npm --prefix webapp ci - run: npm --prefix users/authservice test -- --coverage - run: npm --prefix users/userservice test -- --coverage + - run: npm --prefix question_generator test + - run: npm --prefix questionservice test -- --coverage + - run: npm --prefix gameservice test -- --coverage - run: npm --prefix gatewayservice test -- --coverage - run: npm --prefix webapp test -- --coverage - name: Analyze with SonarCloud @@ -39,6 +43,7 @@ jobs: - run: npm --prefix users/userservice install - run: npm --prefix question_generator install - run: npm --prefix questionservice install + - run: npm --prefix gameservice install - run: npm --prefix gatewayservice install - run: npm --prefix webapp install - run: npm --prefix webapp run build @@ -97,9 +102,8 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io workdir: users/userservice - docker-push-questiongenerationservice: - name: Push question service Docker Image to GitHub Packages + name: Push question generation service Docker Image to GitHub Packages runs-on: ubuntu-latest permissions: contents: read @@ -110,12 +114,11 @@ jobs: - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@v5 with: - name: arquisoft/wiq_es3b/questiongenerationservice + name: arquisoft/wiq_es3b/question_generator username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io - workdir: questiongenerationservice - + workdir: question_generator docker-push-questionservice: name: Push question service Docker Image to GitHub Packages runs-on: ubuntu-latest @@ -133,7 +136,23 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io workdir: questionservice - + docker-push-gameservice: + name: Push game service Docker Image to GitHub Packages + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + needs: [e2e-tests] + steps: + - uses: actions/checkout@v4 + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@v5 + with: + name: arquisoft/wiq_es3b/gameservice + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ghcr.io + workdir: gameservice docker-push-gatewayservice: name: Push gateway service Docker Image to GitHub Packages runs-on: ubuntu-latest @@ -154,7 +173,7 @@ jobs: deploy: name: Deploy over SSH runs-on: ubuntu-latest - needs: [docker-push-userservice,docker-push-authservice,docker-push-questiongenerationservice,docker-push-questionservice,docker-push-gatewayservice,docker-push-webapp] + needs: [docker-push-userservice,docker-push-authservice,docker-push-questiongenerationservice,docker-push-questionservice,docker-push-gameservice,docker-push-gatewayservice,docker-push-webapp] steps: - name: Deploy over SSH uses: fifsky/ssh-action@master @@ -166,4 +185,4 @@ jobs: wget https://raw.githubusercontent.com/arquisoft/wiq_es3b/master/docker-compose.yml -O docker-compose.yml wget https://raw.githubusercontent.com/arquisoft/wiq_es3b/master/.env -O .env docker compose down - docker compose --profile prod up -d + docker compose --profile prod up -d \ No newline at end of file diff --git a/question_generator/questionGenerationService.test.js b/question_generator/questionGenerationService.test.js index 2b00f2c5..9a00e998 100644 --- a/question_generator/questionGenerationService.test.js +++ b/question_generator/questionGenerationService.test.js @@ -18,7 +18,7 @@ describe('Question generation service', () => { expect(response.body).toHaveProperty('question'); expect(response.body).toHaveProperty('correct'); expect(response.body).toHaveProperty('incorrects'); - },10000); + },100000); it('should forward create question request to question generation service', async () => { const response = await request(app) @@ -28,7 +28,7 @@ describe('Question generation service', () => { expect(response.body).toHaveProperty('question'); expect(response.body).toHaveProperty('correct'); expect(response.body).toHaveProperty('incorrects'); - },10000); + },100000); it('should forward create question request to question generation service', async () => { const response = await request(app) @@ -38,5 +38,5 @@ describe('Question generation service', () => { expect(response.body).toHaveProperty('question'); expect(response.body).toHaveProperty('correct'); expect(response.body).toHaveProperty('incorrects'); - },10000); + },100000); }); From c73510ee18cf616976aef4d079108cf439ea78a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20M=C3=A9ndez=20Murias?= Date: Thu, 7 Mar 2024 23:10:05 +0100 Subject: [PATCH 02/10] Cors support --- webapp/src/components/Game.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/webapp/src/components/Game.jsx b/webapp/src/components/Game.jsx index 27f9b5f4..d8737a15 100644 --- a/webapp/src/components/Game.jsx +++ b/webapp/src/components/Game.jsx @@ -43,7 +43,10 @@ const Question = ({ goTo, setGameFinished }) => { const fetchQuestion = async () => { try { - const response = await fetch('http://localhost:8000/api/questions/create'); + const response = await fetch('http://localhost:8000/api/questions/create', { + method: 'GET', + mode: 'cors', + }); const data = await response.json(); setQuestion(data.question); From c1ca6397724ea6fe5ba0e8c38c1d9b78a0898c0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20M=C3=A9ndez=20Murias?= Date: Thu, 7 Mar 2024 23:31:15 +0100 Subject: [PATCH 03/10] Frecuency for categories of questions --- question_generator/questionTemplate.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/question_generator/questionTemplate.js b/question_generator/questionTemplate.js index 4211e196..fced6815 100644 --- a/question_generator/questionTemplate.js +++ b/question_generator/questionTemplate.js @@ -7,9 +7,9 @@ function loadData(){ sportTemplates.loadData() } const templates=[ - planetsTemplates.getRandomQuestion, - geographyTemplates.getRandomQuestion, - sportTemplates.getRandomQuestion + ...Array(1).fill(planetsTemplates.getRandomQuestion), + ...Array(4).fill(geographyTemplates.getRandomQuestion), + ...Array(4).fill(sportTemplates.getRandomQuestion) ] module.exports.getRandomQuestion = () => templates[Math.floor(Math.random()*templates.length)](); From ba16318512964176d097f56b2f2c36c1521c07c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20M=C3=A9ndez=20Murias?= Date: Sat, 9 Mar 2024 00:16:21 +0100 Subject: [PATCH 04/10] useEffect error solved --- webapp/src/components/Game.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webapp/src/components/Game.jsx b/webapp/src/components/Game.jsx index d8737a15..6afa2136 100644 --- a/webapp/src/components/Game.jsx +++ b/webapp/src/components/Game.jsx @@ -21,7 +21,6 @@ const Question = ({ goTo, setGameFinished }) => { const [nQuestion, setNQuestion] = useState(0); const [segundos, setSegundos] = useState(MAX_TIME); - useEffect(() => { const intervalId = setInterval(() => { @@ -32,6 +31,7 @@ const Question = ({ goTo, setGameFinished }) => { }, 1000); return () => clearInterval(intervalId); + // eslint-disable-next-line }, []); const formatTiempo = (segundos) => { @@ -119,6 +119,7 @@ const Question = ({ goTo, setGameFinished }) => { useEffect(() => { fetchQuestion(); + // eslint-disable-next-line }, []); return( From 8fac53a107ed27d019a0af4b2815e9d789c5b317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20M=C3=A9ndez=20Murias?= Date: Sat, 9 Mar 2024 01:18:53 +0100 Subject: [PATCH 05/10] Release.yml updated --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e34ea5bb..7cc6023b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -114,7 +114,7 @@ jobs: - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@v5 with: - name: arquisoft/wiq_es3b/question_generator + name: arquisoft/wiq_es3b/questiongenerationservice username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io From b111f1461ed2c4f6ea83bd50a4becb84ff7508c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20M=C3=A9ndez=20Murias?= Date: Sat, 9 Mar 2024 12:26:43 +0100 Subject: [PATCH 06/10] Communication problems solved between webapp and api gateway --- docker-compose.yml | 2 ++ webapp/src/components/Game.jsx | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 4683cd54..46f9843d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -109,6 +109,8 @@ services: - gatewayservice ports: - "3000:3000" + environment: + GATEWAY_SERVICE_URL: http://gatewayservice:8000 #volumes: #- ./webapp:/app diff --git a/webapp/src/components/Game.jsx b/webapp/src/components/Game.jsx index 6afa2136..bc9e12a5 100644 --- a/webapp/src/components/Game.jsx +++ b/webapp/src/components/Game.jsx @@ -3,10 +3,13 @@ import { Card, List, ListItem, ListItemButton, ListItemText, Typography } from ' import React from 'react' import { useState, useEffect } from 'react' import { PostGame } from './PostGame' +import Axios from 'axios'; const N_QUESTIONS = 10 const MAX_TIME = 600; +const gatewayUrl=process.env.GATEWAY_SERVICE_URL||"http://localhost:8000" + const Question = ({ goTo, setGameFinished }) => { const [question, setQuestion] = useState(''); @@ -43,11 +46,8 @@ const Question = ({ goTo, setGameFinished }) => { const fetchQuestion = async () => { try { - const response = await fetch('http://localhost:8000/api/questions/create', { - method: 'GET', - mode: 'cors', - }); - const data = await response.json(); + const response = await Axios.get(`${gatewayUrl}/api/questions/create`); + const data = response.data; setQuestion(data.question); setCorrect(data.correct); From 752268c7d5d53ec1f92ddcd3809d207e1a9cb44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20M=C3=A9ndez=20Murias?= Date: Sat, 9 Mar 2024 12:50:13 +0100 Subject: [PATCH 07/10] Error solved in tests --- webapp/src/components/Game.jsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/webapp/src/components/Game.jsx b/webapp/src/components/Game.jsx index bc9e12a5..88456bf7 100644 --- a/webapp/src/components/Game.jsx +++ b/webapp/src/components/Game.jsx @@ -3,7 +3,6 @@ import { Card, List, ListItem, ListItemButton, ListItemText, Typography } from ' import React from 'react' import { useState, useEffect } from 'react' import { PostGame } from './PostGame' -import Axios from 'axios'; const N_QUESTIONS = 10 const MAX_TIME = 600; @@ -46,8 +45,10 @@ const Question = ({ goTo, setGameFinished }) => { const fetchQuestion = async () => { try { - const response = await Axios.get(`${gatewayUrl}/api/questions/create`); - const data = response.data; + const response = await fetch(`${gatewayUrl}/api/questions/create`, { + method: 'GET' + }); + const data = await response.json(); setQuestion(data.question); setCorrect(data.correct); From aa46ff6d56d3badca8c1278378c81fbc18793ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20M=C3=A9ndez=20Murias?= Date: Sat, 9 Mar 2024 14:25:43 +0100 Subject: [PATCH 08/10] .env updated --- .env | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env b/.env index e2c6eee0..9dbc766a 100644 --- a/.env +++ b/.env @@ -1 +1,2 @@ -teamname="wiq_es3b" \ No newline at end of file +teamname="wiq_es3b" +GATEWAY_SERVICE_URL=http://gatewayservice:8000 \ No newline at end of file From d9e18fd67ddaf5a5d553789c1a110f044d4b36bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20M=C3=A9ndez=20Murias?= Date: Sat, 9 Mar 2024 14:33:33 +0100 Subject: [PATCH 09/10] REACT_APP_API_ENDPOINT --- .env | 3 +-- webapp/src/components/Game.jsx | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 9dbc766a..e2c6eee0 100644 --- a/.env +++ b/.env @@ -1,2 +1 @@ -teamname="wiq_es3b" -GATEWAY_SERVICE_URL=http://gatewayservice:8000 \ No newline at end of file +teamname="wiq_es3b" \ No newline at end of file diff --git a/webapp/src/components/Game.jsx b/webapp/src/components/Game.jsx index 88456bf7..1dea9ae8 100644 --- a/webapp/src/components/Game.jsx +++ b/webapp/src/components/Game.jsx @@ -7,7 +7,7 @@ import { PostGame } from './PostGame' const N_QUESTIONS = 10 const MAX_TIME = 600; -const gatewayUrl=process.env.GATEWAY_SERVICE_URL||"http://localhost:8000" +const gatewayUrl=process.env.REACT_APP_API_ENDPOINT||"http://localhost:8000" const Question = ({ goTo, setGameFinished }) => { From f93fe0bb86b9393f81c942dc1f8f1347c0825ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Molt=C3=B3?= <144908056+UO287747@users.noreply.github.com> Date: Mon, 11 Mar 2024 09:12:14 +0100 Subject: [PATCH 10/10] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 25b02d26..e64cc4fe 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ This repo is a basic application composed of several components. Both the user and auth service share a Mongo database that is accessed with mongoose. +App Link: http://172.187.201.54:3000/ + ## Quick start guide ### Using docker