From 6d66b6532b2efd1979f5c47295dd8542405f06ab Mon Sep 17 00:00:00 2001 From: ShaoHua <3452651980.> Date: Fri, 28 Jun 2024 00:10:01 +0800 Subject: [PATCH] Supports running on docker --- .dockerignore | 25 ------------------------- Hua.DDNS/Dockerfile | 21 +++++++++++---------- Hua.DDNS/Hua.DDNS.csproj | 4 +--- buildImages.ps1 | 3 +++ 4 files changed, 15 insertions(+), 38 deletions(-) delete mode 100644 .dockerignore create mode 100644 buildImages.ps1 diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 3729ff0..0000000 --- a/.dockerignore +++ /dev/null @@ -1,25 +0,0 @@ -**/.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 \ No newline at end of file diff --git a/Hua.DDNS/Dockerfile b/Hua.DDNS/Dockerfile index 36de2aa..dd2f5f1 100644 --- a/Hua.DDNS/Dockerfile +++ b/Hua.DDNS/Dockerfile @@ -1,21 +1,22 @@ -#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. - -#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed. -#For more information, please see https://aka.ms/containercompat - -FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base +#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. +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS base +USER app WORKDIR /app +#EXPOSE 8080 +#EXPOSE 8081 -FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release WORKDIR /src COPY ["Hua.DDNS/Hua.DDNS.csproj", "Hua.DDNS/"] -RUN dotnet restore "Hua.DDNS/Hua.DDNS.csproj" +RUN dotnet restore "./Hua.DDNS/Hua.DDNS.csproj" COPY . . WORKDIR "/src/Hua.DDNS" -RUN dotnet build "Hua.DDNS.csproj" -c Release -o /app/build +RUN dotnet build "./Hua.DDNS.csproj" -c $BUILD_CONFIGURATION -o /app/build FROM build AS publish -RUN dotnet publish "Hua.DDNS.csproj" -c Release -o /app/publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./Hua.DDNS.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=true FROM base AS final WORKDIR /app diff --git a/Hua.DDNS/Hua.DDNS.csproj b/Hua.DDNS/Hua.DDNS.csproj index 67cafe1..c54ce7e 100644 --- a/Hua.DDNS/Hua.DDNS.csproj +++ b/Hua.DDNS/Hua.DDNS.csproj @@ -4,10 +4,8 @@ net8.0 enable enable - true dotnet-Hua.DDNS-C4DADDFF-6D5B-4BD5-AB11-02F07B517CAC - Windows - true + true diff --git a/buildImages.ps1 b/buildImages.ps1 new file mode 100644 index 0000000..0e9e0fc --- /dev/null +++ b/buildImages.ps1 @@ -0,0 +1,3 @@ +Set-ExecutionPolicy RemoteSigned -Scope CurrentUser +cd ./Hua.DDNS +docker build -t hua.ddns:latest -f Dockerfile .. \ No newline at end of file