diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cd967fc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.idea +**/*.*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 \ No newline at end of file diff --git a/HoolIt.sln b/HoolIt.sln new file mode 100644 index 0000000..fbe2bd1 --- /dev/null +++ b/HoolIt.sln @@ -0,0 +1,21 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HoolIt", "HoolIt\HoolIt.csproj", "{E3812095-9B4D-4A38-B33C-84214FBB7620}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5DD66A23-C25C-4F51-82D3-95A4AC05768B}" + ProjectSection(SolutionItems) = preProject + compose.yaml = compose.yaml + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E3812095-9B4D-4A38-B33C-84214FBB7620}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E3812095-9B4D-4A38-B33C-84214FBB7620}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E3812095-9B4D-4A38-B33C-84214FBB7620}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E3812095-9B4D-4A38-B33C-84214FBB7620}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/HoolIt/Dockerfile b/HoolIt/Dockerfile new file mode 100644 index 0000000..8365ff2 --- /dev/null +++ b/HoolIt/Dockerfile @@ -0,0 +1,23 @@ +FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base +USER $APP_UID +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["HoolIt/HoolIt.csproj", "HoolIt/"] +RUN dotnet restore "HoolIt/HoolIt.csproj" +COPY . . +WORKDIR "/src/HoolIt" +RUN dotnet build "HoolIt.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "HoolIt.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "HoolIt.dll"] diff --git a/HoolIt/HoolIt.csproj b/HoolIt/HoolIt.csproj new file mode 100644 index 0000000..91a59c7 --- /dev/null +++ b/HoolIt/HoolIt.csproj @@ -0,0 +1,18 @@ + + + + net10.0 + enable + enable + true + true + Linux + + + + + .dockerignore + + + + diff --git a/HoolIt/HoolIt.http b/HoolIt/HoolIt.http new file mode 100644 index 0000000..267b862 --- /dev/null +++ b/HoolIt/HoolIt.http @@ -0,0 +1,11 @@ +@HoolIt_HostAddress = http://localhost:5246 + +GET {{HoolIt_HostAddress}}/todos/ +Accept: application/json + +### + +GET {{HoolIt_HostAddress}}/todos/1 +Accept: application/json + +### diff --git a/HoolIt/Program.cs b/HoolIt/Program.cs new file mode 100644 index 0000000..26fa84d --- /dev/null +++ b/HoolIt/Program.cs @@ -0,0 +1,35 @@ +using System.Text.Json.Serialization; + +var builder = WebApplication.CreateSlimBuilder(args); + +builder.Services.ConfigureHttpJsonOptions(options => +{ + options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default); +}); + +var app = builder.Build(); + +var sampleTodos = new Todo[] +{ + new(1, "Walk the dog"), + new(2, "Do the dishes", DateOnly.FromDateTime(DateTime.Now)), + new(3, "Do the laundry", DateOnly.FromDateTime(DateTime.Now.AddDays(1))), + new(4, "Clean the bathroom"), + new(5, "Clean the car", DateOnly.FromDateTime(DateTime.Now.AddDays(2))) +}; + +var todosApi = app.MapGroup("/todos"); +todosApi.MapGet("/", () => sampleTodos); +todosApi.MapGet("/{id}", (int id) => + sampleTodos.FirstOrDefault(a => a.Id == id) is { } todo + ? Results.Ok(todo) + : Results.NotFound()); + +app.Run(); + +public record Todo(int Id, string? Title, DateOnly? DueBy = null, bool IsComplete = false); + +[JsonSerializable(typeof(Todo[]))] +internal partial class AppJsonSerializerContext : JsonSerializerContext +{ +} \ No newline at end of file diff --git a/HoolIt/Properties/launchSettings.json b/HoolIt/Properties/launchSettings.json new file mode 100644 index 0000000..fc0b99d --- /dev/null +++ b/HoolIt/Properties/launchSettings.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "todos", + "applicationUrl": "http://localhost:5246", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/HoolIt/appsettings.Development.json b/HoolIt/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/HoolIt/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..3f5cc58 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,6 @@ +services: + hoolit: + image: hoolit + build: + context: . + dockerfile: HoolIt/Dockerfile