generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b0f356e
Showing
82 changed files
with
46,935 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
teamname="wiq_0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Build | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
jobs: | ||
unit-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: npm --prefix users/authservice ci | ||
- run: npm --prefix users/userservice 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 gatewayservice test -- --coverage | ||
- run: npm --prefix webapp test -- --coverage | ||
- name: Analyze with SonarCloud | ||
uses: sonarsource/sonarcloud-github-action@master | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
name: Deploy on release | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
unit-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: npm --prefix users/authservice ci | ||
- run: npm --prefix users/userservice 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 gatewayservice test -- --coverage | ||
- run: npm --prefix webapp test -- --coverage | ||
- name: Analyze with SonarCloud | ||
uses: sonarsource/sonarcloud-github-action@master | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
e2e-tests: | ||
needs: [unit-tests] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: npm --prefix users/authservice install | ||
- run: npm --prefix users/userservice install | ||
- run: npm --prefix gatewayservice install | ||
- run: npm --prefix webapp install | ||
- run: npm --prefix webapp run build | ||
- run: npm --prefix webapp run test:e2e | ||
docker-push-webapp: | ||
name: Push webapp 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 | ||
env: | ||
API_URI: http://${{ secrets.DEPLOY_HOST }}:8000 | ||
with: | ||
name: arquisoft/wiq_0/webapp | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
registry: ghcr.io | ||
workdir: webapp | ||
buildargs: API_URI | ||
docker-push-authservice: | ||
name: Push auth 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_0/authservice | ||
username: ${{ github.actor }} | ||
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 | ||
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_0/userservice | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
registry: ghcr.io | ||
workdir: users/userservice | ||
docker-push-gatewayservice: | ||
name: Push gateway 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_0/gatewayservice | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
registry: ghcr.io | ||
workdir: gatewayservice | ||
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_0/master/docker-compose.yml | ||
wget https://raw.githubusercontent.com/arquisoft/wiq_0/master/docker-compose-deploy.override.yml | ||
docker compose down | ||
docker compose --profile prod up -d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
coverage | ||
docs/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# wiq_0 | ||
|
||
[![Deploy on release](https://github.com/Arquisoft/wiq_0/actions/workflows/release.yml/badge.svg)](https://github.com/Arquisoft/wiq_0/actions/workflows/release.yml) | ||
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Arquisoft_wiq_0&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Arquisoft_wiq_0) | ||
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=Arquisoft_wiq_0&metric=coverage)](https://sonarcloud.io/summary/new_code?id=Arquisoft_wiq_0) | ||
|
||
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. | ||
|
||
- **Gateway service**. Express service that is exposed to the public and serves as a proxy to the two previous ones. | ||
- **User service**. Express service that handles the insertion of new users in the system. | ||
- **Auth service**. Express service that handles the authentication of users. | ||
- **Webapp**. React web application that uses the gateway service to allow basic login and new user features. | ||
|
||
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_0.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_0/master/docker-compose-deploy.yml -O docker-compose.yml | ||
docker compose down --volumes | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
version: '3' | ||
services: | ||
mongodb: | ||
container_name: mongodb-${teamname:-defaultASW} | ||
image: mongo | ||
profiles: ["dev", "prod"] | ||
volumes: | ||
- mongodb_data:/data/db | ||
ports: | ||
- "27017:27017" | ||
networks: | ||
- mynetwork | ||
|
||
authservice: | ||
container_name: authservice-${teamname:-defaultASW} | ||
image: ghcr.io/arquisoft/wiq_0/authservice:latest | ||
profiles: ["dev", "prod"] | ||
build: ./users/authservice | ||
depends_on: | ||
- mongodb | ||
ports: | ||
- "8002:8002" | ||
networks: | ||
- mynetwork | ||
environment: | ||
MONGODB_URI: mongodb://mongodb:27017/userdb | ||
|
||
userservice: | ||
container_name: userservice-${teamname:-defaultASW} | ||
image: ghcr.io/arquisoft/wiq_0/userservice:latest | ||
profiles: ["dev", "prod"] | ||
build: ./users/userservice | ||
depends_on: | ||
- mongodb | ||
ports: | ||
- "8001:8001" | ||
networks: | ||
- mynetwork | ||
environment: | ||
MONGODB_URI: mongodb://mongodb:27017/userdb | ||
|
||
gatewayservice: | ||
container_name: gatewayservice-${teamname:-defaultASW} | ||
image: ghcr.io/arquisoft/wiq_0/gatewayservice:latest | ||
profiles: ["dev", "prod"] | ||
build: ./gatewayservice | ||
depends_on: | ||
- mongodb | ||
- userservice | ||
- authservice | ||
ports: | ||
- "8000:8000" | ||
networks: | ||
- mynetwork | ||
environment: | ||
AUTH_SERVICE_URL: http://authservice:8002 | ||
USER_SERVICE_URL: http://userservice:8001 | ||
|
||
webapp: | ||
container_name: webapp-${teamname:-defaultASW} | ||
image: ghcr.io/arquisoft/wiq_0/webapp:latest | ||
profiles: ["dev", "prod"] | ||
build: ./webapp | ||
depends_on: | ||
- gatewayservice | ||
ports: | ||
- "3000:3000" | ||
|
||
prometheus: | ||
image: prom/prometheus | ||
container_name: prometheus-${teamname:-defaultASW} | ||
profiles: ["dev"] | ||
networks: | ||
- mynetwork | ||
volumes: | ||
- ./gatewayservice/monitoring/prometheus:/etc/prometheus | ||
- prometheus_data:/prometheus | ||
ports: | ||
- "9090:9090" | ||
depends_on: | ||
- gatewayservice | ||
|
||
grafana: | ||
image: grafana/grafana | ||
container_name: grafana-${teamname:-defaultASW} | ||
profiles: ["dev"] | ||
networks: | ||
- mynetwork | ||
volumes: | ||
- grafana_data:/var/lib/grafana | ||
- ./gatewayservice/monitoring/grafana/provisioning:/etc/grafana/provisioning | ||
environment: | ||
- GF_SERVER_HTTP_PORT=9091 | ||
- GF_AUTH_DISABLE_LOGIN_FORM=true | ||
- GF_AUTH_ANONYMOUS_ENABLED=true | ||
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin | ||
ports: | ||
- "9091:9091" | ||
depends_on: | ||
- prometheus | ||
|
||
|
||
volumes: | ||
mongodb_data: | ||
prometheus_data: | ||
grafana_data: | ||
|
||
networks: | ||
mynetwork: | ||
driver: bridge |
Oops, something went wrong.