diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3dbbcf3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..19a471c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,39 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/src/NorthwindStore.Tests.UnitTests/bin/Debug/net6.0/NorthwindStore.Tests.UnitTests.dll", + "args": [], + "cwd": "${workspaceFolder}/src/NorthwindStore.Tests.UnitTests", + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + }, + { + "name": "Docker .NET Launch", + "type": "docker", + "request": "launch", + "preLaunchTask": "docker-run: debug", + "netCore": { + "appProject": "${workspaceFolder}/src/NorthwindStore.Tests.UnitTests/NorthwindStore.Tests.UnitTests.csproj" + } + }, + { + "name": "Docker .NET Launch release", + "type": "docker", + "request": "launch", + "preLaunchTask": "docker-run: release", + "netCore": { + "appProject": "${workspaceFolder}/NorthwindStore.App/NorthwindStore.App.csproj" + } + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..63b4a23 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,112 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/src/NorthwindStore.sln", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary;ForceNoAlign" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/src/NorthwindStore.sln", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary;ForceNoAlign" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/src/NorthwindStore.sln" + ], + "problemMatcher": "$msCompile" + }, + { + "type": "docker-build", + "label": "docker-build: debug", + "dependsOn": [ + "build" + ], + "dockerBuild": { + "tag": "robotdreamskubernetesprivatevt:dev", + "target": "base", + "dockerfile": "${workspaceFolder}/src/NorthwindStore.Tests.UnitTests/Dockerfile", + "context": "${workspaceFolder}", + "pull": true + }, + "netCore": { + "appProject": "${workspaceFolder}/src/NorthwindStore.Tests.UnitTests/NorthwindStore.Tests.UnitTests.csproj" + } + }, + { + "type": "docker-build", + "label": "docker-build: release", + "dependsOn": [ + "build" + ], + "dockerBuild": { + "tag": "robotdreamskubernetesprivatevt:latest", + "dockerfile": "${workspaceFolder}/src/NorthwindStore.Tests.UnitTests/Dockerfile", + "context": "${workspaceFolder}", + "platform": { + "os": "linux", + "architecture": "amd64" + }, + "pull": true + }, + "netCore": { + "appProject": "${workspaceFolder}/src/NorthwindStore.Tests.UnitTests/NorthwindStore.Tests.UnitTests.csproj" + } + }, + { + "type": "docker-run", + "label": "docker-run: debug", + "dependsOn": [ + "docker-build: debug" + ], + "dockerRun": { + "env": { + "ConnectionStrings__DB": "Data Source=tcp:northwind-db,1433; Initial Catalog=Northwind; User ID=sa; Password=DevPass_1" + }, + "network": "northwind-network" + }, + "netCore": { + "appProject": "${workspaceFolder}/src/NorthwindStore.Tests.UnitTests/NorthwindStore.Tests.UnitTests.csproj", + "enableDebugging": true, + "configureSsl": false + } + }, + { + "type": "docker-run", + "label": "docker-run: release", + "dependsOn": [ + "docker-build: release" + ], + "dockerRun": { + "env": { + "ConnectionStrings__DB": "Data Source=tcp:northwind-db,1433; Initial Catalog=Northwind; User ID=sa; Password=DevPass_1" + }, + "network": "northwind-network" + }, + "netCore": { + "appProject": "${workspaceFolder}/src/NorthwindStore.Tests.UnitTests/NorthwindStore.Tests.UnitTests.csproj" + } + } + ] +} \ No newline at end of file diff --git a/ci/docker-compose.ci.yml b/ci/docker-compose.ci.yml new file mode 100644 index 0000000..2f9b78a --- /dev/null +++ b/ci/docker-compose.ci.yml @@ -0,0 +1,19 @@ +version: '3.4' + +services: + northwindstore.app: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=http://+:80 + - ConnectionStrings__DB=Data Source=tcp:northwindstore.db,1433; Initial Catalog=Northwind; User ID=sa; Password=DevPass_1 + ports: + - "80" + networks: + - northwindstore-dev + northwindstore.db: + networks: + - northwindstore-dev + +networks: + northwindstore-dev: + name: northwindstore-dev diff --git a/ci/pipelines/build.yml b/ci/pipelines/build.yml new file mode 100644 index 0000000..9964508 --- /dev/null +++ b/ci/pipelines/build.yml @@ -0,0 +1,48 @@ +# Starter pipeline +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +trigger: +- main + +pool: + vmImage: ubuntu-latest + +steps: +- task: DockerCompose@1 + inputs: + containerregistrytype: "Azure Container Registry" + dockerComposeFile: src/docker-compose.yml + additionalDockerComposeFiles: ../ci/docker-compose.ci.yml + projectName: "northwindstore" + action: "Run a Docker Compose command" + dockerComposeCommand: "up" + arguments: --build --force-recreate -d +- task: Docker@2 + displayName: Build Unit tests + inputs: + repository: 'northwindstoretestsunittests' + command: 'build' + Dockerfile: 'src/NorthwindStore.Tests.UnitTests/Dockerfile' + buildContext: 'src' +- task: Docker@2 + displayName: Run Unit tests + inputs: + command: 'run' + arguments: '--rm northwindstoretestsunittests:$(Build.BuildId)' +- task: Docker@2 + displayName: Build Integration tests + inputs: + repository: 'northwindstoretestsintegrationtest' + command: 'build' + Dockerfile: 'src/NorthwindStore.Tests.IntegrationTests/Dockerfile' + buildContext: 'src' +- task: Docker@2 + displayName: Run Integration tests + inputs: + command: 'run' + arguments: '--rm -e "ConnectionStrings__DB=Data Source=tcp:northwindstore.db,1433; Initial Catalog=Northwind; User ID=sa; Password=DevPass_1" --network northwindstore-dev northwindstoretestsintegrationtests' + + + diff --git a/src/NorthwindStore.Tests.IntegrationTests/Dockerfile b/src/NorthwindStore.Tests.IntegrationTests/Dockerfile index a7e3a70..7cb4da9 100644 --- a/src/NorthwindStore.Tests.IntegrationTests/Dockerfile +++ b/src/NorthwindStore.Tests.IntegrationTests/Dockerfile @@ -1,12 +1,26 @@ +main +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build +======= # 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. # This stage is used to build the service project FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +main WORKDIR /src COPY ["packages/", "packages/"] COPY ["nuget.config", "."] COPY ["NorthwindStore.Tests.IntegrationTests/NorthwindStore.Tests.IntegrationTests.csproj", "NorthwindStore.Tests.IntegrationTests/"] +main +COPY ["NorthwindStore.DAL/NorthwindStore.DAL.csproj", "NorthwindStore.DAL/"] +COPY ["NorthwindStore.BL/NorthwindStore.BL.csproj", "NorthwindStore.BL/"] +RUN dotnet restore "NorthwindStore.Tests.IntegrationTests/NorthwindStore.Tests.IntegrationTests.csproj" +COPY . . +WORKDIR "/src/NorthwindStore.Tests.IntegrationTests" +RUN dotnet build "NorthwindStore.Tests.IntegrationTests.csproj" + +ENTRYPOINT ["dotnet", "test", "NorthwindStore.Tests.IntegrationTests.csproj"] +======= COPY ["NorthwindStore.App/NorthwindStore.App.csproj", "NorthwindStore.App/"] COPY ["NorthwindStore.BL/NorthwindStore.BL.csproj", "NorthwindStore.BL/"] COPY ["NorthwindStore.DAL/NorthwindStore.DAL.csproj", "NorthwindStore.DAL/"] @@ -15,4 +29,5 @@ COPY . . WORKDIR "/src/NorthwindStore.Tests.IntegrationTests" RUN dotnet build "./NorthwindStore.Tests.IntegrationTests.csproj" -ENTRYPOINT ["dotnet", "test", "NorthwindStore.Tests.IntegrationTests.csproj"] \ No newline at end of file +ENTRYPOINT ["dotnet", "test", "NorthwindStore.Tests.IntegrationTests.csproj"] +main diff --git a/src/NorthwindStore.Tests.UnitTests/Dockerfile b/src/NorthwindStore.Tests.UnitTests/Dockerfile index 0241d77..3d6191f 100644 --- a/src/NorthwindStore.Tests.UnitTests/Dockerfile +++ b/src/NorthwindStore.Tests.UnitTests/Dockerfile @@ -1,11 +1,26 @@ +main +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS build +ARG configuration=Release +======= # 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. # This stage is used to build the service project FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +main WORKDIR /src COPY ["packages/", "packages/"] COPY ["nuget.config", "."] COPY ["NorthwindStore.Tests.UnitTests/NorthwindStore.Tests.UnitTests.csproj", "NorthwindStore.Tests.UnitTests/"] +main +COPY ["NorthwindStore.DAL/NorthwindStore.DAL.csproj", "NorthwindStore.DAL/"] +COPY ["NorthwindStore.BL/NorthwindStore.BL.csproj", "NorthwindStore.BL/"] +RUN dotnet restore "NorthwindStore.Tests.UnitTests/NorthwindStore.Tests.UnitTests.csproj" +COPY . . +WORKDIR "/src/NorthwindStore.Tests.UnitTests" +RUN dotnet build "NorthwindStore.Tests.UnitTests.csproj" + +ENTRYPOINT ["dotnet", "test", "NorthwindStore.Tests.UnitTests.csproj"] +======= COPY ["NorthwindStore.BL/NorthwindStore.BL.csproj", "NorthwindStore.BL/"] COPY ["NorthwindStore.DAL/NorthwindStore.DAL.csproj", "NorthwindStore.DAL/"] RUN dotnet restore "./NorthwindStore.Tests.UnitTests/NorthwindStore.Tests.UnitTests.csproj" @@ -14,4 +29,5 @@ WORKDIR "/src/NorthwindStore.Tests.UnitTests" RUN dotnet build "./NorthwindStore.Tests.UnitTests.csproj" -ENTRYPOINT ["dotnet", "test", "NorthwindStore.Tests.UnitTests.csproj"] \ No newline at end of file +ENTRYPOINT ["dotnet", "test", "NorthwindStore.Tests.UnitTests.csproj"] +main