diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fe1152b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,30 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*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 +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** \ No newline at end of file diff --git a/Vegasco.slnx b/Vegasco.slnx new file mode 100644 index 0000000..287e45b --- /dev/null +++ b/Vegasco.slnx @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/Vegasco.WebApi/Dockerfile b/src/Vegasco.WebApi/Dockerfile new file mode 100644 index 0000000..5539aae --- /dev/null +++ b/src/Vegasco.WebApi/Dockerfile @@ -0,0 +1,30 @@ +# 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. + +# This stage is used when running from VS in fast mode (Default for Debug configuration) +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +USER app +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + + +# This stage is used to build the service project +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["Vegasco.Api/Vegasco.Api.csproj", "Vegasco.Api/"] +RUN dotnet restore "./Vegasco.Api/Vegasco.Api.csproj" +COPY . . +WORKDIR "/src/Vegasco.Api" +RUN dotnet build "./Vegasco.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build + +# This stage is used to publish the service project to be copied to the final stage +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./Vegasco.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration) +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Vegasco.Api.dll"] \ No newline at end of file diff --git a/src/Vegasco.WebApi/Program.cs b/src/Vegasco.WebApi/Program.cs new file mode 100644 index 0000000..bb04eb2 --- /dev/null +++ b/src/Vegasco.WebApi/Program.cs @@ -0,0 +1,44 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +var summaries = new[] +{ + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" +}; + +app.MapGet("/weatherforecast", () => +{ + var forecast = Enumerable.Range(1, 5).Select(index => + new WeatherForecast + ( + DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + Random.Shared.Next(-20, 55), + summaries[Random.Shared.Next(summaries.Length)] + )) + .ToArray(); + return forecast; +}) +.WithName("GetWeatherForecast") +.WithOpenApi(); + +app.Run(); + +internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) +{ + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); +} diff --git a/src/Vegasco.WebApi/Properties/launchSettings.json b/src/Vegasco.WebApi/Properties/launchSettings.json new file mode 100644 index 0000000..53f242a --- /dev/null +++ b/src/Vegasco.WebApi/Properties/launchSettings.json @@ -0,0 +1,52 @@ +{ + "profiles": { + "http": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5236" + }, + "https": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:7226;http://localhost:5236" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Container (Dockerfile)": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "environmentVariables": { + "ASPNETCORE_HTTPS_PORTS": "8081", + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true, + "useSSL": true + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:40988", + "sslPort": 44347 + } + } +} \ No newline at end of file diff --git a/src/Vegasco.WebApi/Vegasco.WebApi.csproj b/src/Vegasco.WebApi/Vegasco.WebApi.csproj new file mode 100644 index 0000000..277155c --- /dev/null +++ b/src/Vegasco.WebApi/Vegasco.WebApi.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + 2855ad97-67f4-455a-81af-69c212566ff2 + Linux + + + + + + + + + diff --git a/src/Vegasco.WebApi/Vegasco.WebApi.http b/src/Vegasco.WebApi/Vegasco.WebApi.http new file mode 100644 index 0000000..c318cc8 --- /dev/null +++ b/src/Vegasco.WebApi/Vegasco.WebApi.http @@ -0,0 +1,6 @@ +@Vegasco.Api_HostAddress = http://localhost:5236 + +GET {{Vegasco.Api_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/src/Vegasco.WebApi/appsettings.Development.json b/src/Vegasco.WebApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/src/Vegasco.WebApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/Vegasco.WebApi/appsettings.json b/src/Vegasco.WebApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/src/Vegasco.WebApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}