Docker + Jenkfins File + v0.1

This commit is contained in:
Marco Santos
2024-11-18 10:42:44 +00:00
parent 964bad93f1
commit 048d3ea82f
32 changed files with 505 additions and 975 deletions

View File

@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using GeradoresService;
using GeradoresService.DAL;
namespace GeradoresWS.Controllers
{
@@ -7,8 +8,13 @@ namespace GeradoresWS.Controllers
[Route("[controller]")]
public class GenerateController : Controller
{
GeradoresContext _context;
public GenerateController(GeradoresContext context)
{
_context = context;
}
#region NIF
[HttpGet("GetNIFTypes")]
public List<NIF.NIFType> GetNIFTypes()
{
@@ -18,13 +24,15 @@ namespace GeradoresWS.Controllers
[HttpGet("GenerateNIF")]
public string GenerateNIF(string? type)
{
return NIF.Generate(type);
var nif = new NIF(_context);
return nif.Generate(type);
}
[HttpGet("ValidateNIF")]
public bool ValidateNIF(string nif)
{
return NIF.Validate(nif);
var teste = new NIF(_context);
return teste.Validate(nif);
}
#endregion

32
GeradoresWS/Dockerfile Normal file
View File

@@ -0,0 +1,32 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["GeradoresWS/GeradoresWS.csproj", "GeradoresWS/"]
COPY ["GeradoresService/GeradoresService.csproj", "GeradoresService/"]
RUN dotnet restore "GeradoresWS/GeradoresWS.csproj"
COPY . .
WORKDIR "/src/GeradoresWS"
RUN dotnet build "GeradoresWS.csproj" -c debug -o /app/build
FROM build AS publish
RUN dotnet publish "GeradoresWS.csproj" -c debug -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
# Set environment variables
ENV ASPNETCORE_URLS=http://+:8080
ENV ASPNETCORE_ENVIRONMENT=Production
ENTRYPOINT ["dotnet", "GeradoresWS.dll"]

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>df357c84-88b1-4100-86d1-889166b333f7</UserSecretsId>

View File

@@ -1,3 +1,6 @@
using GeradoresService.DAL;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
@@ -7,13 +10,16 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var connectionString = builder.Configuration.GetConnectionString("GeradoresConnection");
builder.Services.AddDbContext<GeradoresContext>(options => options.UseSqlServer(connectionString));
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.UseAuthorization();

View File

@@ -32,6 +32,10 @@
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"environmentVariables": {
"ASPNETCORE_URLS": "http://+:8080",
"ASPNETCORE_ENVIRONMENT": "Development"
},
"publishAllPorts": true,
"useSSL": false
}

View File

@@ -5,5 +5,9 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ConnectionStrings": {
"GeradoresConnection": "server=127.0.0.1;uid=sa;pwd=mssqlAdmin!1;database=Geradores;TrustServerCertificate=True;"
}
}