Skip to content

Commit

Permalink
Merge pull request #36 from eduardo-paes/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
Eduardo Paes authored Nov 2, 2023
2 parents c352901 + 20d7090 commit b386f24
Show file tree
Hide file tree
Showing 982 changed files with 43,931 additions and 11,305 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/azure-functions-app-dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Deploy WebFunctions to Azure

on:
push:
branches: ["main"]

env:
AZURE_FUNCTIONAPP_NAME: "GPIC-Stg-WebFunctions" # set this to your function app name on Azure
AZURE_FUNCTIONAPP_PACKAGE_PATH: "src" # set this to the path to your function app project, defaults to the repository root
DOTNET_VERSION: "7.0" # set this to the dotnet version to use (e.g. '2.1.x', '3.1.x', '5.0.x')

jobs:
build-and-deploy:
runs-on: ubuntu-latest # For Linux, use ubuntu-latest
environment: dev
steps:
- name: "Checkout GitHub Action"
uses: actions/checkout@v3

- name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: "Resolve Project Dependencies Using Dotnet"
shell: bash # For Linux, use bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
dotnet build --configuration Release --output ./output
popd
- name: Create env
run: |
echo "AZURE_BLOB_STORAGE_CONNECTION_STRING=${{ secrets.AZURE_BLOB_STORAGE_CONNECTION_STRING }}
AZURE_BLOB_STORAGE_CONTAINER_NAME=${{ secrets.AZURE_BLOB_STORAGE_CONTAINER_NAME }}
POSTGRES_CONNECTION_STRING=${{ secrets.POSTGRES_CONNECTION_STRING }}
FRONTEND_URL=${{ secrets.FRONTEND_URL }}
ALLOW_ORIGINS=${{ secrets.ALLOW_ORIGINS }}
JWT_AUDIENCE=${{ secrets.JWT_AUDIENCE }}
JWT_EXPIRE_IN=${{ secrets.JWT_EXPIRE_IN }}
JWT_ISSUER=${{ secrets.JWT_ISSUER }}
JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}
SEQ_API_KEY=${{ secrets.SEQ_API_KEY }}
SEQ_URL=${{ secrets.SEQ_URL }}
SMTP_EMAIL_PASSWORD=${{ secrets.SMTP_EMAIL_PASSWORD }}
SMTP_EMAIL_USERNAME=${{ secrets.SMTP_EMAIL_USERNAME }}
EXECUTE_MIGRATION=${{ secrets.EXECUTE_MIGRATION }}" > src/Infrastructure/WebAPI/.env
- name: "Run Azure Functions Action"
uses: Azure/functions-action@v1
id: fa
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: "${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output"
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }} # Remove publish-profile to use Azure RBAC
69 changes: 59 additions & 10 deletions .github/workflows/azure-webapps-dotnet-core.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
name: Build and deploy ASP.Net Core app to an Azure Web App
name: Deploy WebAPI to Azure

env:
AZURE_WEBAPP_NAME: GPIC-Staging-WebAPI # set this to the name of your Azure Web App
AZURE_WEBAPP_PACKAGE_PATH: 'src' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '7.0' # set this to the .NET Core version to use
AZURE_WEBAPP_NAME: ${{ secrets.AZURE_WEBAPP_NAME }}
AZURE_WEBAPP_PACKAGE_PATH: "."
DOTNET_VERSION: "7.0"
PROJECT_PATH: "src/Infrastructure/WebAPI/WebAPI.csproj"
WEBAPI_PATH: "src/Infrastructure/WebAPI/"
UNIT_TESTS_PROJ: "src/Domain.Tests/Domain.Tests.csproj"
INTEGRATION_TESTS_PROJ: "src/Application.Tests/Application.Tests.csproj"
ASPNETCORE_ENVIRONMENT: ${{ secrets.ASPNETCORE_ENVIRONMENT }}

on:
push:
branches: [ "main" ]
branches: ["staging"]
workflow_dispatch:

permissions:
Expand All @@ -16,6 +21,7 @@ permissions:
jobs:
build:
runs-on: ubuntu-latest
environment: STAGING

steps:
- uses: actions/checkout@v3
Expand All @@ -33,25 +39,68 @@ jobs:
restore-keys: |
${{ runner.os }}-nuget-
- name: Create env
run: |
echo "AZURE_BLOB_STORAGE_CONNECTION_STRING=${{ secrets.AZURE_BLOB_STORAGE_CONNECTION_STRING }}
AZURE_BLOB_STORAGE_CONTAINER_NAME=${{ secrets.AZURE_BLOB_STORAGE_CONTAINER_NAME }}
POSTGRES_CONNECTION_STRING=${{ secrets.POSTGRES_CONNECTION_STRING }}
FRONTEND_URL=${{ secrets.FRONTEND_URL }}
ALLOW_ORIGINS=${{ secrets.ALLOW_ORIGINS }}
JWT_AUDIENCE=${{ secrets.JWT_AUDIENCE }}
JWT_EXPIRE_IN=${{ secrets.JWT_EXPIRE_IN }}
JWT_ISSUER=${{ secrets.JWT_ISSUER }}
JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}
SEQ_API_KEY=${{ secrets.SEQ_API_KEY }}
SEQ_URL=${{ secrets.SEQ_URL }}
SMTP_EMAIL_PASSWORD=${{ secrets.SMTP_EMAIL_PASSWORD }}
SMTP_EMAIL_USERNAME=${{ secrets.SMTP_EMAIL_USERNAME }}
EXECUTE_MIGRATION=${{ secrets.EXECUTE_MIGRATION }}" > src/Infrastructure/WebAPI/.env
- name: Set environment variable
run: echo "ASPNETCORE_ENVIRONMENT=${{ env.ASPNETCORE_ENVIRONMENT }}" >> $GITHUB_ENV

- name: Build with dotnet
run: dotnet build --configuration Release
run: dotnet build ${{env.PROJECT_PATH}} --configuration Release -o ${{env.DOTNET_ROOT}}/dist

- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Dotnet publish
run: dotnet publish ${{env.PROJECT_PATH}} -c Release -o ${{env.DOTNET_ROOT}}/myapp

- name: Copy XML documentation file
run: cp ${{env.DOTNET_ROOT}}/dist/*.xml ${{env.DOTNET_ROOT}}/myapp/

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp

test:
needs: build
runs-on: ubuntu-latest
environment: STAGING

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Run Unit Tests
run: dotnet test ${{ env.UNIT_TESTS_PROJ }} --configuration Release

- name: Run Integration Tests
run: dotnet test ${{ env.INTEGRATION_TESTS_PROJ }} --configuration Release

deploy:
permissions:
contents: none
runs-on: ubuntu-latest
needs: build
needs: test
environment:
name: 'Development'
name: STAGING
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
Expand Down
15 changes: 11 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,21 @@ FodyWeavers.xsd
*.sln.iml

volumes
Migrations

node_modules
.DS_Store

certificate
certificate/*

RemoteFiles
RemoteFiles/*
src/Infrastructure/WebAPI/.env
storage
storage/*

temp
temp/*

files
files/*

**/.env
thunder-tests
5 changes: 4 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"recommendations": []
"recommendations": [
"ms-azuretools.vscode-azurefunctions",
"ms-dotnettools.csharp"
]
}
8 changes: 7 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
},
{
"name": "Attach to .NET Functions",
"type": "coreclr",
"request": "attach",
"processId": "${command:azureFunctions.pickProcess}"
}
]
}
}
12 changes: 10 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{
"dotnet-test-explorer.testProjectPath": "src/Domain.Tests/Domain.Tests.csproj"
}
// "dotnet-test-explorer.testProjectPath": "src/Domain.Tests/Domain.Tests.csproj",
"dotnet-test-explorer.testProjectPath": "src/Application.Tests/Application.Tests.csproj",
"dotnet.defaultSolution": "src/GPIC.BackEnd.sln",
"azureFunctions.deploySubpath": "src/Infrastructure/WebFunctions/bin/Release/net7.0/publish",
"azureFunctions.projectLanguage": "C#",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
"azureFunctions.projectSubpath": "src/Infrastructure/WebFunctions",
"azureFunctions.preDeployTask": "publish (functions)"
}
78 changes: 77 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,82 @@
"${workspaceFolder}/src/Infrastructure/WebAPI/WebAPI.csproj"
],
"problemMatcher": "$msCompile"
},
{
"label": "clean (functions)",
"command": "dotnet",
"args": [
"clean",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"type": "process",
"problemMatcher": "$msCompile",
"options": {
"cwd": "${workspaceFolder}/src/Infrastructure/WebFunctions"
}
},
{
"label": "build (functions)",
"command": "dotnet",
"args": [
"build",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"type": "process",
"dependsOn": "clean (functions)",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$msCompile",
"options": {
"cwd": "${workspaceFolder}/src/Infrastructure/WebFunctions"
}
},
{
"label": "clean release (functions)",
"command": "dotnet",
"args": [
"clean",
"--configuration",
"Release",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"type": "process",
"problemMatcher": "$msCompile",
"options": {
"cwd": "${workspaceFolder}/src/Infrastructure/WebFunctions"
}
},
{
"label": "publish (functions)",
"command": "dotnet",
"args": [
"publish",
"--configuration",
"Release",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"type": "process",
"dependsOn": "clean release (functions)",
"problemMatcher": "$msCompile",
"options": {
"cwd": "${workspaceFolder}/src/Infrastructure/WebFunctions"
}
},
{
"type": "func",
"dependsOn": "build (functions)",
"options": {
"cwd": "${workspaceFolder}/src/Infrastructure/WebFunctions/bin/Debug/net7.0"
},
"command": "host start",
"isBackground": true,
"problemMatcher": "$func-dotnet-watch"
}
]
}
}
67 changes: 2 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,3 @@
# Infrastructure.WebAPI
# GPIC WebAPI / WebFunctions

Restful API created in .NET 7.0.0 to support SPA.

## DataBase - PostgreSQL

Para levantar o banco de dados é necessário executar o comando abaixo na pasta raiz:

```bash
cd docker
docker compose up -d
```

Em seguida, é preciso acessar o pgAdmin através da rota abaixo:

- [PGAdmin](http://localhost:16543/browser)

E criar um servidor utilizando as informações de _host_, _username_, _password_ e _database_ que estão informadas no arquivo docker-compose.yaml utilizado.
Exemplo:

- **host**: copet-system-db
- **username**: copet-admin
- **password**: Copet@123
- **database**: COPET_DB
- **port**: 5432

## Migrations

Criando as Migrations iniciais para criação das tabelas do banco de dados:

```bash
cd src/Infrastructure/WebAPI
dotnet ef migrations add Initialize --project ../Persistence/Persistence.csproj
```

Executando as Migrations:

```bash
dotnet ef database update
```

Removendo as Migrations:

```bash
cd src/Infrastructure/WebAPI
dotnet ef migrations remove --project ../Persistence/Persistence.csproj
```

## Execução com Dotnet

Comandos para execução do projeto .NET utilizando CLI:

```bash
cd Infrastructure.WebAPI
dotnet build
dotnet run
```

## Execucação com Docker

Comandos para execução do projeto .NET utilizando Docker:

```bash
docker build . -t copet-system-api:dev
docker run --name copet-system-api -p 8080:80 -d copet-system-api:dev
```
Restful API created in .NET 7 to centralize the business rules of the GPIC system (Gerenciador de Projetos de Iniciação Científica).
Loading

0 comments on commit b386f24

Please sign in to comment.