Skip to content

Commit

Permalink
added docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Eyup GEVENIM committed Jan 7, 2020
1 parent 9b72b11 commit 7f54ca5
Show file tree
Hide file tree
Showing 20 changed files with 270 additions and 9 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.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
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
REGISTRY=blog-api
PLATFORM=linux
TAG=latest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/**/obj

/**/*.csproj.user

/tests-results
7 changes: 6 additions & 1 deletion Blog.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blog.API", "src\Presentatio
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{39D22109-1F01-4C47-A1A2-2084DB00881F}"
ProjectSection(SolutionItems) = preProject
.env = .env
docker-compose-tests.override.yml = docker-compose-tests.override.yml
docker-compose-tests.yml = docker-compose-tests.yml
docker-compose.override.yml = docker-compose.override.yml
docker-compose.yml = docker-compose.yml
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{696B9A5B-F3E5-4914-B019-E5343E17045E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blog.Services.Tests", "src\Tests\Blog.Services.Tests\Blog.Services.Tests.csproj", "{5B534BC0-57E6-4780-9B56-A5B9610F1D23}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blog.API.IntegrationTests", "src\Tests\Blog.API.IntegrationTests\Blog.API.IntegrationTests.csproj", "{9EDFA350-E6BD-4015-8BAB-EB77B63AEC14}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blog.API.IntegrationTests", "src\Tests\Blog.API.IntegrationTests\Blog.API.IntegrationTests.csproj", "{9EDFA350-E6BD-4015-8BAB-EB77B63AEC14}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
36 changes: 36 additions & 0 deletions docker-compose-tests.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.4'

# docker-compose -f docker-compose-tests.yml -f docker-compose-tests.override.yml up --build

services:
sql-data-test:
environment:
- SA_PASSWORD=Pass@word
- ACCEPT_EULA=Y
ports:
- "5433:1433"

blog-api-integration-test:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionStrings:DefaultConnection=${BLOG_API_TEST_DB:-Server=sql-data-test;Database=blog_api_test_db;User Id=sa;Password=Pass@word}
ports:
- "5101:80"
entrypoint:
- dotnet
- test
- --logger
- trx;LogFileName=/tests/blog-api-integration-test-results.xml

blog-services-test:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
ports:
- "5102:80"
entrypoint:
- dotnet
- test
- --logger
- trx;LogFileName=/tests/blog-services-test-results.xml
27 changes: 27 additions & 0 deletions docker-compose-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.4'

# docker-compose -f docker-compose-tests.yml -f docker-compose-tests.override.yml up --build

services:
sql-data-test:
image: mcr.microsoft.com/mssql/server:2017-latest

blog-api-integration-test:
image: ${REGISTRY:-test}/blog-api-integration-test:${TAG:-latest}
build:
context: .
dockerfile: src/Tests/Blog.API.IntegrationTests/Dockerfile
target: integrationtest
volumes:
- ${BUILD_ARTIFACTSTAGINGDIRECTORY:-./tests-results/}:/tests
depends_on:
- sql-data-test

blog-services-test:
image: '${REGISTRY:-test}/blog-services-test:${TAG:-latest}'
build:
context: .
dockerfile: src/Tests/Blog.Services.Tests/Dockerfile
target: servicestest
volumes:
- ${BUILD_ARTIFACTSTAGINGDIRECTORY:-./tests-results/}:/tests
20 changes: 20 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3.4'

# You need to start it with the following CLI command:
# docker-compose -f docker-compose.yml -f docker-compose.override.yml up --build

services:
sqldata:
environment:
- SA_PASSWORD=Pass@word
- ACCEPT_EULA=Y
ports:
- '5433:1433'

blog.api:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionStrings:DefaultConnection=${BLOG_API_DB:-Server=sqldata;Database=blog_api_db;User Id=sa;Password=Pass@word}
ports:
- '5100:80'
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.4'

# You need to start it with the following CLI command:
# docker-compose -f docker-compose.yml -f docker-compose.override.yml up --build

services:
sqldata:
image: 'mcr.microsoft.com/mssql/server:2017-latest'

blog.api:
image: '${REGISTRY:-mp}/blog.api:${PLATFORM:-linux}-${TAG:-latest}'
build:
context: .
dockerfile: src/Presentation/Blog.API/Dockerfile
depends_on:
- sqldata
1 change: 1 addition & 0 deletions run-test-infrastructure.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-compose -f .\docker-compose-tests.yml -f .\docker-compose-tests.override.yml up
13 changes: 13 additions & 0 deletions src/Presentation/Blog.API/Blog.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..\..</DockerfileContext>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>Blog.API.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Resease|AnyCPU'">
<DocumentationFile>Blog.API.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="4.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.0.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.6.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.5" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.6.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />
Expand All @@ -28,4 +35,10 @@
<ProjectReference Include="..\..\Libraries\Blog.Services\Blog.Services.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Blog.API.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
34 changes: 34 additions & 0 deletions src/Presentation/Blog.API/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src

COPY ["Blog.sln", "."]
COPY ["src/Presentation/Blog.API/Blog.API.csproj", "src/Presentation/Blog.API/"]
COPY ["src/Presentation/Blog.API/Blog.API.xml", "src/Presentation/Blog.API/"]
COPY ["src/Libraries/Blog.Data/Blog.Data.csproj", "src/Libraries/Blog.Data/"]
COPY ["src/Libraries/Blog.Core/Blog.Core.csproj", "src/Libraries/Blog.Core/"]
COPY ["src/Libraries/Blog.Services/Blog.Services.csproj", "src/Libraries/Blog.Services/"]
#COPY ["src/Tests/Blog.Services.Tests.csproj", "src/Tests/Blog.Services.Tests/"]
#COPY ["src/Tests/Blog.API.IntegrationTests.csproj", "src/Tests/Blog.API.IntegrationTests/"]
RUN dotnet restore "src/Presentation/Blog.API/Blog.API.csproj"
#RUN dotnet restore "Blog.sln"
COPY . .
WORKDIR "/src/src/Presentation/Blog.API"
RUN dotnet build "Blog.API.csproj" -c Release -o /app/build

#FROM build as servicestest
#WORKDIR "/src/src/Tests/Blog.Services.Tests"

#FROM build as integrationtest
#WORKDIR "/src/src/Tests/Blog.API.IntegrationTests"

FROM build AS publish
RUN dotnet publish "Blog.API.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Blog.API.dll"]
19 changes: 13 additions & 6 deletions src/Presentation/Blog.API/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:58966",
"sslPort": 0
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
Expand All @@ -21,10 +21,17 @@
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "index.html",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"applicationUrl": "http://localhost:5000"
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/index.html",
"environmentVariables": {},
"httpPort": 58967
}
}
}
2 changes: 1 addition & 1 deletion src/Presentation/Blog.API/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=blog_api_db;Trusted_Connection=True;MultipleActiveResultSets=true" //database connection strings
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=blog_api_db;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
<TargetFramework>netcoreapp3.0</TargetFramework>

<IsPackable>false</IsPackable>

<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>

<DockerfileContext>..\..\..</DockerfileContext>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.5" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public virtual async Task Get_Token_Unauthorized()

//Assert

//Assert.Throws<UnauthorizedAccessException>(() => httpResponse.EnsureSuccessStatusCode());
Assert.Throws<HttpRequestException>(() => httpResponse.EnsureSuccessStatusCode());

Assert.True(httpResponse.StatusCode == HttpStatusCode.Unauthorized);
Expand Down
22 changes: 22 additions & 0 deletions src/Tests/Blog.API.IntegrationTests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM mcr.microsoft.com/dotnet/core/runtime:3.0-buster-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src
COPY ["src/Tests/Blog.API.IntegrationTests/Blog.API.IntegrationTests.csproj", "src/Tests/Blog.API.IntegrationTests/"]
COPY ["src/Presentation/Blog.API/Blog.API.csproj", "src/Presentation/Blog.API/"]
COPY ["src/Libraries/Blog.Data/Blog.Data.csproj", "src/Libraries/Blog.Data/"]
COPY ["src/Libraries/Blog.Core/Blog.Core.csproj", "src/Libraries/Blog.Core/"]
COPY ["src/Libraries/Blog.Services/Blog.Services.csproj", "src/Libraries/Blog.Services/"]
RUN dotnet restore "src/Tests/Blog.API.IntegrationTests/Blog.API.IntegrationTests.csproj"
COPY . .
WORKDIR "/src/src/Tests/Blog.API.IntegrationTests"
RUN dotnet build "Blog.API.IntegrationTests.csproj" -c Release -o /app/build

FROM build as integrationtest
WORKDIR "/src/src/Tests/Blog.API.IntegrationTests"

#FROM base AS final
#WORKDIR /app
#COPY --from=publish /app/publish .
#ENTRYPOINT ["dotnet", "Blog.API.IntegrationTests.dll"]
10 changes: 10 additions & 0 deletions src/Tests/Blog.API.IntegrationTests/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"Blog.API.IntegrationTests": {
"commandName": "Project"
},
"Docker": {
"commandName": "Docker"
}
}
}
5 changes: 5 additions & 0 deletions src/Tests/Blog.Services.Tests/Blog.Services.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
<TargetFramework>netcoreapp3.0</TargetFramework>

<IsPackable>false</IsPackable>

<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>

<DockerfileContext>..\..\..</DockerfileContext>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.5" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
Expand Down
21 changes: 21 additions & 0 deletions src/Tests/Blog.Services.Tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM mcr.microsoft.com/dotnet/core/runtime:3.0-buster-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src
COPY ["src/Tests/Blog.Services.Tests/Blog.Services.Tests.csproj", "src/Tests/Blog.Services.Tests/"]
COPY ["src/Libraries/Blog.Data/Blog.Data.csproj", "src/Libraries/Blog.Data/"]
COPY ["src/Libraries/Blog.Core/Blog.Core.csproj", "src/Libraries/Blog.Core/"]
COPY ["src/Libraries/Blog.Services/Blog.Services.csproj", "src/Libraries/Blog.Services/"]
RUN dotnet restore "src/Tests/Blog.Services.Tests/Blog.Services.Tests.csproj"
COPY . .
WORKDIR "/src/src/Tests/Blog.Services.Tests"
RUN dotnet build "Blog.Services.Tests.csproj" -c Release -o /app/build

FROM build as servicestest
WORKDIR "/src/src/Tests/Blog.Services.Tests"

#FROM base AS final
#WORKDIR /app
#COPY --from=publish /app/publish .
#ENTRYPOINT ["dotnet", "Blog.Services.Tests.dll"]
10 changes: 10 additions & 0 deletions src/Tests/Blog.Services.Tests/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"Blog.Services.Tests": {
"commandName": "Project"
},
"Docker": {
"commandName": "Docker"
}
}
}

0 comments on commit 7f54ca5

Please sign in to comment.