Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated readme #15

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f705496
Deployed docs and updated docs/README.md
labra Jan 18, 2024
e0d2580
Updated README
labra Jan 18, 2024
7253a36
Merge pull request #1 from pglez82/master
labra Jan 18, 2024
ca0ff3d
Updated README
labra Jan 18, 2024
0b3cea5
Removed dependabot and change name of github action to release
labra Jan 21, 2024
c3ccc90
Updated sonar
labra Jan 21, 2024
2b13d4e
Updated badges
labra Jan 21, 2024
4e46a61
Replaced names from original repo (pzlez) to arquisoft
labra Jan 21, 2024
cacb599
Changing how the composes are structured
augustocristian Jan 21, 2024
9bc62ff
Merge pull request #2 from Arquisoft/dev_composeimprovement
labra Jan 22, 2024
37fd26b
Added code that runs tests to build.yml
labra Jan 22, 2024
bddcdd1
Merge branch 'master' of https://github.com/Arquisoft/wiq_0
labra Jan 22, 2024
9eebb69
Changed name of sonar project
labra Jan 22, 2024
f179ce6
Added fetch-depth 0
labra Jan 22, 2024
ff5fadb
Update sonar-project.properties
ExarcaFidalgo Jan 22, 2024
3a7d874
Update README.md
ExarcaFidalgo Jan 22, 2024
f67f94d
Update sonar-project.properties
ExarcaFidalgo Jan 22, 2024
caa267f
Update README.md
ExarcaFidalgo Jan 22, 2024
72fedaf
Fixing some old-fashioned code in the actions and README.md file
augustocristian Jan 23, 2024
09590d8
0 por es6b
ExarcaFidalgo Jan 23, 2024
d7948e9
0 por es6c
ExarcaFidalgo Jan 23, 2024
2f84702
Merge pull request #3 from Arquisoft/dev_fixcomposeandactions
pglez82 Jan 23, 2024
d658968
Adding the .env to the service deployment
augustocristian Jan 23, 2024
d6ec049
Merge pull request #4 from Arquisoft/ft_Addenvfiledeployment
augustocristian Jan 23, 2024
f7c5893
Adding -O to wget to overwrite existing files
augustocristian Jan 23, 2024
88c299b
Changed welcome message and some devDependencies
labra Jan 26, 2024
fa9aec3
Merge branch 'master' of https://github.com/Arquisoft/wiq_0
labra Jan 26, 2024
dbaea69
Merge branch 'master' into master
ExarcaFidalgo Jan 26, 2024
dc74163
Revert "Merge branch 'master' into master"
ExarcaFidalgo Jan 26, 2024
a50371b
Merge branch 'master' into master
ExarcaFidalgo Jan 26, 2024
e049274
Revert "Merge branch 'master' of https://github.com/Arquisoft/wiq_0"
ExarcaFidalgo Jan 26, 2024
e9278f2
Expiando mis pecados
ExarcaFidalgo Jan 26, 2024
1f0cbfb
Minor fixes to tear-down the container
augustocristian Feb 12, 2024
f4f8efb
Merge pull request #6 from Arquisoft/ft_solveproblemcompose
labra Feb 12, 2024
304dd15
Adding --pull always to the deployment command to force image downloa…
augustocristian Mar 14, 2024
227b3f5
Added OpenAPI specification for wiq_0 gateway service (#17)
augustocristian Mar 17, 2024
6e9d94e
Sync package.json with package-lock.json (#18)
augustocristian Mar 17, 2024
789b3f2
Adding some examples to the OpenAPI spec (#19)
augustocristian Mar 17, 2024
7c88c7e
Fixing OpenAPI E2E Tests
pglez82 Mar 18, 2024
997e0bc
Small local changes
labra Mar 19, 2024
520ce67
Add the README.md with the monitoring info (#22)
augustocristian Apr 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
teamname="asw2324_0"
teamname="wiq_0"
62 changes: 0 additions & 62 deletions .github/dependabot.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/build.yml
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 }}
22 changes: 13 additions & 9 deletions .github/workflows/asw2324.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI for ASW2324
name: Deploy on release

on:
release:
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
env:
API_URI: http://${{ secrets.DEPLOY_HOST }}:8000
with:
name: pglez82/asw2324_0/webapp
name: arquisoft/wiq_0/webapp
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
Expand All @@ -71,7 +71,7 @@ jobs:
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: pglez82/asw2324_0/authservice
name: arquisoft/wiq_0/authservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
Expand All @@ -88,7 +88,7 @@ jobs:
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: pglez82/asw2324_0/userservice
name: arquisoft/wiq_0/userservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
Expand All @@ -102,10 +102,14 @@ 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:
name: pglez82/asw2324_0/gatewayservice
name: arquisoft/wiq_0/gatewayservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
Expand All @@ -122,7 +126,7 @@ jobs:
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://raw.githubusercontent.com/pglez82/asw2324_0/master/docker-compose.yml
wget https://raw.githubusercontent.com/pglez82/asw2324_0/master/docker-compose-deploy.override.yml
docker compose down
docker compose -f docker-compose.yml -f docker-compose-deploy.override.yml 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
66 changes: 44 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# asw2324_0
# wiq_0

[![Actions Status](https://github.com/pglez82/asw2324_0/workflows/CI%20for%20ASW2324/badge.svg)](https://github.com/pglez82/asw2324_0/actions)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=pglez82_asw2324_0&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=pglez82_asw2324_0)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=pglez82_asw2324_0&metric=coverage)](https://sonarcloud.io/summary/new_code?id=pglez82_asw2324_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)

<p float="left">
<img src="https://blog.wildix.com/wp-content/uploads/2020/06/react-logo.jpg" height="100">
<img src="https://miro.medium.com/max/365/1*Jr3NFSKTfQWRUyjblBSKeg.png" height="100">
</p>
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 is a base project for the Software Architecture course in 2023/2024. It is a basic application composed of several components.
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.
- **Gateway service**. Express service that is exposed to the public and serves as a proxy to the two previous ones.
- **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.
Expand All @@ -23,27 +20,49 @@ Both the user and auth service share a Mongo database that is accessed with mong
### Using docker

The fastest way for launching this sample project is using docker. Just clone the project:
```git clone [email protected]:pglez82/asw2324_0.git```

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

and launch it with docker compose:
```docker compose -f docker-compose.yml -f docker-compose-dev.override.yml up --build```

### Component by component start
```sh
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:

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

You can use also services like Mongo Altas for running a Mongo database in the cloud.
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`.
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 all the cloud services provide. This means, deploying our Docker containers directly. Here I am going to use the first approach. I am going to create a virtual machine in a cloud service and after installing docker and docker-compose, deploy our containers there using GitHub Actions and SSH.

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.
Expand All @@ -65,9 +84,10 @@ 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. The precondition to trigger a deployment is going to be: "create a new release". The actions to execute are the following:

![imagen](https://github.com/pglez82/asw2324_0/assets/10683040/44d0fe21-a93f-4b01-b458-ab7af4267fa3)
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.

Expand All @@ -86,14 +106,16 @@ deploy:
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://raw.githubusercontent.com/pglez82/asw2324_0/master/docker-compose-deploy.yml -O docker-compose.yml
docker compose down --volumes
docker compose -f docker-compose.yml -f docker-compose-deploy.override.yml 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.
41 changes: 0 additions & 41 deletions docker-compose-deploy.override.yml

This file was deleted.

Loading