Skip to content

Commit

Permalink
Merge branch 'develop' into initial-modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
gony02 authored Feb 20, 2024
2 parents d6821ec + f1ea0b9 commit 4c9857d
Show file tree
Hide file tree
Showing 28 changed files with 678 additions and 775 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ coverage
docs/build

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
*.ipr
.idea
.vscode
.DS_Store
97 changes: 97 additions & 0 deletions Quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
## Quick start guide

### Using docker

The fastest way for launching this sample project is using docker. Just clone the project:

```sh
git clone https://github.com/Arquisoft/wiq_en2b.git
```

and launch it with docker compose:

```sh
docker compose --profile dev up --build
```

### Starting Component by component

First, start the database. Either install and run Mongo or run it using docker:

```docker run -d -p 27017:27017 --name=my-mongo mongo:latest```

You can also use services like Mongo Altas for running a Mongo database in the cloud.

Now, launch the auth, user and gateway services. Just go to each directory and run `npm install` followed by `npm start`.

Lastly, go to the webapp directory and launch this component with `npm install` followed by `npm start`.

After all the components are launched, the app should be available in localhost in port 3000.

## Deployment

For the deployment, we have several options.

The first and more flexible is to deploy to a virtual machine using SSH. This will work with any cloud service (or with our own server).

Other options include using the container services that most cloud services provide. This means, deploying our Docker containers directly.

We are going to use the first approach, creating a virtual machine in a cloud service and after installing docker and docker-compose, deploy our containers there using GitHub Actions and SSH.

### Machine requirements for deployment

The machine for deployment can be created in services like Microsoft Azure or Amazon AWS. These are in general the settings that it must have:

- Linux machine with Ubuntu > 20.04.
- Docker and docker-compose installed.
- Open ports for the applications installed (in this case, ports 3000 for the webapp and 8000 for the gateway service).

Once you have the virtual machine created, you can install **docker** and **docker-compose** using the following instructions:

```ssh
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
sudo apt update
sudo apt install docker-ce
sudo usermod -aG docker ${USER}
sudo curl -L "https://github.com/docker/compose/releases/download/1.28.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
```

### Continuous delivery (GitHub Actions)

Once we have our machine ready, we could deploy by hand the application, taking our docker-compose file and executing it in the remote machine.

In this repository, this process is done automatically using **GitHub Actions**. The idea is to trigger a series of actions when some condition is met in the repository.

As you can see, unitary tests of each module and e2e tests are executed before pushing the docker images and deploying them. Using this approach we avoid deploying versions that do not pass the tests.

The deploy action is the following:

```yml
deploy:
name: Deploy over SSH
runs-on: ubuntu-latest
needs: [docker-push-userservice,docker-push-authservice,docker-push-gatewayservice,docker-push-webapp]
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
with:
host: ${{ secrets.DEPLOY_HOST }}
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://raw.githubusercontent.com/arquisoft/wiq_en2b/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_en2b/master/.env -O .env
docker compose down
docker compose --profile prod up -d
```
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.
124 changes: 21 additions & 103 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# wiq_en2b
# 🧠🤔 wiq_en2b ❓📚

[![Deploy on release](https://github.com/Arquisoft/wiq_en2b/actions/workflows/release.yml/badge.svg)](https://github.com/Arquisoft/wiq_en2b/actions/workflows/release.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Arquisoft_wiq_en2b&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Arquisoft_wiq_en2b)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=Arquisoft_wiq_en2b&metric=coverage)](https://sonarcloud.io/summary/new_code?id=Arquisoft_wiq_en2b)
WIQ is a quiz game project inspired by the engaging and thought-provoking show "Saber y Ganar."
We aim to create a platform that not only challenges your knowledge but also sparks curiosity and the thrill of discovery.


## What Sets WIQ Apart
🤔 Thoughtful Questions: Dive into a world of intriguing and diverse questions, all generated procedurally using WikiData.
🌐 Encourage to improve: WIQ lets you keep track of your score to see in which areas you need to improve.

## Features
🏆 Adaptable difficulty: You can adjust the difficulty to push your limits.
🌐 Multiplayer: Compete with friends and strangers to prove you are the best.

This is a base repo for the [Software Architecture course](http://arquisoft.github.io/) in [2023/2024 edition](https://arquisoft.github.io/course2324.html).

## Contributors
| Nombre | UO |
|---------------------------------|----------|
Expand All @@ -16,6 +22,15 @@ This is a base repo for the [Software Architecture course](http://arquisoft.gith
| Sergio Quintana Fernández | UO288090 |
| Diego Villanueva Berros | UO283615 |
| Gonzalo Suárez Losada | UO283928 |

***


[![Deploy on release](https://github.com/Arquisoft/wiq_en2b/actions/workflows/release.yml/badge.svg)](https://github.com/Arquisoft/wiq_en2b/actions/workflows/release.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Arquisoft_wiq_en2b&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Arquisoft_wiq_en2b)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=Arquisoft_wiq_en2b&metric=coverage)](https://sonarcloud.io/summary/new_code?id=Arquisoft_wiq_en2b)

This is a base repo for the [Software Architecture course](http://arquisoft.github.io/) in [2023/2024 edition](https://arquisoft.github.io/course2324.html).

This repo is a basic application composed of several components.

Expand All @@ -26,100 +41,3 @@ 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.

## Quick start guide

### Using docker

The fastest way for launching this sample project is using docker. Just clone the project:

```sh
git clone https://github.com/Arquisoft/wiq_en2b.git
```

and launch it with docker compose:

```sh
docker compose --profile dev up --build
```

### Starting Component by component

First, start the database. Either install and run Mongo or run it using docker:

```docker run -d -p 27017:27017 --name=my-mongo mongo:latest```

You can also use services like Mongo Altas for running a Mongo database in the cloud.

Now, launch the auth, user and gateway services. Just go to each directory and run `npm install` followed by `npm start`.

Lastly, go to the webapp directory and launch this component with `npm install` followed by `npm start`.

After all the components are launched, the app should be available in localhost in port 3000.

## Deployment

For the deployment, we have several options.

The first and more flexible is to deploy to a virtual machine using SSH. This will work with any cloud service (or with our own server).

Other options include using the container services that most cloud services provide. This means, deploying our Docker containers directly.

We are going to use the first approach, creating a virtual machine in a cloud service and after installing docker and docker-compose, deploy our containers there using GitHub Actions and SSH.

### Machine requirements for deployment

The machine for deployment can be created in services like Microsoft Azure or Amazon AWS. These are in general the settings that it must have:

- Linux machine with Ubuntu > 20.04.
- Docker and docker-compose installed.
- Open ports for the applications installed (in this case, ports 3000 for the webapp and 8000 for the gateway service).

Once you have the virtual machine created, you can install **docker** and **docker-compose** using the following instructions:

```ssh
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
sudo apt update
sudo apt install docker-ce
sudo usermod -aG docker ${USER}
sudo curl -L "https://github.com/docker/compose/releases/download/1.28.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
```

### Continuous delivery (GitHub Actions)

Once we have our machine ready, we could deploy by hand the application, taking our docker-compose file and executing it in the remote machine.

In this repository, this process is done automatically using **GitHub Actions**. The idea is to trigger a series of actions when some condition is met in the repository.

As you can see, unitary tests of each module and e2e tests are executed before pushing the docker images and deploying them. Using this approach we avoid deploying versions that do not pass the tests.

The deploy action is the following:

```yml
deploy:
name: Deploy over SSH
runs-on: ubuntu-latest
needs: [docker-push-userservice,docker-push-authservice,docker-push-gatewayservice,docker-push-webapp]
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
with:
host: ${{ secrets.DEPLOY_HOST }}
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://raw.githubusercontent.com/arquisoft/wiq_en2b/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_en2b/master/.env -O .env
docker compose down
docker compose --profile prod up -d
```
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.
23 changes: 23 additions & 0 deletions docs/diagrams/10_Quality_Tree.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@startuml
title Quality attributes
agent Quality
agent Security
agent Reliability
agent Transferability
agent Usability
agent "Performance Efficiency"
agent Maintainability
agent Availability
agent Compatibility
agent "Functional Suitability"

Quality --- Security
Quality --- Reliability
Quality --- Transferability
Quality --- Usability
Quality --- "Performance Efficiency"
Quality --- Maintainability
Quality --- Availability
Quality --- Compatibility
Quality --- "Functional Suitability"
@enduml
18 changes: 18 additions & 0 deletions docs/diagrams/BusinessContextDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@startuml
!includeurl https://raw.githubusercontent.com/RicardoNiepel/C4-PlantUML/master/C4_Container.puml
!include <c4/C4_Context.puml>

title Context Diagram for the WIQ System
LAYOUT_WITH_LEGEND()

'Containers
Person(player, Player,"An authenticated player that wants to play WIQ games")

Container(wiq, "WIQ Application","", "Application that allows the users to play WIQ games")

System_Ext(wikidata,"WikiData API","Contains the information used for the question generation")

'RELATIONS
Rel(player,wiq,"Plays games")
Rel(wiq,wikidata,"Asks for data for question generation")
@enduml
24 changes: 24 additions & 0 deletions docs/diagrams/ContainerDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@startuml
!includeurl https://raw.githubusercontent.com/RicardoNiepel/C4-PlantUML/master/C4_Container.puml
!include <c4/C4_Context.puml>

title Context Diagram for the WIQ System
LAYOUT_WITH_LEGEND()

'Containers
Person(player, Player,"An authenticated player that wants to play WIQ games")

System_Boundary(wiq,"WIQ"){
Container(web_app, "WIQ Client", "React, Typescript", "Allows the user to play WIQ games")
Container(backend_api, "WIQ REST API","Java SpringBoot 3","Handles the users, game logic and question generation")
ContainerDb(database,"WIQ Database","PostgreSQL","Stores users, questions and other game info")
}

System_Ext(wikidata,"WikiData API","Contains the information used for the question generation")

'RELATIONS
Rel(player,web_app,"Uses","HTTPS")
Rel(backend_api,wikidata,"Asks for data","SPARQL,HTTPS")
Rel(web_app,backend_api,"Asks for user/game information","JSON,HTTPS")
Rel(backend_api,database,"Stores game/user information","JPA")
@enduml
32 changes: 32 additions & 0 deletions docs/diagrams/DeploymentDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@startuml

title WIQ Deployment View

legend right
|Color| Type |
|<#PeachPuff>| WIQ Server |
|<#DarkSalmon>| External Service |
end legend

node "Server Hosting WIQ" #PeachPuff {
node "WIQ WebApp Server"{
component "WIQ React Application"
}
node "WIQ API" {
component "WIQ_API.jar"
}
node "PostgreSQL Docker" {
database "WIQ Database"
}
}
node "User Computer" #DarkSalmon{
frame "Web Client"
}
node "WikiData Server" #DarkSalmon {
frame "WikiData REST API"
}
"Web Client" ..> "WIQ React Application" : "HTTPS"
"WIQ React Application" ..> "WIQ_API.jar" : "HTTPS"
"WIQ_API.jar" ..> "WIQ Database" : "JPA"
"WIQ API" ..> "WikiData REST API" : "HTTPS, SPARQL"
@enduml
23 changes: 23 additions & 0 deletions docs/diagrams/TechnicalContextDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@startuml
!includeurl https://raw.githubusercontent.com/RicardoNiepel/C4-PlantUML/master/C4_Container.puml
!include <c4/C4_Context.puml>

title Context Diagram for the WIQ System
LAYOUT_WITH_LEGEND()

'Containers
Person(player, Player's Browser,"Preferred browser (Firefox, Chrome, Opera...)")

System_Boundary(wiq,"WIQ Server"){
Container(web_app, "WIQ Client", "React, Typescript", "nginx web server")
Container(backend_api, "WIQ REST API","Java SpringBoot 3",".jar file")
ContainerDb(database,"WIQ Database","PostgreSQL","PostgreSQL docker container")
}
System_Ext(wikidata,"WikiData API","REST API")

'RELATIONS
Rel(player,web_app,"Uses","HTTPS")
Rel(backend_api,wikidata,"Asks for data","SPARQL,HTTPS")
Rel(web_app,backend_api,"Asks for user/game information","JSON,HTTPS")
Rel(backend_api,database,"Stores game/user information","JPA")
@enduml
Binary file added docs/images/10_Quality_Tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/BusinessContext.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/ContainerDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/DeploymentDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/TechnicalContextDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@ include::src/11_technical_risks.adoc[]
// 12. Glossary
include::src/12_glossary.adoc[]


<<<<
// 13. Annex
include::src/13_annex.adoc[]
Loading

0 comments on commit 4c9857d

Please sign in to comment.