From bb42488bb64b854a8d71a4c77495fc0f852a9822 Mon Sep 17 00:00:00 2001 From: elotoja Date: Tue, 26 Dec 2023 01:17:42 +0100 Subject: [PATCH] Move to Dockerfile --- .dockerignore | 30 +++++++++++++++++++ .github/workflows/publish.yml | 15 ++++------ Dockerfile | 27 +++++++++++++++++ appsettings.Production.json | 13 ++++++++ docker-compose.yml | 4 +-- src/Quizer.Api/Quizer.Api.csproj | 7 ----- .../IValidatorAssemblyMarker.cs | 6 ---- .../Quizer.Validation.csproj | 13 -------- 8 files changed, 78 insertions(+), 37 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 appsettings.Production.json delete mode 100644 src/Quizer.Validation/IValidatorAssemblyMarker.cs delete mode 100644 src/Quizer.Validation/Quizer.Validation.csproj diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fe1152b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,30 @@ +**/.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 +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ec58e8f..95abfa8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,18 +18,15 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: '8.x' - - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - - name: Publish and push the container image - run: | - dotnet publish --os linux --arch x64 -p:PublishProfile=DefaultContainer -c Release \ No newline at end of file + + - name: Build the Docker image + run: docker build -t ghcr.io/${{ github.repository_owner }}/${{ github.repository_name }}:latest . + + - name: Push the container image + run: docker push ghcr.io/${{ github.repository_owner }}/${{ github.repository_name }}:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..174fdad --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +USER app +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["src/Quizer.Api/Quizer.Api.csproj", "./src/Quizer.Api/"] +COPY ["src/Quizer.Contracts/Quizer.Contracts.csproj", "./src/Quizer.Contracts/"] +COPY ["src/Quizer.Application/Quizer.Application.csproj", "./src/Quizer.Application/"] +COPY ["src/Quizer.Domain/Quizer.Domain.csproj", "./src/Quizer.Domain/"] +COPY ["src/Quizer.Infrastructure/Quizer.Infrastructure.csproj", "./src/Quizer.Infrastructure/"] +RUN dotnet restore "./src/Quizer.Api/Quizer.Api.csproj" +COPY . . +WORKDIR "/src/Quizer.Api" +RUN dotnet build "./Quizer.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./Quizer.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Quizer.Api.dll"] \ No newline at end of file diff --git a/appsettings.Production.json b/appsettings.Production.json new file mode 100644 index 0000000..6028276 --- /dev/null +++ b/appsettings.Production.json @@ -0,0 +1,13 @@ +{ + "JwtSettings": { + "Secret": "", + "Issuer": "quizer.elotoja.com", + "Audience": "quizer.elotoja.com" + }, + "Swagger": { + "Enabled": true + }, + "ConnectionStrings": { + "DefaultConnection": "" + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e4cbd6f..86cb76c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,5 +4,5 @@ services: image: ghcr.io/quizer-app/quizer:latest container_name: quizer volumes: - - ./appsettings.json:/home/runner/work/Quizer/Quizer/src/Quizer.Api/appsettings.Production.json - restart: unless-stopped + - ./appsettings.json:/app/src/Quizer.Api/appsettings.Production.json + restart: unless-stopped \ No newline at end of file diff --git a/src/Quizer.Api/Quizer.Api.csproj b/src/Quizer.Api/Quizer.Api.csproj index 1224351..83b796e 100644 --- a/src/Quizer.Api/Quizer.Api.csproj +++ b/src/Quizer.Api/Quizer.Api.csproj @@ -6,15 +6,8 @@ enable true d5aba78c-3529-4cb4-8caf-891dfecd83de - latest - ghcr.io - quizer-app/quizer - - - - diff --git a/src/Quizer.Validation/IValidatorAssemblyMarker.cs b/src/Quizer.Validation/IValidatorAssemblyMarker.cs deleted file mode 100644 index 644a1ca..0000000 --- a/src/Quizer.Validation/IValidatorAssemblyMarker.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Quizer.Validation -{ - public interface IValidatorAssemblyMarker - { - } -} diff --git a/src/Quizer.Validation/Quizer.Validation.csproj b/src/Quizer.Validation/Quizer.Validation.csproj deleted file mode 100644 index 37e2cd5..0000000 --- a/src/Quizer.Validation/Quizer.Validation.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - -