commit e8ec8f8e5cf861dc5b216011da7114e9b0c83072 Author: Fernando Araoz Date: Sat Jan 11 16:20:05 2025 -0500 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..98ff247 --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +[Bb]in/ +[Oo]bj/ + +.vs/ +.idea/ +*.user +*.userosscache +*.sln.docstates +*.suo + +*.DS_Store +Thumbs.db + +.idea/ +*.sln.iml +.idea/**/workspace.xml + +appsettings.*.json +!appsettings.json +!appsettings.Example.json + +*.dbmdl +*.jfm +*.pfx +*.publishsettings + +*.nupkg +**/packages/* +!**/packages/build/ +*.nuget.props +*.nuget.targets + +# build artifacts +out diff --git a/Controllers/WeatherForecastController.cs b/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..fd0dc44 --- /dev/null +++ b/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Trazo.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..08980e3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM mcr.microsoft.com/dotnet/sdk:9.0 + +WORKDIR /app + +# Set ASP.NET to actually listen on all interfaces, not just localhost +ENV ASPNETCORE_URLS=http://+:5266 +# Allow non-HTTPS because it's just development, who cares +ENV ASPNETCORE_ENVIRONMENT=Development + +ENTRYPOINT ["dotnet", "watch", "run", "--no-launch-profile"] diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 100644 index 0000000..abb5cb4 --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1,11 @@ +FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build +WORKDIR /app +COPY . . +RUN dotnet restore +RUN dotnet publish -c Release -o out + +FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine +WORKDIR /app +COPY --from=build /app/out . + +CMD ["./csharp"] diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..48863a6 --- /dev/null +++ b/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// 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(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..629bb5c --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:22703", + "sslPort": 44392 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5233", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7038;http://localhost:5233", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Trazo.csproj b/Trazo.csproj new file mode 100644 index 0000000..5419ef0 --- /dev/null +++ b/Trazo.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Trazo.http b/Trazo.http new file mode 100644 index 0000000..cde6654 --- /dev/null +++ b/Trazo.http @@ -0,0 +1,6 @@ +@Trazo_HostAddress = http://localhost:5233 + +GET {{Trazo_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/WeatherForecast.cs b/WeatherForecast.cs new file mode 100644 index 0000000..c251c71 --- /dev/null +++ b/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace Trazo; + +public class WeatherForecast +{ + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..bc04db4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,46 @@ +services: + aspnet-prison: + container_name: aspnet-prison + build: + context: . + dockerfile: Dockerfile + ports: + - "5266:5266" + volumes: + - ./:/app + networks: + - aspnet-network + + aspnet-postgres: + image: postgres:latest + container_name: aspnet-postgres + restart: always + environment: + POSTGRES_DB: postgres + POSTGRES_USER: root + POSTGRES_PASSWORD: root + PGDATA: /var/lib/postgresql/data + # ports: + # - '5432:5432' + networks: + - aspnet-network + + aspnet-pgadmin4: + image: elestio/pgadmin:latest + container_name: aspnet-pgadmin + restart: always + environment: + PGADMIN_DEFAULT_EMAIL: admin@admin.com + PGADMIN_DEFAULT_PASSWORD: admin + PGADMIN_LISTEN_PORT: 8080 + ports: + - "8080:8080" + volumes: + - ./servers.json:/pgadmin4/servers.json + networks: + - aspnet-network + +networks: + aspnet-network: + driver: bridge +