From 264b6319cbfa0a302dde0133b82b7aed609247e9 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Sun, 9 Feb 2025 15:21:13 -0700 Subject: [PATCH] Linux AOT and Container --- .vscode/tasks.json | 100 ++++++++++++++++++++++++++++++++++++++ Dockerfile | 25 ++++++++++ File-Folder-Helper.csproj | 2 +- docker-compose.yaml | 6 +++ global.json | 6 +++ 5 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yaml create mode 100644 global.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 6b48f02..89a335f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -58,12 +58,95 @@ "type": "process", "args": [ "build", + "-r", + "win-x64", "${workspaceFolder}/File-Folder-Helper.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile" }, + { + "label": "build Linux", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "-r", + "linux-x64", + "${workspaceFolder}/File-Folder-Helper.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "podmanLogin", + "command": "podman", + "type": "process", + "args": [ + "login", + "gitea.phares.duckdns.org:443" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "podmanBuild", + "command": "podman", + "type": "process", + "args": [ + "build", + "-t", + "file-folder-helper", + "." + ], + "problemMatcher": "$msCompile" + }, + { + "label": "podmanImageList", + "command": "podman", + "type": "process", + "args": [ + "image", + "ls" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "podmanRun", + "command": "podman", + "type": "process", + "args": [ + "run", + "-p", + "5001:5001", + "--name", + "file-folder-helper-001", + "a3de856b5731" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "podmanTag", + "command": "podman", + "type": "process", + "args": [ + "tag", + "a3de856b5731", + "gitea.phares.duckdns.org:443/phares3757/file-folder-helper:latest" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "podmanPush", + "command": "podman", + "type": "process", + "args": [ + "push", + "gitea.phares.duckdns.org:443/phares3757/file-folder-helper:latest" + ], + "problemMatcher": "$msCompile" + }, { "label": "publish", "command": "dotnet", @@ -105,6 +188,23 @@ ], "problemMatcher": "$msCompile" }, + { + "label": "Publish AOT Linux", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "-r", + "linux-x64", + "-c", + "Release", + "-p:PublishAot=true", + "${workspaceFolder}/File-Folder-Helper.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, { "label": "File-Folder-Helper AOT s J Verdaccio", "type": "shell", diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d298d19 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# Stage 1: Build Stage +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build + +WORKDIR /src + +# restore +COPY ["src/File-Folder-Helper/File-Folder-Helper.csproj", "File-Folder-Helper/"] +RUN dotnet restore 'File-Folder-Helper/File-Folder-Helper.csproj' + +# build +COPY ["src/File-Folder-Helper", "File-Folder-Helper/"] +WORKDIR /src/File-Folder-Helper +RUN dotnet build 'File-Folder-Helper.csproj' -c Release -o /app/build + +# Stage 2: Publish Stage +FROM build AS publish +RUN dotnet publish 'File-Folder-Helper.csproj' -c Release -o /app/publish + +# Stage 3: Run Stage +FROM mcr.microsoft.com/dotnet/aspnet:8.0 +ENV ASPNETCORE_HTTP_PORTS=5001 +EXPOSE 5001 +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT [ "dotnet", "File-Folder-Helper.dll" ] diff --git a/File-Folder-Helper.csproj b/File-Folder-Helper.csproj index fbc58fa..55821b4 100644 --- a/File-Folder-Helper.csproj +++ b/File-Folder-Helper.csproj @@ -4,7 +4,7 @@ Exe enable net8.0 - win-x64 + win-x64;linux-x64 true 8da397d4-13ec-4576-9722-3c79cad25563 eb9e8f58-fcb5-45bb-9d4d-54f064c485b1 diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..90f1d21 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,6 @@ +services: + webapp: + container_name: file-folder-helper + build: + context: . + dockerfile: Dockerfile \ No newline at end of file diff --git a/global.json b/global.json new file mode 100644 index 0000000..d606cbd --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "rollForward": "latestMinor", + "version": "8.0.112" + } +} \ No newline at end of file