From ac211886f1f114b50cb5fed62af0277f091ef6fc Mon Sep 17 00:00:00 2001 From: Phil Proctor Date: Wed, 26 Dec 2018 11:30:59 -0500 Subject: [PATCH] Dockerfile build (#727) * Added Dockerfile run configuration and fixed manual test project to run appropriately * Finished updates for Docker build and management of project through docker commands. Any of the dotnet CLI commands accessible through 'builder' container and default run is manual test project * Added a docker-compose.yaml files to support commands: docker-compose run tests, docker-compose run benchmarks, docker-compose run manual-test --- .dockerignore | 2 ++ .gitignore | 3 +++ Dockerfile | 39 +++++++++++++++++++++++++++++++ Ocelot.sln | 4 +++- docker-compose.yaml | 24 +++++++++++++++++++ test/Ocelot.ManualTest/Program.cs | 8 +++++-- 6 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..54fec4f0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +*/*/bin +*/*/obj diff --git a/.gitignore b/.gitignore index e314ed94..4980a426 100644 --- a/.gitignore +++ b/.gitignore @@ -252,3 +252,6 @@ _templates/ # JetBrains Rider .idea/ + +# Test Results +*.trx diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..47814325 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +#This is the base image used for any ran images +FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base +WORKDIR /app +EXPOSE 80 + +#This image is used to build the source for the runnable app +#It can also be used to run other CLI commands on the project, such as packing/deploying nuget packages. Some examples: +#Run tests: docker build --target builder -t ocelot-build . && docker run ocelot-build test --logger:trx;LogFileName=results.trx +#Run benchmarks: docker build --target builder --build-arg build_configuration=Release -t ocelot-build . && docker run ocelot-build run -c Release --project test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj +FROM microsoft/dotnet:2.1.502-sdk AS builder +WORKDIR /build +#First we add only the project files so that we can cache nuget packages with dotnet restore +COPY Ocelot.sln Ocelot.sln +COPY src/Ocelot/Ocelot.csproj src/Ocelot/Ocelot.csproj +COPY test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj +COPY test/Ocelot.ManualTest/Ocelot.ManualTest.csproj test/Ocelot.ManualTest/Ocelot.ManualTest.csproj +COPY test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj +COPY test/Ocelot.UnitTests/Ocelot.UnitTests.csproj test/Ocelot.UnitTests/Ocelot.UnitTests.csproj +COPY test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj +RUN dotnet restore +#Now we add the rest of the source and run a complete build... --no-restore is used because nuget should be resolved at this point +COPY codeanalysis.ruleset codeanalysis.ruleset +COPY src src +COPY test test +ARG build_configuration=Debug +RUN dotnet build --no-restore -c ${build_configuration} +ENTRYPOINT ["dotnet"] + +#This is just for holding the published manual tests... +FROM builder AS manual-test-publish +ARG build_configuration=Debug +RUN dotnet publish --no-build -c ${build_configuration} -o /app test/Ocelot.ManualTest + +#Run manual tests! This is the default run option. +#docker build -t ocelot-manual-test . && docker run --net host ocelot-manual-test +FROM base AS manual-test +ENV ASPNETCORE_ENVIRONMENT=Development +COPY --from=manual-test-publish /app . +ENTRYPOINT ["dotnet", "Ocelot.ManualTest.dll"] diff --git a/Ocelot.sln b/Ocelot.sln index c9ac2782..d20e939e 100644 --- a/Ocelot.sln +++ b/Ocelot.sln @@ -16,7 +16,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution GitVersion.yml = GitVersion.yml global.json = global.json LICENSE.md = LICENSE.md - ocelot.postman_collection.json = ocelot.postman_collection.json README.md = README.md release.ps1 = release.ps1 ReleaseNotes.md = ReleaseNotes.md @@ -24,6 +23,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution run-benchmarks.ps1 = run-benchmarks.ps1 run-unit-tests.ps1 = run-unit-tests.ps1 version.ps1 = version.ps1 + Dockerfile = Dockerfile + .dockerignore = .dockerignore + docker-compose.yaml = docker-compose.yaml EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{5B401523-36DA-4491-B73A-7590A26E420B}" diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..83136844 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,24 @@ +version: "3.4" +services: + + tests: + build: + context: . + target: builder + volumes: + - type: bind + source: . + target: /results + command: test --logger:trx -r /results + + benchmarks: + build: + context: . + target: builder + args: + build_configuration: Release + command: run -c Release --project test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj 0 1 2 3 4 + + manual-test: + build: . + ports: [ "5000:80" ] diff --git a/test/Ocelot.ManualTest/Program.cs b/test/Ocelot.ManualTest/Program.cs index 2a43e886..43f9bc59 100644 --- a/test/Ocelot.ManualTest/Program.cs +++ b/test/Ocelot.ManualTest/Program.cs @@ -1,4 +1,7 @@ -namespace Ocelot.ManualTest +using System.Reflection.Metadata.Ecma335; +using Ocelot.Requester; + +namespace Ocelot.ManualTest { using System.IO; using Microsoft.AspNetCore.Hosting; @@ -36,7 +39,8 @@ x.Audience = "test"; }); - s.AddOcelot() + s.AddSingleton((x, t) => new FakeHandler()); + s.AddOcelot() .AddDelegatingHandler(true); // .AddCacheManager(x => // {