Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 14 additions & 21 deletions .azure/pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ variables:
value: "Keeptrack.slnx"
- name: "TestProjects"
value: "test/*Tests/*.csproj"
- name: "UnitTestProjects"
value: "test/*UnitTests/*.csproj"

stages:
- stage: "unit_testing"
Expand All @@ -46,13 +44,18 @@ stages:
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: 1
- task: DotNetCoreCLI@2
displayName: "Run .NET unit tests"
- task: CmdLine@2
displayName: "Run .NET test projects"
inputs:
command: "test"
projects: "$(UnitTestProjects)"
arguments: "--configuration $(BuildConfiguration)"
script: >
dotnet test
--configuration $(BuildConfiguration)
-- --filter-query "/[Category=UnitTests]"
env:
AllowedOrigins__0: "5207"
Features__IsScalarEnabled: true
Features__IsHttpsRedirectionEnabled: false
ASPNETCORE_ENVIRONMENT: Development
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: 1

Expand Down Expand Up @@ -104,27 +107,17 @@ stages:
inputs:
command: "test"
projects: "$(TestProjects)"
arguments: '--configuration $(BuildConfiguration) --report-xunit-trx --coverage --coverage-output-format cobertura -- --filter-query "/[(Category=UnitTests)|(Mode=Readonly)]"'
arguments: |
--configuration $(BuildConfiguration)
--report-xunit-trx --coverage --coverage-output-format cobertura
-- --filter-query "/[(Category=UnitTests)|(Mode=Readonly)]"
env:
AllowedOrigins__0: "5207"
Features__IsScalarEnabled: true
Features__IsHttpsRedirectionEnabled: false
ASPNETCORE_ENVIRONMENT: Development
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: 1
# - task: CmdLine@2
# displayName: "Run .NET test projects"
# inputs:
# script: >
# dotnet test
# --configuration $(BuildConfiguration)
# --report-xunit-trx
# --coverage
# --coverage-output-format cobertura
# -- --filter-query "/[(Category=UnitTests)|(Mode=Readonly)]"
# env:
# DOTNET_CLI_TELEMETRY_OPTOUT: 1
# DOTNET_NOLOGO: 1
- task: PublishBuildArtifacts@1
displayName: "Publish artifacts"
condition: failed()
Expand Down
50 changes: 25 additions & 25 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
13 changes: 7 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

on:
push:
branches: [main]
branches: [ main ]
pull_request:
branches: [main]
branches: [ main ]
workflow_dispatch:
inputs:
run-code-quality:
Expand Down Expand Up @@ -37,13 +37,13 @@ jobs:

markup-lint:
name: Markup
uses: devpro/github-workflow-parts/.github/workflows/reusable-markup-lint.yml@b5937db15c2a060f3c9dd989ca06bac7eccc75a7
uses: devpro/github-workflow-parts/.github/workflows/reusable-markup-lint.yml@62dbf6e833e49230ab34ef3c44093ebb727a095f

code-quality:
name: Code
needs: git-check
if: needs.git-check.outputs.app_changed == 'true' || (github.event_name == 'workflow_dispatch' && inputs.run-code-quality)
uses: devpro/github-workflow-parts/.github/workflows/reusable-dotnet-quality.yml@b5937db15c2a060f3c9dd989ca06bac7eccc75a7
uses: devpro/github-workflow-parts/.github/workflows/reusable-dotnet-quality.yml@62dbf6e833e49230ab34ef3c44093ebb727a095f
with:
custom-commands: |
./scripts/mongodb-install.sh
Expand All @@ -58,10 +58,11 @@ jobs:
Infrastructure__MongoDB__DatabaseName=keeptrack_ci
fossa-enabled: true
sonar-enabled: true
sonar-exclusions: "samples/**"
sonar-organization: ${{ vars.SONAR_ORG }}
sonar-project-key: ${{ vars.SONAR_PROJECT_KEY }}
sonar-project-name: Keeptrack
workflow-parts-version: b5937db15c2a060f3c9dd989ca06bac7eccc75a7
workflow-parts-version: 62dbf6e833e49230ab34ef3c44093ebb727a095f
secrets:
fossa-api-key: ${{ secrets.FOSSA_API_KEY }}
sonar-token: ${{ secrets.SONAR_TOKEN }}
Expand Down Expand Up @@ -89,7 +90,7 @@ jobs:
- name: "Web Api"
image-name: "keeptrack-webapi"
image-definition: "src/WebApi/Dockerfile"
uses: devpro/github-workflow-parts/.github/workflows/reusable-container-scan.yml@b5937db15c2a060f3c9dd989ca06bac7eccc75a7
uses: devpro/github-workflow-parts/.github/workflows/reusable-container-scan.yml@62dbf6e833e49230ab34ef3c44093ebb727a095f
with:
image-definition: ${{ matrix.image-definition }}
image-name: ${{ matrix.image-name }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
permissions:
id-token: write
contents: read
uses: devpro/github-workflow-parts/.github/workflows/reusable-container-publication.yml@b5937db15c2a060f3c9dd989ca06bac7eccc75a7
uses: devpro/github-workflow-parts/.github/workflows/reusable-container-publication.yml@62dbf6e833e49230ab34ef3c44093ebb727a095f
with:
create-latest: ${{ github.ref_name == 'main' }}
image-definition: ${{ matrix.image-definition }}
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ Local.runsettings
# NPM
firebase.config.js
node_modules/
dist/
139 changes: 75 additions & 64 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,64 @@
# Contibutor guide
# Contributor guide

[![GitLab Pipeline Status](https://gitlab.com/devpro-labs/software/keeptrack/badges/main/pipeline.svg)](https://gitlab.com/devpro-labs/software/keeptrack/-/pipelines)
[![Build Status](https://dev.azure.com/devprofr/open-source/_apis/build/status/keeptrack-ci?branchName=main)](https://dev.azure.com/devprofr/open-source/_build/latest?definitionId=26&branchName=main)

## Design
Follow this steps to run/debug/develop the application on your machine.

This design of API has been inspired by the [Hexagonal Architecture](https://blog.octo.com/en/hexagonal-architecture-three-principles-and-an-implementation-example/).
For an environment, look at [operations.md](docs/operations.md).

NuGet Packages:
## Design

- [MongoDB C# Driver](https://www.mongodb.com/docs/drivers/csharp/current/)
The application source code is in the following .NET projects:

## Requirements
Project name | Technology | Project type
---------------------------|------------|------------------------------
`BlazorApp` | ASP.NET 10 | Blazor Server web application
`Common.System` | .NET 10 | Library
`Domain` | .NET 10 | Library
`Infrastructure.MongoDb` | .NET 10 | Library
`WebApi` | ASP.NET 10 | Web application (REST API)
`WebApi.Contracts` | .NET 10 | Library

- [.NET 10.0 SDK](https://dotnet.microsoft.com/download)
- MongoDB 8.2 database
- Local server
The application is using the following .NET packages (via NuGet):

```bash
cd D:/Programs/mongodb-8.2/bin
md log
md data
mongod --logpath log/mongod.log --dbpath data --port 27017
```
Name | Description
--------------------|--------------------
`FirebaseAdmin` | Firebase
`MongoDB.Bson` | MongoDB BSON
`MongoDB.Driver` | MongoDB .NET Driver
`Scalar.AspNetCore` | OpenAPI web UI

- [Docker](https://hub.docker.com/_/mongo/)
## Requirements

1. [.NET 10.0 SDK](https://dotnet.microsoft.com/download)

```bash
docker run --name mongodb -d -p 27017:27017 mongo:8.2
```
2. MongoDB database

- [MongoDB Atlas](https://cloud.mongodb.com/) cluster
Several options:

- Database indexes
- Local server

```bash
cd D:/Programs/mongodb-8.2/bin
md log
md data
mongod --logpath log/mongod.log --dbpath data --port 27017
```

- [Docker](https://hub.docker.com/_/mongo/)

```bash
docker run --name mongodb -d -p 27017:27017 mongo:8.2
```

- [MongoDB Atlas](https://cloud.mongodb.com/) cluster

```bash
docker run --rm --link mongodb -v "$(pwd)/scripts":/home/scripts mongo:8.2 bash -c "mongo mongodb://mongodb:27017/keeptrack /home/scripts/mongo-create-index.js"
```
3. IDE: Rider, Visual Studio, Visual Studio Code

## How to configure
## Configuration

### Web API
### Web API appsettings

Key | Description
------------------------------------------|--------------------------
Expand All @@ -49,10 +67,14 @@ Key | Description

This values can be easily provided as environment variables (replace ":" by "__") or by configuration (json).

Template for `src/Api/appsettings.Development.json`:
Template for `src/WebApi/appsettings.Development.json`:

```json
{
"AllowedOrigins": [
"http://localhost:5207",
"https://localhost:7042"
],
"Authentication": {
"JwtBearer": {
"Authority": "https://securetoken.google.com/<firebase-project-id>",
Expand All @@ -62,43 +84,54 @@ Template for `src/Api/appsettings.Development.json`:
}
}
},
"Features": {
"IsScalarEnabled": true,
"IsHttpsRedirectionEnabled": false
},
"Infrastructure": {
"MongoDB": {
"ConnectionString": "mongodb://localhost:27017",
"DatabaseName": "keeptrack"
"DatabaseName": "keeptrack_dev"
}
},
"Logging": {
"LogLevel": {
"KeepTrack": "Debug",
"Withywoods": "Debug"
"Default": "Debug",
"KeepTrack": "Debug"
}
}
}
```

### Blazor Server App
### Blazor Server App appsettings

TODO
Key | Required | Default value
----------------------------------------|----------|--------------
AllowedHosts | false | "*"
Features:IsHttpsRedirectionEnabled | false | true
Firebase:WebAppConfiguration:ApiKey | true | ""
Firebase:WebAppConfiguration:AuthDomain | true | ""
Firebase:WebAppConfiguration:ProjectId | true | ""
Firebase:ServiceAccount | true | ""
Logging:LogLevel:Default | false | "Information"
Logging:LogLevel:Microsoft.AspNetCore | false | "Warning"
WebApi:BaseUrl | true | ""

## How to build
## Run

```bash
dotnet restore
dotnet build
```

## How to debug
dotnet build

```bash
# run the API (https://localhost:5011/)
dotnet run --project src/WebApi

# run the Blazor WebAssembly web app (https://localhost:5021)
dotnet run --project src/BlazorApp
```

## How to test
## Tests

For integration tests, to manage the configuration (secrets) you can create a file at the root directory called `Local.runsettings` or define them as environment variables:

Expand All @@ -107,7 +140,7 @@ For integration tests, to manage the configuration (secrets) you can create a fi
<RunSettings>
<RunConfiguration>
<EnvironmentVariables>
<AllowedOrigins__0>http://localhost:4200</AllowedOrigins__0>
<AllowedOrigins__0>http://localhost:5207</AllowedOrigins__0>
<Infrastructure__MongoDB__ConnectionString>mongodb://localhost:27017</Infrastructure__MongoDB__ConnectionString>
<Infrastructure__MongoDB__DatabaseName>keeptrack_integrationtests</Infrastructure__MongoDB__DatabaseName>
<Authentication__JwtBearer__Authority></Authentication__JwtBearer__Authority>
Expand All @@ -130,31 +163,9 @@ Or in Rider, in "File | Settings | Build, Execution, Deployment | Unit Testing |

Set KESTREL_WEBAPP_URL to target a specific instance (not use web app test instance).

And execute all tests (unit and integration ones):

```bash
dotnet test --settings Local.runsettings
```

## How to deploy

- Add the outbound IP to the MongoDB Atlas cluster
- Add the application url to Firebase domains
- Create web project in Firebase and grab ids to be set to environment.ts file
- Create a GitHub OAuth application ([firebase.google.com](https://firebase.google.com/docs/auth/web/github-auth),
[github.com](https://github.com/settings/applications/new))
- Add URLs in Azure web app CORS page

## How to operate

- Backup MongoDB database

```bash
docker run --rm -it --workdir=/data --volume $(pwd):/data mongo:8.2 /bin/sh -c "mongodump --uri mongodb+srv://<USER>:<PASSWORD>@<CLUSTER>.<PROJECT>.mongodb.net/test"
```

- Restore MongoDB database
## Container images

```bash
docker run --rm -it --workdir=/data --volume $(pwd):/data mongo:8.2 /bin/sh -c "mongorestore --uri mongodb+srv://<USER>:<PASSWORD>@<CLUSTER>.<PROJECT>.mongodb.net"
docker build . -t devprofr/keeptrack-blazorapp:local -f src/BlazorApp/Dockerfile
docker build . -t devprofr/keeptrack-webapi:local -f src/WebApi/Dockerfile
```
Loading
Loading