From be44fb4b4bc17e1dfabfa827943778859361aab0 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 13 Aug 2023 16:38:56 +0100 Subject: [PATCH] chore: add per-project Dockerfile --- OliverBooth.Blog/Dockerfile | 20 ++++++++++++++++++++ OliverBooth.sln | 3 +-- Dockerfile => OliverBooth/Dockerfile | 4 ++-- docker-compose.yml | 26 ++++++++++++-------------- 4 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 OliverBooth.Blog/Dockerfile rename Dockerfile => OliverBooth/Dockerfile (80%) diff --git a/OliverBooth.Blog/Dockerfile b/OliverBooth.Blog/Dockerfile new file mode 100644 index 0000000..ae04ebe --- /dev/null +++ b/OliverBooth.Blog/Dockerfile @@ -0,0 +1,20 @@ +FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +WORKDIR /src +COPY ["OliverBooth.Blog/OliverBooth.Blog.csproj", "OliverBooth.Blog/"] +RUN dotnet restore "OliverBooth.Blog/OliverBooth.Blog.csproj" +COPY . . +WORKDIR "/src/OliverBooth.Blog" +RUN dotnet build "OliverBooth.Blog.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "OliverBooth.Blog.csproj" -c Release -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "OliverBooth.Blog.dll"] diff --git a/OliverBooth.sln b/OliverBooth.sln index b661696..b61ab0e 100644 --- a/OliverBooth.sln +++ b/OliverBooth.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OliverBooth", "OliverBooth\OliverBooth.csproj", "{A58A6FA3-480C-400B-822A-3786741BF39C}" EndProject @@ -11,7 +11,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .dockerignore = .dockerignore docker-compose.yml = docker-compose.yml global.json = global.json - Dockerfile = Dockerfile EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8A323E64-E41E-4780-99FD-17BF58961FB5}" diff --git a/Dockerfile b/OliverBooth/Dockerfile similarity index 80% rename from Dockerfile rename to OliverBooth/Dockerfile index 2fe3fcf..9ccbb31 100644 --- a/Dockerfile +++ b/OliverBooth/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base WORKDIR /app EXPOSE 80 EXPOSE 443 @@ -6,7 +6,7 @@ EXPOSE 443 FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build WORKDIR /src COPY ["OliverBooth/OliverBooth.csproj", "OliverBooth/"] -RUN dotnet restore "oliverbooth.dev/oliverbooth.dev.csproj" +RUN dotnet restore "OliverBooth/OliverBooth.csproj" COPY . . WORKDIR "/src/OliverBooth" RUN dotnet build "OliverBooth.csproj" -c Release -o /app/build diff --git a/docker-compose.yml b/docker-compose.yml index 05970bf..2cb053f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,9 @@ services: oliverbooth: container_name: oliverbooth.dev pull_policy: build - build: . + build: + context: . + dockerfile: OliverBooth/Dockerfile volumes: - type: bind source: /var/log/oliverbooth/site @@ -11,27 +13,23 @@ services: - type: bind source: /etc/oliverbooth/site target: /app/data + ports: + - "2845:2845" restart: always - environment: - - MYSQL_HOST=${MYSQL_HOST} - - MYSQL_DATABASE=${MYSQL_DATABASE} - - MYSQL_USER=${MYSQL_USER} - - MYSQL_PASSWORD=${MYSQL_PASSWORD} oliverbooth-blog: container_name: blog.oliverbooth.dev pull_policy: build - build: . + build: + context: . + dockerfile: OliverBooth/Dockerfile volumes: - type: bind - source: /var/log/oliverbooth-blog/site + source: /var/log/oliverbooth/blog target: /app/logs - type: bind - source: /etc/oliverbooth-blog/site + source: /etc/oliverbooth/blog target: /app/data + ports: + - "2846:2846" restart: always - environment: - - MYSQL_HOST=${MYSQL_HOST} - - MYSQL_DATABASE=${MYSQL_DATABASE} - - MYSQL_USER=${MYSQL_USER} - - MYSQL_PASSWORD=${MYSQL_PASSWORD}