From 5a309b431ea327196e864f5d103d08778f8d26c2 Mon Sep 17 00:00:00 2001 From: Matej Hires Date: Tue, 19 Dec 2023 20:22:00 +0100 Subject: [PATCH 1/7] Refactored Dockerfile --- Dockerfile | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1a3dbe5..996c81b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,12 @@ -FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base -WORKDIR /app -EXPOSE 80 +EXPOSE 80 EXPOSE 443 -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /src -COPY ["AutomatedTestingApp/AutomatedTestingApp/AutomatedTestingApp.csproj", "AutomatedTestingApp/"] -RUN dotnet restore "AutomatedTestingApp/AutomatedTestingApp.csproj" -COPY . . -WORKDIR "/src/AutomatedTestingApp" +FROM mcr.microsoft.com/dotnet/sdk:7.0 AS base -FROM build AS publish -RUN dotnet publish "AutomatedTestingApp.csproj" -c Release -o /app/publish /p:UseAppHost=false +ARG APP_PATH -FROM base AS final WORKDIR /app -COPY --from=publish /app/publish . + +COPY ${APP_PATH} ./ + ENTRYPOINT ["dotnet", "AutomatedTestingApp.dll"] From 4d521c722e82b7b05718569cc36d308091c4fd1c Mon Sep 17 00:00:00 2001 From: Matej Hires Date: Tue, 19 Dec 2023 20:22:15 +0100 Subject: [PATCH 2/7] Added Views into output directory --- .../AutomatedTestingApp.csproj | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/AutomatedTestingApp/AutomatedTestingApp/AutomatedTestingApp.csproj b/AutomatedTestingApp/AutomatedTestingApp/AutomatedTestingApp.csproj index 447a194..8924e66 100644 --- a/AutomatedTestingApp/AutomatedTestingApp/AutomatedTestingApp.csproj +++ b/AutomatedTestingApp/AutomatedTestingApp/AutomatedTestingApp.csproj @@ -11,6 +11,30 @@ .dockerignore + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + @@ -35,11 +59,4 @@ - - - <_ContentIncludedByDefault Remove="Views\Account\Index.cshtml" /> - <_ContentIncludedByDefault Remove="Views\Articles\Index.cshtml" /> - - - From 4dcc9085bd29a389dd29fa110a16cc94ff2cb1d7 Mon Sep 17 00:00:00 2001 From: Matej Hires Date: Tue, 19 Dec 2023 20:22:30 +0100 Subject: [PATCH 3/7] Added build-docker.sh --- build-docker.sh | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 build-docker.sh diff --git a/build-docker.sh b/build-docker.sh new file mode 100644 index 0000000..dfbb371 --- /dev/null +++ b/build-docker.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -ex + +dotnet publish AutomatedTestingApp/AutomatedTestingApp/AutomatedTestingApp.csproj -c Release -o out /p:UseAppHost=false + +docker build --build-arg APP_PATH=./out -t hiresm/czechitas:test . \ No newline at end of file From dee2db189c3672ad739554f1146599fd6d265dfe Mon Sep 17 00:00:00 2001 From: Matej Hires Date: Tue, 19 Dec 2023 21:23:02 +0100 Subject: [PATCH 4/7] Expose ports --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 996c81b..e7b1f59 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ -EXPOSE 80 -EXPOSE 443 +FROM mcr.microsoft.com/dotnet/sdk:7.0 AS base -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS base +EXPOSE 80 +EXPOSE 443 ARG APP_PATH From ba98154bf7a5d6731b15eebda31fbbd6eda2d4b3 Mon Sep 17 00:00:00 2001 From: Matej Hires Date: Tue, 19 Dec 2023 21:23:15 +0100 Subject: [PATCH 5/7] Copy Views into output directory --- .../AutomatedTestingApp.csproj | 54 +++++++------------ 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/AutomatedTestingApp/AutomatedTestingApp/AutomatedTestingApp.csproj b/AutomatedTestingApp/AutomatedTestingApp/AutomatedTestingApp.csproj index 8924e66..da9d62a 100644 --- a/AutomatedTestingApp/AutomatedTestingApp/AutomatedTestingApp.csproj +++ b/AutomatedTestingApp/AutomatedTestingApp/AutomatedTestingApp.csproj @@ -7,35 +7,7 @@ Linux - - - .dockerignore - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - + @@ -45,12 +17,15 @@ - - - - + + Always + + + Always + + @@ -58,5 +33,16 @@ - + + + + + + + + + + + + From 6000d99561b20222a7cc3b9bfa318cf0e23a4132 Mon Sep 17 00:00:00 2001 From: Matej Hires Date: Tue, 19 Dec 2023 21:47:06 +0100 Subject: [PATCH 6/7] Changed base image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e7b1f59..7ab9c1e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base EXPOSE 80 EXPOSE 443 From d14594b5a013ca7dc308af32c7b4b563dde500a5 Mon Sep 17 00:00:00 2001 From: Matej Hires Date: Tue, 2 Jan 2024 18:04:11 +0100 Subject: [PATCH 7/7] Added publish into docker-image.yml --- .github/workflows/docker-image.yml | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index a3b5606..9d3eccf 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -13,7 +13,26 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - + + - name: Setup .NET Core + uses: actions/setup-dotnet@v3 + with: + global-json: 'global.json' + + - name: Install dependencies + run: dotnet restore + working-directory: ./AutomatedTestingApp + + - name: Build + run: | + dotnet build ${{ env.PROJECT_NAME }} --configuration Release --no-restore + working-directory: ${{ env.PROJECT_PATH }} + + - name: Publish + run: | + dotnet publish ${{ env.PROJECT_NAME }} --no-build --no-restore --configuration Release --output ./publish + working-directory: ${{ env.PROJECT_PATH }} + - name: Log in to Docker Hub uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a with: @@ -26,4 +45,6 @@ jobs: context: . file: ./Dockerfile push: true - tags: hiresm/czechitas:latest \ No newline at end of file + tags: hiresm/czechitas:latest + args: | + --build-arg APP_PATH=./publish \ No newline at end of file