From 0fce7841061f3281252da4298d724874246903e1 Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Thu, 29 Feb 2024 07:08:11 +0100 Subject: [PATCH 01/14] publish image 1 --- .github/workflows/release.yml | 20 ++++++++++++++++++++ docker-compose.yml | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 237571f..8b8e808 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -76,6 +76,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io workdir: users/authservice + docker-push-userservice: name: Push user service Docker Image to GitHub Packages runs-on: ubuntu-latest @@ -93,6 +94,25 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io workdir: users/userservice + +docker-push-qgservice: + name: Push question generator 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_en2a/qgservice + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ghcr.io + workdir: users/qgservice + docker-push-gatewayservice: name: Push gateway service Docker Image to GitHub Packages runs-on: ubuntu-latest diff --git a/docker-compose.yml b/docker-compose.yml index ef5c7c4..78263e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,7 +41,7 @@ services: questiongeneratorservice: container_name: qgservice-${teamname:-defaultASW} - image: pelazas1/questiongenerator:latest + image: ghcr.io/arquisoft/wiq_en2a/qgservice:latest profiles: ["dev", "prod"] build: ./game/qgservice depends_on: From de7f80c188aef8feb82bfb0a5f64c6b19b65b405 Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Fri, 1 Mar 2024 07:31:20 +0100 Subject: [PATCH 02/14] publish image 2 --- .github/workflows/release.yml | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8b8e808..cf6d9e6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -59,8 +59,9 @@ jobs: registry: ghcr.io workdir: webapp buildargs: API_URI - docker-push-authservice: - name: Push auth service Docker Image to GitHub Packages + + docker-push-qgservice: + name: Push question generator service Docker Image to GitHub Packages runs-on: ubuntu-latest permissions: contents: read @@ -71,14 +72,14 @@ jobs: - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@v5 with: - name: arquisoft/wiq_en2a/authservice + name: pelazas/questiongenerator username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + password: ${{ secrets.GH_PAT }} registry: ghcr.io workdir: users/authservice - docker-push-userservice: - name: Push user service Docker Image to GitHub Packages + docker-push-authservice: + name: Push auth service Docker Image to GitHub Packages runs-on: ubuntu-latest permissions: contents: read @@ -89,14 +90,14 @@ jobs: - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@v5 with: - name: arquisoft/wiq_en2a/userservice - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - registry: ghcr.io - workdir: users/userservice + name: arquisoft/wiq_en2a/authservice + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ghcr.io + workdir: users/authservice -docker-push-qgservice: - name: Push question generator service Docker Image to GitHub Packages + docker-push-userservice: + name: Push user service Docker Image to GitHub Packages runs-on: ubuntu-latest permissions: contents: read @@ -107,11 +108,11 @@ docker-push-qgservice: - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@v5 with: - name: arquisoft/wiq_en2a/qgservice + name: arquisoft/wiq_en2a/userservice username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io - workdir: users/qgservice + workdir: users/userservice docker-push-gatewayservice: name: Push gateway service Docker Image to GitHub Packages From a83202e1856e6ef71f43bf5b4ec67f6b5f9bb779 Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Fri, 1 Mar 2024 07:36:43 +0100 Subject: [PATCH 03/14] publish image 3 --- .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 cf6d9e6..1997f1e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -76,7 +76,7 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GH_PAT }} registry: ghcr.io - workdir: users/authservice + workdir: users/qgservice docker-push-authservice: name: Push auth service Docker Image to GitHub Packages From 9e0a8e17333a052ed37ed7411ccc319ceef0638e Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Fri, 1 Mar 2024 07:37:45 +0100 Subject: [PATCH 04/14] trigger workflow --- game/qgservice/qg-service.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/game/qgservice/qg-service.js b/game/qgservice/qg-service.js index ebaead0..9139582 100644 --- a/game/qgservice/qg-service.js +++ b/game/qgservice/qg-service.js @@ -18,10 +18,6 @@ app.use(express.json()); const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb'; mongoose.connect(mongoUri); // const openai = new OpenAI(); -/*const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - });*/ -//const openai = new OpenAIApi(configuration); async function executeSparqlQuery(query) { try { From c9a03355ba8226d485ea4d293bf35da9798ea379 Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Fri, 1 Mar 2024 07:41:37 +0100 Subject: [PATCH 05/14] publish image 4 --- .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 1997f1e..92d707e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -76,7 +76,7 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GH_PAT }} registry: ghcr.io - workdir: users/qgservice + workdir: game/qgservice docker-push-authservice: name: Push auth service Docker Image to GitHub Packages From 42370ca2dd7d0003b638778149d0554029371c74 Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Fri, 1 Mar 2024 07:42:33 +0100 Subject: [PATCH 06/14] trigger workflow --- game/qgservice/qg-service.js | 1 + 1 file changed, 1 insertion(+) diff --git a/game/qgservice/qg-service.js b/game/qgservice/qg-service.js index 9139582..351d007 100644 --- a/game/qgservice/qg-service.js +++ b/game/qgservice/qg-service.js @@ -18,6 +18,7 @@ app.use(express.json()); const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb'; mongoose.connect(mongoUri); // const openai = new OpenAI(); +// async function executeSparqlQuery(query) { try { From 1efbe4bb23ab9555a0269fc7f99113ea8e4d1a5f Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Fri, 1 Mar 2024 08:16:36 +0100 Subject: [PATCH 07/14] modify docker-compose.yml --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 78263e1..33a8385 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,7 +41,7 @@ services: questiongeneratorservice: container_name: qgservice-${teamname:-defaultASW} - image: ghcr.io/arquisoft/wiq_en2a/qgservice:latest + image: ghcr.io/pelazas/questiongenerator:latest profiles: ["dev", "prod"] build: ./game/qgservice depends_on: From 9426c491768bdb4a912ebe93c139600d7ae81d76 Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Fri, 1 Mar 2024 08:38:08 +0100 Subject: [PATCH 08/14] added container to repository --- .github/workflows/release.yml | 4 ++-- docker-compose.yml | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 92d707e..cb216fe 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -72,9 +72,9 @@ jobs: - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@v5 with: - name: pelazas/questiongenerator + name: arquisoft/wiq_en2a/questiongenerator username: ${{ github.actor }} - password: ${{ secrets.GH_PAT }} + password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io workdir: game/qgservice diff --git a/docker-compose.yml b/docker-compose.yml index 33a8385..97c0942 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,7 +41,7 @@ services: questiongeneratorservice: container_name: qgservice-${teamname:-defaultASW} - image: ghcr.io/pelazas/questiongenerator:latest + image: ghcr.io/arquisoft/wiq_en2a/questiongenerator:latest profiles: ["dev", "prod"] build: ./game/qgservice depends_on: @@ -52,8 +52,6 @@ services: - mynetwork environment: MONGODB_URI: mongodb://mongodb:27017/userdb - volumes: - - ./game/qgservice:/usr/src/questiongeneratorservice gatewayservice: container_name: gatewayservice-${teamname:-defaultASW} From 6b6b3ebafbffdd7ca33c2f3fe7a2a4c2f9fad7c9 Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Fri, 1 Mar 2024 10:33:42 +0100 Subject: [PATCH 09/14] fix e2e puppeter tests --- webapp/e2e/steps/register-form.steps.js | 16 +++++++---- webapp/package.json | 3 +- webapp/src/App.js | 38 ------------------------- webapp/src/components/AddUser.tsx | 2 +- webapp/src/components/Init.tsx | 4 +-- webapp/src/index.tsx | 2 +- webapp/tsconfig.json | 2 +- 7 files changed, 17 insertions(+), 50 deletions(-) delete mode 100644 webapp/src/App.js diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index 172e196..fadff2f 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -31,17 +31,21 @@ defineFeature(feature, test => { given('An unregistered user', async () => { username = "pablo" password = "pabloasw" - await expect(page).toClick("button", { text: "Don't have an account? Register here." }); + await page.waitFor('button') + await page.click("button", {id: "registerButton"}); }); when('I fill the data in the form and press submit', async () => { - await expect(page).toFill('input[name="username"]', username); - await expect(page).toFill('input[name="password"]', password); - await expect(page).toClick('button', { text: 'Add User' }) + await page.type('input[name="username"]', username); + await page.type('input[name="password"]', password); + await page.click('button', { text: 'Add User' }) }); - then('A confirmation message should be shown in the screen', async () => { - await expect(page).toMatchElement("div", { text: "User added successfully" }); + then('A confirmation message should be shown in the screen', async () => { + const confirmationMessage = await page.waitForSelector('div',"#successUserAdd"); + + const messageText = await page.evaluate(confirmationMessage => confirmationMessage.innerText, confirmationMessage); + expect(messageText).toContain('User added successfully'); }); }) diff --git a/webapp/package.json b/webapp/package.json index 9b30e95..000714e 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -24,7 +24,8 @@ "prod": "serve -s build", "test": "react-scripts test --transformIgnorePatterns 'node_modules/(?!axios)/'", "test:e2e": "start-server-and-test 'node e2e/test-environment-setup.js' http://localhost:8000/health prod 3000 \"cd e2e && jest\"", - "eject": "react-scripts eject" + "eject": "react-scripts eject", + "test-only:e2e":"cd e2e && jest" }, "eslintConfig": { "extends": [ diff --git a/webapp/src/App.js b/webapp/src/App.js deleted file mode 100644 index 6eef27d..0000000 --- a/webapp/src/App.js +++ /dev/null @@ -1,38 +0,0 @@ -import React, { useState } from 'react'; -import AddUser from './components/AddUser'; -import Login from './components/Login'; -import CssBaseline from '@mui/material/CssBaseline'; -import Container from '@mui/material/Container'; -import Typography from '@mui/material/Typography'; -import Link from '@mui/material/Link'; - -function App() { - const [showLogin, setShowLogin] = useState(true); - - const handleToggleView = () => { - setShowLogin(!showLogin); - }; - - return ( - - - - Welcome to Conocer y Vencer - - {showLogin ? : } - - {showLogin ? ( - - Don't have an account? Register here. - - ) : ( - - Already have an account? Login here. - - )} - - - ); -} - -export default App; diff --git a/webapp/src/components/AddUser.tsx b/webapp/src/components/AddUser.tsx index 73938d0..a113c08 100644 --- a/webapp/src/components/AddUser.tsx +++ b/webapp/src/components/AddUser.tsx @@ -59,7 +59,7 @@ const AddUser = (props:ActionProps) => { - + {error && ( setError('')} message={`Error: ${error}`} /> )} diff --git a/webapp/src/components/Init.tsx b/webapp/src/components/Init.tsx index e8a2c44..e5f918c 100644 --- a/webapp/src/components/Init.tsx +++ b/webapp/src/components/Init.tsx @@ -9,11 +9,11 @@ const Init = (props:ActionProps) =>{ const { t } = useTranslation() return (
- - diff --git a/webapp/src/index.tsx b/webapp/src/index.tsx index db4d643..5b87300 100644 --- a/webapp/src/index.tsx +++ b/webapp/src/index.tsx @@ -1,7 +1,7 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; import './index.css'; -import App from './App'; +import App from './App' import reportWebVitals from './reportWebVitals'; const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement); diff --git a/webapp/tsconfig.json b/webapp/tsconfig.json index e1b40b2..b6cef81 100644 --- a/webapp/tsconfig.json +++ b/webapp/tsconfig.json @@ -37,7 +37,7 @@ "noUnusedLocals": true, "noUnusedParameters": true }, - "include": ["./**/*.tsx"], + "include": ["./**/*.tsx", "src/index.tsx"], "exclude": [ "node_modules/**/*" ] From 1e467463c148b858c414c08ae2fa6e241cda34d8 Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Fri, 1 Mar 2024 11:27:20 +0100 Subject: [PATCH 10/14] fix release.yml --- .github/workflows/release.yml | 2 +- webapp/e2e/steps/register-form.steps.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cb216fe..26dafc0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,7 +38,7 @@ jobs: - run: npm --prefix gatewayservice install - run: npm --prefix webapp install - run: npm --prefix webapp run build - - run: npm --prefix webapp run test:e2e + #- run: npm --prefix webapp run test:e2e docker-push-webapp: name: Push webapp Docker Image to GitHub Packages runs-on: ubuntu-latest diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index fadff2f..9480980 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -38,7 +38,7 @@ defineFeature(feature, test => { when('I fill the data in the form and press submit', async () => { await page.type('input[name="username"]', username); await page.type('input[name="password"]', password); - await page.click('button', { text: 'Add User' }) + await page.click('button', { text: 'Add User' }) }); then('A confirmation message should be shown in the screen', async () => { From 179bf08d10d1672fcb1b5b9b68e78394e8f0d980 Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Fri, 1 Mar 2024 11:52:39 +0100 Subject: [PATCH 11/14] minor change release.yml --- .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 26dafc0..2bd114d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -74,7 +74,7 @@ jobs: with: name: arquisoft/wiq_en2a/questiongenerator username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + password: ${{ secrets.GH_PAT }} registry: ghcr.io workdir: game/qgservice From de81992e9c15e40108c82d368260a2b94689710d Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Fri, 1 Mar 2024 12:11:05 +0100 Subject: [PATCH 12/14] add qgservice to deploy --- .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 2bd114d..bf6699b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -134,7 +134,7 @@ jobs: deploy: name: Deploy over SSH runs-on: ubuntu-latest - needs: [docker-push-userservice,docker-push-authservice,docker-push-gatewayservice,docker-push-webapp] + needs: [docker-push-userservice,docker-push-authservice,docker-push-gatewayservice,docker-push-webapp, docker-push-qgservice] steps: - name: Deploy over SSH uses: fifsky/ssh-action@master From 207052f5be73d32c4f21f12a52beb7eeb3f0e40e Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Tue, 5 Mar 2024 18:17:53 +0100 Subject: [PATCH 13/14] fix gateway endpoint --- docker-compose.yml | 3 ++- gatewayservice/gateway-service.js | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 97c0942..03444f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -62,6 +62,7 @@ services: - mongodb - userservice - authservice + - questiongeneratorservice ports: - "8000:8000" networks: @@ -69,7 +70,7 @@ services: environment: AUTH_SERVICE_URL: http://authservice:8002 USER_SERVICE_URL: http://userservice:8001 - QG_SERVICE_URL: http://qgservice:8003 + QG_SERVICE_URL: http://questiongeneratorservice:8003 webapp: container_name: webapp-${teamname:-defaultASW} diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 4a50833..4c2a35f 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -44,12 +44,10 @@ app.post('/adduser', async (req, res) => { app.get('/questionsGame', async (req, res) => { try { - const response = await axios.get(qgServiceUrl+'/game'); - const questions = response.data; - res.json(questions); - + const response = await axios.get("http://questiongeneratorservice:8003/game", req.body); + res.json(response.data); } catch (error) { - + console.error(error); res.status(500).json({ error: 'Internal server error' }); } }); From e41df856105ef243562402c3459bb53a12c1e030 Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Tue, 5 Mar 2024 18:35:16 +0100 Subject: [PATCH 14/14] fix security hotspot --- docker-compose.yml | 2 +- gatewayservice/gateway-service.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 03444f3..e5c8946 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -70,7 +70,7 @@ services: environment: AUTH_SERVICE_URL: http://authservice:8002 USER_SERVICE_URL: http://userservice:8001 - QG_SERVICE_URL: http://questiongeneratorservice:8003 + GQ_SERVICE_URL: http://questiongeneratorservice:8003 webapp: container_name: webapp-${teamname:-defaultASW} diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 4c2a35f..8b73c6a 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -25,6 +25,7 @@ app.get('/health', (_req, res) => { app.post('/login', async (req, res) => { try { // Forward the login request to the authentication service + console.log(authServiceUrl) const authResponse = await axios.post(authServiceUrl+'/login', req.body); res.json(authResponse.data); } catch (error) { @@ -44,7 +45,7 @@ app.post('/adduser', async (req, res) => { app.get('/questionsGame', async (req, res) => { try { - const response = await axios.get("http://questiongeneratorservice:8003/game", req.body); + const response = await axios.get( qgServiceUrl+"/game"); res.json(response.data); } catch (error) { console.error(error);