Skip to content

Commit

Permalink
refactor: modify projects to add docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardo committed Sep 7, 2023
1 parent 4b9be7c commit 6199e9e
Show file tree
Hide file tree
Showing 17 changed files with 122 additions and 126 deletions.
25 changes: 0 additions & 25 deletions .dockerignore

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/azure-functions-app-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# run: |
# echo "AZURE_BLOB_STORAGE_CONNECTION_STRING=${{ secrets.AZURE_BLOB_STORAGE_CONNECTION_STRING }}
# AZURE_BLOB_STORAGE_CONTAINER_NAME=${{ secrets.AZURE_BLOB_STORAGE_CONTAINER_NAME }}
# AZURE_POSTGRES_CONNECTION_STRING=${{ secrets.AZURE_POSTGRES_CONNECTION_STRING }}
# POSTGRES_CONNECTION_STRING=${{ secrets.POSTGRES_CONNECTION_STRING }}
# JWT_AUDIENCE=${{ secrets.JWT_AUDIENCE }}
# JWT_EXPIRE_IN=${{ secrets.JWT_EXPIRE_IN }}
# JWT_ISSUER=${{ secrets.JWT_ISSUER }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/azure-webapps-dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: |
echo "AZURE_BLOB_STORAGE_CONNECTION_STRING=${{ secrets.AZURE_BLOB_STORAGE_CONNECTION_STRING }}
AZURE_BLOB_STORAGE_CONTAINER_NAME=${{ secrets.AZURE_BLOB_STORAGE_CONTAINER_NAME }}
AZURE_POSTGRES_CONNECTION_STRING=${{ secrets.AZURE_POSTGRES_CONNECTION_STRING }}
POSTGRES_CONNECTION_STRING=${{ secrets.POSTGRES_CONNECTION_STRING }}
JWT_AUDIENCE=${{ secrets.JWT_AUDIENCE }}
JWT_EXPIRE_IN=${{ secrets.JWT_EXPIRE_IN }}
JWT_ISSUER=${{ secrets.JWT_ISSUER }}
Expand Down
23 changes: 2 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
# Infrastructure.WebAPI
# GPIC WebAPI / WebFunctions

Restful API created in .NET 7.0.0 to support SPA.

## 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).
6 changes: 0 additions & 6 deletions src/CopetSystem.API.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoC", "Infrastructure\IoC\I
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI", "Infrastructure\WebAPI\WebAPI.csproj", "{163219BE-A0D2-41A1-A028-501AAB069BD9}"
EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "Docker\docker-compose.dcproj", "{58DF51E2-67F0-4740-B20B-8DE70C99FE2B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Services", "Infrastructure\Services\Services.csproj", "{7555C53A-BADC-49D9-82BE-C4D8587260EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "Application\Application.csproj", "{10D17198-CD98-48BF-BEF3-A689B668F5E3}"
Expand Down Expand Up @@ -47,10 +45,6 @@ Global
{163219BE-A0D2-41A1-A028-501AAB069BD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{163219BE-A0D2-41A1-A028-501AAB069BD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{163219BE-A0D2-41A1-A028-501AAB069BD9}.Release|Any CPU.Build.0 = Release|Any CPU
{58DF51E2-67F0-4740-B20B-8DE70C99FE2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58DF51E2-67F0-4740-B20B-8DE70C99FE2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58DF51E2-67F0-4740-B20B-8DE70C99FE2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58DF51E2-67F0-4740-B20B-8DE70C99FE2B}.Release|Any CPU.Build.0 = Release|Any CPU
{7555C53A-BADC-49D9-82BE-C4D8587260EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7555C53A-BADC-49D9-82BE-C4D8587260EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7555C53A-BADC-49D9-82BE-C4D8587260EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
35 changes: 35 additions & 0 deletions src/Docker/Postgres/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3.4'

services:
# PostgreSQL Database
postgres:
image: postgres:latest
container_name: postgres
environment:
POSTGRES_PASSWORD: Copet@123
POSTGRES_USER: copet-admin
POSTGRES_DB: COPET_DB
ports:
- 15432:5432
volumes:
- ./volumes/postgresql:/var/lib/postgresql/data
networks:
- gpic-network

# PostgreAdmin UI
pgadmin:
image: dpage/pgadmin4:latest
container_name: pgadmin
environment:
PGADMIN_DEFAULT_EMAIL: eduardo-paes@outlook.com
PGADMIN_DEFAULT_PASSWORD: CopetSystem!2022
ports:
- 16543:80
depends_on:
- postgres
networks:
- gpic-network

networks:
gpic-network:
driver: bridge
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ services:
environment:
- ACCEPT_EULA=Y
- SEQ_LICENSE_KEY=<your-license-key>
networks:
- gpic-network

networks:
gpic-network:
driver: bridge
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
version: '3.4'

services:

# PostgreSQL Database
postgres:
container_name: postgres_gpic
image: postgres:latest
container_name: postgres
environment:
POSTGRES_PASSWORD: Copet@123
POSTGRES_USER: copet-admin
Expand All @@ -14,48 +15,38 @@ services:
volumes:
- ./volumes/postgresql:/var/lib/postgresql/data
networks:
- postgres-network

# PostgreAdmin UI
pgadmin:
image: dpage/pgadmin4:latest
container_name: pgadmin
environment:
PGADMIN_DEFAULT_EMAIL: eduardo-paes@outlook.com
PGADMIN_DEFAULT_PASSWORD: CopetSystem!2022
ports:
- 16543:80
depends_on:
- postgres
networks:
- postgres-network
- gpic-network

# Seq - Servidor de Logs
seq:
container_name: seq_gpic
image: datalust/seq:latest
ports:
- "5341:80"
environment:
- ACCEPT_EULA=Y
- SEQ_LICENSE_KEY=<your-license-key>
- SEQ_API_KEY=vxM2YLukOTgnraaYczDh
networks:
- postgres-network
- gpic-network

# Web API
webapi:
container_name: webapi_gpic
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
ports:
- 5555:443
- 5051:443
- 5050:80
volumes:
- ~/.aspnet/https:/root/.aspnet/https:ro
- ~/.microsoft/usersecrets:/root/.microsoft/usersecrets:ro
depends_on:
- postgres
- seq
networks:
- postgres-network
- gpic-network

networks:
postgres-network:
gpic-network:
driver: bridge
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ services:
webapi:
image: ${DOCKER_REGISTRY-}webapi
build:
context: ../
context: ../../
dockerfile: Infrastructure/WebAPI/Dockerfile
10 changes: 10 additions & 0 deletions src/Docker/WebAPI/init-seq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Gere uma API Key aleatória
api_key=$(openssl rand -hex 32)

# Defina a API Key como uma variável de ambiente
export SEQ_API_KEY=$api_key

# Inicie o Seq Logger
exec "$@"
20 changes: 20 additions & 0 deletions src/Docker/WebAPI/sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Email Service
SMTP_EMAIL_USERNAME=EMAIL
SMTP_EMAIL_PASSWORD=SENHA

# JWT Secrets
JWT_SECRET_KEY=8y/B?E(G+KbPeShVmYq3t6w9z$C&F)J@McQfTjWnZr4u7x!A%D*G-KaPdRgUkXp2
JWT_EXPIRE_IN=60
JWT_ISSUER=gpic-webapi
JWT_AUDIENCE=webapi.gpic.server

# SEQ Logger Service
SEQ_API_KEY=vxM2YLukOTgnraaYczDh
SEQ_URL=http://seq_gpic:5341

# Connection String do banco de dados
POSTGRES_CONNECTION_STRING="Server=postgres_gpic;Database=COPET_DB;Port=5432;User Id=copet-admin;Password=Copet@123;"

# Executa a migração do banco de dados
# deixe como True apenas na inicilização
EXECUTE_MIGRATION=False
18 changes: 0 additions & 18 deletions src/Docker/docker-compose.dcproj

This file was deleted.

27 changes: 0 additions & 27 deletions src/Dockerfile

This file was deleted.

16 changes: 16 additions & 0 deletions src/Infrastructure/IoC/PersistenceDI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ public static IServiceCollection AddPersistence(this IServiceCollection services
b => b.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName)));
#endregion Inicialização do banco de dados

#region Migração do banco de dados
if (dotEnvSecrets.ExecuteMigration())
{
try
{
var dbContext = services.BuildServiceProvider().GetService<ApplicationDbContext>();
dbContext?.Database.Migrate();
Console.WriteLine("Migração realizada com sucesso.");
}
catch (Exception ex)
{
Console.WriteLine($"Ocorreu um erro durante a migração do banco de dados. {ex}");
}
}
#endregion Migração do banco de dados

#region Repositórios
services.AddScoped<IAreaRepository, AreaRepository>();
services.AddScoped<IActivityRepository, ActivityRepository>();
Expand Down
14 changes: 13 additions & 1 deletion src/Infrastructure/IoC/Utils/DotEnvSecrets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public string GetBlobStorageContainerName()

public string GetDatabaseConnectionString()
{
return DotNetEnv.Env.GetString("AZURE_POSTGRES_CONNECTION_STRING");
return DotNetEnv.Env.GetString("POSTGRES_CONNECTION_STRING");
}

public string GetSmtpUserName()
Expand Down Expand Up @@ -67,5 +67,17 @@ public string GetJwtExpirationTime()
{
return DotNetEnv.Env.GetString("JWT_EXPIRE_IN");
}

public bool ExecuteMigration()
{
try
{
return DotNetEnv.Env.GetBool("EXECUTE_MIGRATION");
}
catch
{
return false;
}
}
}
}
7 changes: 4 additions & 3 deletions src/Infrastructure/WebAPI/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["Infrastructure/WebAPI/WebAPI.csproj", "Infrastructure/WebAPI/"]
COPY ["Infrastructure/IoC/IoC.csproj", "Infrastructure/IoC/"]
COPY ["Adapters/Adapters.csproj", "Adapters/"]
COPY ["Domain/Domain.csproj", "Domain/"]
COPY ["Application/Application.csproj", "Application/"]
COPY ["Infrastructure/Services/Services.csproj", "Infrastructure/Services/"]
COPY ["Infrastructure/Persistence/Persistence.csproj", "Infrastructure/Persistence/"]
COPY ["Infrastructure/IoC/IoC.csproj", "Infrastructure/IoC/"]
COPY ["Infrastructure/WebAPI/WebAPI.csproj", "Infrastructure/WebAPI/"]
RUN dotnet restore "Infrastructure/WebAPI/WebAPI.csproj"
COPY . .
WORKDIR "/src/Infrastructure/WebAPI"
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/WebAPI/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseSwaggerUI();

// Show development mode message
Console.WriteLine("Development mode");
Console.WriteLine("Swagger is up.");
}

// UseExceptionHandler for non-development environments
Expand Down

0 comments on commit 6199e9e

Please sign in to comment.