Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pluralsight pipeline start #15

Open
wants to merge 4 commits into
base: pluralsight-pipeline-start
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/bin/
**/obj/
**/.git/
**/.vs/
infra/
**/global.json
**/Dockerfile*
**/.dockerignore*
**/docker-compose*.yml
**/*.user
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Build stage
FROM microsoft/aspnetcore-build:2 AS build-env

WORKDIR /generator

# restore
COPY api/api.csproj ./api/
RUN dotnet restore api/api.csproj
COPY tests/tests.csproj ./tests/
RUN dotnet restore tests/tests.csproj

# debug...
#RUN ls -alR

# copy src
COPY . .


## test
ENV TEAMCITY_PROJECT_NAME=fake
RUN dotnet test tests/tests.csproj


#
# publish
RUN dotnet publish api/api.csproj -o /publish



# Runtime stage
FROM microsoft/aspnetcore:2
COPY --from=build-env /publish /publish
WORKDIR /publish
ENTRYPOINT ["dotnet", "api.dll"]
2 changes: 1 addition & 1 deletion api/api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Faker.Net" Version="1.0.3" />
<PackageReference Include="Faker.Net" Version="1.3.77" />
<PackageReference Include="MailKit" Version="1.16.1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
Expand Down
100 changes: 85 additions & 15 deletions generator.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "api", "api\api.csproj", "{395194DA-84B9-4E9B-BA03-F4D091155E37}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "api", "api\api.csproj", "{395194DA-84B9-4E9B-BA03-F4D091155E37}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{687FD694-1180-4B8F-9D51-BBFA50281B23}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "tests", "tests\tests.csproj", "{A7FC782A-14CC-4556-BA47-F5AE2C06884B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Root", "Root", "{4EEA85E1-FDD2-43AD-8437-03305AE05997}"
ProjectSection(SolutionItems) = preProject
.dockerignore = .dockerignore
Dockerfile = Dockerfile
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructure", "Infrastructure", "{A7DC401F-D314-4833-AEDE-23FE5F50D234}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Registry", "Registry", "{E8B61874-DB6D-42B5-8DDE-AA9E28375CBC}"
ProjectSection(SolutionItems) = preProject
infra\registry\docker-compose.yml = infra\registry\docker-compose.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TeamCity", "TeamCity", "{C15CDA56-CDE3-4E2C-BDD2-C2BCCC00F3A7}"
ProjectSection(SolutionItems) = preProject
infra\teamcity\docker-compose.yml = infra\teamcity\docker-compose.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Agent", "Agent", "{4D1A85B6-7A00-4EE7-8EC5-02D2BE4F2157}"
ProjectSection(SolutionItems) = preProject
infra\teamcity\agent\Dockerfile = infra\teamcity\agent\Dockerfile
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "integration", "integration\integration.csproj", "{7CB23307-3C75-4A20-96C6-99BC68679D73}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Integration Testing", "Integration Testing", "{D104DEF7-CD5E-42BF-A980-567543FEC88F}"
ProjectSection(SolutionItems) = preProject
integration\.dockerignore = integration\.dockerignore
integration\docker-compose.yml = integration\docker-compose.yml
integration\Dockerfile = integration\Dockerfile
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -14,21 +49,56 @@ Global
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Debug|Any CPU.Build.0 = Debug|Any CPU
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Debug|x64.ActiveCfg = Debug|x64
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Debug|x64.Build.0 = Debug|x64
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Debug|x86.ActiveCfg = Debug|x86
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Debug|x86.Build.0 = Debug|x86
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Debug|x64.ActiveCfg = Debug|Any CPU
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Debug|x64.Build.0 = Debug|Any CPU
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Debug|x86.ActiveCfg = Debug|Any CPU
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Debug|x86.Build.0 = Debug|Any CPU
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Release|Any CPU.Build.0 = Release|Any CPU
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Release|x64.ActiveCfg = Release|x64
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Release|x64.Build.0 = Release|x64
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Release|x86.ActiveCfg = Release|x86
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Release|x86.Build.0 = Release|x86
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Release|x64.ActiveCfg = Release|Any CPU
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Release|x64.Build.0 = Release|Any CPU
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Release|x86.ActiveCfg = Release|Any CPU
{395194DA-84B9-4E9B-BA03-F4D091155E37}.Release|x86.Build.0 = Release|Any CPU
{A7FC782A-14CC-4556-BA47-F5AE2C06884B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7FC782A-14CC-4556-BA47-F5AE2C06884B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7FC782A-14CC-4556-BA47-F5AE2C06884B}.Debug|x64.ActiveCfg = Debug|Any CPU
{A7FC782A-14CC-4556-BA47-F5AE2C06884B}.Debug|x64.Build.0 = Debug|Any CPU
{A7FC782A-14CC-4556-BA47-F5AE2C06884B}.Debug|x86.ActiveCfg = Debug|Any CPU
{A7FC782A-14CC-4556-BA47-F5AE2C06884B}.Debug|x86.Build.0 = Debug|Any CPU
{A7FC782A-14CC-4556-BA47-F5AE2C06884B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7FC782A-14CC-4556-BA47-F5AE2C06884B}.Release|Any CPU.Build.0 = Release|Any CPU
{A7FC782A-14CC-4556-BA47-F5AE2C06884B}.Release|x64.ActiveCfg = Release|Any CPU
{A7FC782A-14CC-4556-BA47-F5AE2C06884B}.Release|x64.Build.0 = Release|Any CPU
{A7FC782A-14CC-4556-BA47-F5AE2C06884B}.Release|x86.ActiveCfg = Release|Any CPU
{A7FC782A-14CC-4556-BA47-F5AE2C06884B}.Release|x86.Build.0 = Release|Any CPU
{7CB23307-3C75-4A20-96C6-99BC68679D73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7CB23307-3C75-4A20-96C6-99BC68679D73}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7CB23307-3C75-4A20-96C6-99BC68679D73}.Debug|x64.ActiveCfg = Debug|Any CPU
{7CB23307-3C75-4A20-96C6-99BC68679D73}.Debug|x64.Build.0 = Debug|Any CPU
{7CB23307-3C75-4A20-96C6-99BC68679D73}.Debug|x86.ActiveCfg = Debug|Any CPU
{7CB23307-3C75-4A20-96C6-99BC68679D73}.Debug|x86.Build.0 = Debug|Any CPU
{7CB23307-3C75-4A20-96C6-99BC68679D73}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7CB23307-3C75-4A20-96C6-99BC68679D73}.Release|Any CPU.Build.0 = Release|Any CPU
{7CB23307-3C75-4A20-96C6-99BC68679D73}.Release|x64.ActiveCfg = Release|Any CPU
{7CB23307-3C75-4A20-96C6-99BC68679D73}.Release|x64.Build.0 = Release|Any CPU
{7CB23307-3C75-4A20-96C6-99BC68679D73}.Release|x86.ActiveCfg = Release|Any CPU
{7CB23307-3C75-4A20-96C6-99BC68679D73}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4EEA85E1-FDD2-43AD-8437-03305AE05997} = {687FD694-1180-4B8F-9D51-BBFA50281B23}
{A7DC401F-D314-4833-AEDE-23FE5F50D234} = {687FD694-1180-4B8F-9D51-BBFA50281B23}
{E8B61874-DB6D-42B5-8DDE-AA9E28375CBC} = {A7DC401F-D314-4833-AEDE-23FE5F50D234}
{C15CDA56-CDE3-4E2C-BDD2-C2BCCC00F3A7} = {A7DC401F-D314-4833-AEDE-23FE5F50D234}
{4D1A85B6-7A00-4EE7-8EC5-02D2BE4F2157} = {C15CDA56-CDE3-4E2C-BDD2-C2BCCC00F3A7}
{D104DEF7-CD5E-42BF-A980-567543FEC88F} = {687FD694-1180-4B8F-9D51-BBFA50281B23}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8D7F76E8-A82B-4271-997A-5B50B2830863}
EndGlobalSection
EndGlobal
13 changes: 13 additions & 0 deletions infra/registry/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.1'

services:
straps-q2-registry:
image: registry:2.6.1
volumes:
- registry:/var/lib/registry
ports:
- "56000:5000"
restart: unless-stopped

volumes:
registry:
4 changes: 4 additions & 0 deletions infra/teamcity/agent/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM jetbrains/teamcity-agent:2017.1.2

RUN curl -L https://github.com/docker/compose/releases/download/1.13.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose
22 changes: 22 additions & 0 deletions infra/teamcity/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3.1'

services:
teamcity:
image: jetbrains/teamcity-server:2017.1.2
volumes:
- teamcity-server-datadir:/data/teamcity_server/datadir
- teamcity-server-logs:/opt/teamcity/logs
ports:
- 8111:8111
teamcity-agent:
image: aspnetcore/teamcity-agent-with-compose:2017.1.2
build: ./agent
environment:
SERVER_URL: http://teamcity:8111
volumes:
- /var/run/docker.sock:/var/run/docker.sock


volumes:
teamcity-server-datadir:
teamcity-server-logs:
5 changes: 5 additions & 0 deletions integration/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bin/
obj/
**/Dockerfile*
**/.dockerignore*
**/docker-compose*.yml
9 changes: 9 additions & 0 deletions integration/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Build Stage
FROM microsoft/dotnet:2-sdk
WORKDIR /integration

COPY integration.csproj .
RUN dotnet restore

COPY . .
ENTRYPOINT ["dotnet", "test"]
52 changes: 52 additions & 0 deletions integration/EmailTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using FluentAssertions.Json;
using Newtonsoft.Json.Linq;
using Xunit;

namespace integration
{
public class EmailTests
{
public const string GeneratorApiRoot = "http://generator";
public const string MailHogApiV2Root = "http://mail:8025/api/v2";

[Fact]
public async Task SendEmailWithNames_IsFromGenerator()
{
// send email
var client = new HttpClient();
var sendEmail = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri($"{GeneratorApiRoot}/EmailRandomNames")
};
Console.WriteLine($"Sending email: [{sendEmail.RequestUri}]");
using (var response = await client.SendAsync(sendEmail))
{
response.EnsureSuccessStatusCode();
}

// check if email
var checkEmails = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri($"{MailHogApiV2Root}/messages")
};
Console.WriteLine($"Checking emails: [{checkEmails.RequestUri}]");
using (var response = await client.SendAsync(checkEmails))
{
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
var messages = JObject.Parse(content);
messages.Should().HaveElement("total").Which.Should().Be(1);
messages.Should().HaveElement("items")
.Which.Should().BeOfType<JArray>()
.Which.First.Should().HaveElement("Raw")
.Which.Should().HaveElement("From")
.Which.Should().Be("[email protected]");
}
}
}
}
22 changes: 22 additions & 0 deletions integration/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3.1'

services:
generator:
image: straps-q2-registry:56000/tcbuild:ci-9
#
# DO NOT USE PORTS IN CI BUILD -
# THIS IS FOR LOCAL DEV DEBUGGING ONLY...
#
ports:
- "8080:80"
mail:
image: mailhog/mailhog
#
# DO NOT USE PORTS IN CI BUILD -
# THIS IS FOR LOCAL DEV DEBUGGING ONLY...
#
ports:
- "8025:8025"
integration:
image: straps-q2-registry:56000/tcbuild:integration-9
build: .
17 changes: 17 additions & 0 deletions integration/integration.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions.Json" Version="4.19.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.2" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>

</Project>
30 changes: 30 additions & 0 deletions tests/RangeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Linq;
using Xunit;
using Range = api.Controllers.Range;

namespace tests
{
public class RangeTests
{
[Fact]
public void CountShouldControlNumberOfResults()
{
var range = new Range { Count = 3 };

var generated = range.Of(() => "");

Assert.Equal(3, generated.Count());
}

[Fact]
public void SortShouldOrderResults()
{
var range = new Range { Count = 3, Sort = true };
var values = new[] { "a", "c", "b" };
var counter = 0;
var generated = range.Of(() => values[counter++]);

Assert.Equal(new[] { "a", "b", "c" }, generated.ToArray());
}
}
}
21 changes: 21 additions & 0 deletions tests/tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Faker.Net" Version="1.3.77" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.2" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\api\api.csproj" />
</ItemGroup>

</Project>