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/AwesomeMicroservices.WebApi/AwesomeMicroservices.WebApi.csproj b/AwesomeMicroservices.WebApi/AwesomeMicroservices.WebApi.csproj new file mode 100644 index 0000000..9a277f8 --- /dev/null +++ b/AwesomeMicroservices.WebApi/AwesomeMicroservices.WebApi.csproj @@ -0,0 +1,16 @@ + + + + net8.0 + enable + enable + 12ea8899-f963-4978-9139-09d18ab72fdc + Linux + + + + + + + + diff --git a/AwesomeMicroservices.WebApi/AwesomeMicroservices.WebApi.http b/AwesomeMicroservices.WebApi/AwesomeMicroservices.WebApi.http new file mode 100644 index 0000000..353cd70 --- /dev/null +++ b/AwesomeMicroservices.WebApi/AwesomeMicroservices.WebApi.http @@ -0,0 +1,6 @@ +@AwesomeMicroservices.WebApi_HostAddress = http://localhost:5007 + +GET {{AwesomeMicroservices.WebApi_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/AwesomeMicroservices.WebApi/Controllers/WeatherForecastController.cs b/AwesomeMicroservices.WebApi/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..88afa93 --- /dev/null +++ b/AwesomeMicroservices.WebApi/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace AwesomeMicroservices.WebApi.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/AwesomeMicroservices.WebApi/Dockerfile b/AwesomeMicroservices.WebApi/Dockerfile new file mode 100644 index 0000000..30a597d --- /dev/null +++ b/AwesomeMicroservices.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_UID +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 ["AwesomeMicroservices.WebApi/AwesomeMicroservices.WebApi.csproj", "AwesomeMicroservices.WebApi/"] +RUN dotnet restore "./AwesomeMicroservices.WebApi/AwesomeMicroservices.WebApi.csproj" +COPY . . +WORKDIR "/src/AwesomeMicroservices.WebApi" +RUN dotnet build "./AwesomeMicroservices.WebApi.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 "./AwesomeMicroservices.WebApi.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", "AwesomeMicroservices.WebApi.dll"] \ No newline at end of file diff --git a/AwesomeMicroservices.WebApi/Program.cs b/AwesomeMicroservices.WebApi/Program.cs new file mode 100644 index 0000000..1452165 --- /dev/null +++ b/AwesomeMicroservices.WebApi/Program.cs @@ -0,0 +1,36 @@ + +namespace AwesomeMicroservices.WebApi +{ + public class Program + { + public static void Main(string[] args) + { + 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/AwesomeMicroservices.WebApi/Properties/launchSettings.json b/AwesomeMicroservices.WebApi/Properties/launchSettings.json new file mode 100644 index 0000000..c260a02 --- /dev/null +++ b/AwesomeMicroservices.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:5007" + }, + "https": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:7135;http://localhost:5007" + }, + "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:49517", + "sslPort": 44336 + } + } +} \ No newline at end of file diff --git a/AwesomeMicroservices.WebApi/WeatherForecast.cs b/AwesomeMicroservices.WebApi/WeatherForecast.cs new file mode 100644 index 0000000..329a85c --- /dev/null +++ b/AwesomeMicroservices.WebApi/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace AwesomeMicroservices.WebApi +{ + 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/AwesomeMicroservices.WebApi/appsettings.Development.json b/AwesomeMicroservices.WebApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/AwesomeMicroservices.WebApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/AwesomeMicroservices.WebApi/appsettings.json b/AwesomeMicroservices.WebApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/AwesomeMicroservices.WebApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/AwesomeMicroservicesSolution.sln b/AwesomeMicroservicesSolution.sln new file mode 100644 index 0000000..7c154a0 --- /dev/null +++ b/AwesomeMicroservicesSolution.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35527.113 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AwesomeMicroservices.WebApi", "AwesomeMicroservices.WebApi\AwesomeMicroservices.WebApi.csproj", "{B0EDD9B6-A3D1-4DCC-B9B3-7000997551BA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B0EDD9B6-A3D1-4DCC-B9B3-7000997551BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0EDD9B6-A3D1-4DCC-B9B3-7000997551BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0EDD9B6-A3D1-4DCC-B9B3-7000997551BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0EDD9B6-A3D1-4DCC-B9B3-7000997551BA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal