Skip to content

Commit

Permalink
Merge pull request #92 from Arquisoft/ray
Browse files Browse the repository at this point in the history
Ray
  • Loading branch information
UO290054 authored Apr 1, 2024
2 parents ada6418 + 3613362 commit e197ad2
Show file tree
Hide file tree
Showing 22 changed files with 780 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ jobs:
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Update OpenAPI configuration
run: |
DEPLOY_HOST=${{ secrets.DEPLOY_HOST }}
sed -i "s/SOMEIP/${DEPLOY_HOST}/g" gatewayservice/openapi.yaml
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
Expand All @@ -160,7 +164,9 @@ jobs:
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://raw.githubusercontent.com/arquisoft/wiq_es2b/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_es2b/master/.env -O .env
docker compose down
docker compose --profile prod up -d
wget https://raw.githubusercontent.com/arquisoft/wiq_0/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_0/master/.env -O .env
docker compose --profile prod down
docker compose --profile prod up -d --pull always
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ and launch it with docker compose:
docker compose --profile dev up --build
```

and tear it down:

```sh
docker compose --profile dev down
```

### Starting Component by component

First, start the database. Either install and run Mongo or run it using docker:
Expand Down Expand Up @@ -100,15 +106,18 @@ deploy:
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://raw.githubusercontent.com/arquisoft/wiq_es2b/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_es2b/master/.env -O .env
docker compose down
docker compose --profile prod up -d
wget https://raw.githubusercontent.com/arquisoft/wiq_0/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_0/master/.env -O .env
docker compose --profile prod down
docker compose --profile prod up -d --pull always
```
This action uses three secrets that must be configured in the repository:
- DEPLOY_HOST: IP of the remote machine.
- DEPLOY_USER: user with permission to execute the commands in the remote machine.
- DEPLOY_KEY: key to authenticate the user in the remote machine.
Note that this action logs in the remote machine and downloads the docker-compose file from the repository and launches it. Obviously, previous actions have been executed which have uploaded the docker images to the GitHub Packages repository.
Note that this action logs in the remote machine and downloads the docker-compose file from the repository and launches it.
Obviously, previous actions have been executed which have uploaded the docker images to the GitHub Packages repository.
48 changes: 48 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ const express = require('express');
const axios = require('axios');
const cors = require('cors');
const promBundle = require('express-prom-bundle');
//libraries required for OpenAPI-Swagger
const swaggerUi = require('swagger-ui-express');
const fs = require("fs")
const YAML = require('yaml')


const app = express();
const port = 8000;
Expand Down Expand Up @@ -41,6 +46,29 @@ app.post('/adduser', async (req, res) => {
}
});


app.post('/addgame', async (req, res) => {
try {
const userResponse = await axios.post(userServiceUrl+'/addgame', req.body);
res.json(userResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});


app.get('/getgamehistory/:username', async (req, res) => {
try {
const username = req.params.username;
const userResponse = await axios.get(`${userServiceUrl}/getgamehistory/${username}`);
res.json(userResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});



app.post('/createquestion', async (req, res) => {
try {
// Create a petition to the URL (le llegará a creation-service.js) with the option /createquestion and the req.body params
Expand All @@ -63,9 +91,29 @@ app.post('/getquestionshistory', async (req, res) => {
}
});



// Read the OpenAPI YAML file synchronously
openapiPath='./openapi.yaml'
if (fs.existsSync(openapiPath)) {
const file = fs.readFileSync(openapiPath, 'utf8');

// Parse the YAML content into a JavaScript object representing the Swagger document
const swaggerDocument = YAML.parse(file);

// Serve the Swagger UI documentation at the '/api-doc' endpoint
// This middleware serves the Swagger UI files and sets up the Swagger UI page
// It takes the parsed Swagger document as input
app.use('/api-doc', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
} else {
console.log("Not configuring OpenAPI. Configuration file not present.")
}


// Start the gateway service
const server = app.listen(port, () => {
console.log(`Gateway Service listening at http://localhost:${port}`);
});


module.exports = server
144 changes: 144 additions & 0 deletions gatewayservice/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
openapi: 3.0.0
info:
title: Gatewayservice API
description: Gateway OpenAPI specification.
version: 0.2.0
servers:
- url: http://localhost:8000
description: Development server
- url: http://SOMEIP:8000
description: Production server
paths:
/adduser:
post:
summary: Add a new user to the database.
operationId: addUser
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
username:
type: string
description: User ID.
example: student
password:
type: string
description: User password.
example: pass
responses:
'200':
description: User added successfully.
content:
application/json:
schema:
type: object
properties:
username:
type: string
description: User ID
password:
type: string
description: Hashed password
example: $2b$10$ZKdNYLWFQxzt5Rei/YTc/OsZNi12YiWz30JeUFHNdAt7MyfmkTuvC
_id:
type: string
description: Identification
example: 65f756db3fa22d227a4b7c7d
createdAt:
type: string
description: Creation date.
example: '2024-03-17T20:47:23.935Z'
___v:
type: integer
example: '0'
'400':
description: Failed to add user.
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: Error information.
example: getaddrinfo EAI_AGAIN mongodb
/health:
get:
summary: Check the health status of the service.
operationId: checkHealth
responses:
'200':
description: Service is healthy.
content:
application/json:
schema:
type: object
properties:
status:
type: string
description: Health status.
example: OK
/login:
post:
summary: Log in to the system.
operationId: loginUser
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
username:
type: string
description: User ID.
example: student
password:
type: string
description: User password.
example: pass
responses:
'200':
description: Login successful. Returns user token, username, and creation date.
content:
application/json:
schema:
type: object
properties:
token:
type: string
description: User token.
example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NWY3NTZkYjNmYTIyZDIyN2E0YjdjN2QiLCJpYXQiOjE3MTA3MDg3NDUsImV4cCI6MTcxMDcxMjM0NX0.VMG_5DOyQ4GYlJQRcu1I6ICG1IGzuo2Xuei093ONHxw
username:
type: string
description: Username.
example: student
createdAt:
type: string
description: Creation date.
example: '2024-03-17T20:47:23.935Z'
'401':
description: Invalid credentials.
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: Shows the error info..
example: Invalid credentials
'500':
description: Internal server error.
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: Error information.
example: Internal Server Error
Loading

0 comments on commit e197ad2

Please sign in to comment.