From c92eb0591ca73b3447854c0184e75b322bd3602a Mon Sep 17 00:00:00 2001 From: Rui Quintas Barbosa Date: Mon, 5 Feb 2024 14:52:53 +0000 Subject: [PATCH] ci: correct sample dockerfile --- LoadShedding.sln | 4 +- Makefile | 23 +--- deploy/docker/Dockerfile | 111 -------------------- docker-compose.sample.yaml | 2 +- docker-compose.yaml | 44 -------- {deploy/docker => docker}/Sample.Dockerfile | 6 +- 6 files changed, 7 insertions(+), 183 deletions(-) delete mode 100644 deploy/docker/Dockerfile delete mode 100644 docker-compose.yaml rename {deploy/docker => docker}/Sample.Dockerfile (88%) diff --git a/LoadShedding.sln b/LoadShedding.sln index 1d410eb..2e05588 100644 --- a/LoadShedding.sln +++ b/LoadShedding.sln @@ -39,10 +39,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig docker-compose.sample.yaml = docker-compose.sample.yaml - docker-compose.yaml = docker-compose.yaml - deploy\docker\Dockerfile = deploy\docker\Dockerfile Makefile = Makefile - deploy\docker\Sample.Dockerfile = deploy\docker\Sample.Dockerfile + docker\Sample.Dockerfile = docker\Sample.Dockerfile EndProjectSection EndProject Global diff --git a/Makefile b/Makefile index 861e1d6..3afb631 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,7 @@ -.PHONY: build unit-tests integration-tests performance-tests clean sample sample-clean +.PHONY: sample sample-clean -build: - @docker compose up --build --no-start - -unit-tests: build - @docker compose up --abort-on-container-exit --exit-code-from unit-tests unit-tests - -integration-tests: build - @docker compose up --abort-on-container-exit --exit-code-from integration-tests integration-tests - -performance-tests: build - @docker compose up -d performance-tests-sample - @docker compose up -d performance-tests-sample-no-limiter - - @docker compose up --abort-on-container-exit --exit-code-from performance-tests performance-tests - -clean: - @docker compose down - @docker compose -f docker-compose.sample.yaml down - sample: - @docker compose -f docker-compose.sample.yaml up -d + @docker compose -f docker-compose.sample.yaml up --build -d sample-clean: @docker compose -f docker-compose.sample.yaml down diff --git a/deploy/docker/Dockerfile b/deploy/docker/Dockerfile deleted file mode 100644 index 230ec09..0000000 --- a/deploy/docker/Dockerfile +++ /dev/null @@ -1,111 +0,0 @@ -ARG FROM_REPO=mcr.microsoft.com/dotnet -ARG DOTNET_SDK_IMAGE=sdk:8.0-jammy -ARG DOTNET_RUNTIME_IMAGE=runtime:8.0-jammy -ARG ASPNET_RUNTIME_IMAGE=aspnet:8.0-jammy -ARG RUNTIME_IDENTIFIER=linux-x64 - -## -## sdk-image - Has the .net core SDK required to build and run tests -## -FROM ${FROM_REPO}/${DOTNET_SDK_IMAGE} as sdk-image - -## -## runtime-image - Has the .net core runtime, required to run the service -## -FROM ${FROM_REPO}/${DOTNET_RUNTIME_IMAGE} as runtime-image - -## -## aspnet-runtime-image - Has the asp.net core runtime, required to run the web applications -## -FROM ${FROM_REPO}/${ASPNET_RUNTIME_IMAGE} AS aspnet-runtime-image - -## -## Building -## -FROM sdk-image AS build - -ARG RUNTIME_IDENTIFIER - -RUN mkdir /app -WORKDIR /app - -# 1 - Copy sln and csprojs to make restore faster - Optional -COPY LoadShedding.sln LoadShedding.sln - -# 1.1 Library -COPY src/*/*.csproj ./ -RUN for file in $(ls *.csproj); do mkdir -p src/${file%.*}/ && mv $file src/${file%.*}/; done - -# 1.2 Unit tests -COPY tests/unit-tests/*/*.csproj ./ -RUN for file in $(ls *.csproj); do mkdir -p tests/unit-tests/${file%.*}/ && mv $file tests/unit-tests/${file%.*}/; done - -# 1.3 Integration tests -COPY tests/integration-tests/Farfetch.LoadShedding.IntegrationTests/Farfetch.LoadShedding.IntegrationTests.csproj tests/integration-tests/Farfetch.LoadShedding.IntegrationTests/Farfetch.LoadShedding.IntegrationTests.csproj - -# 1.4 Performance tests -COPY tests/performance-tests/Farfetch.LoadShedding.PerformanceTests/Farfetch.LoadShedding.PerformanceTests.csproj tests/performance-tests/Farfetch.LoadShedding.PerformanceTests/Farfetch.LoadShedding.PerformanceTests.csproj - -# 1.5 - Restore nuget packages -RUN dotnet restore LoadShedding.sln -r ${RUNTIME_IDENTIFIER} - -# 2 - Copy all files -COPY . . - -# 3 - Build -RUN dotnet build --no-restore --configuration Release LoadShedding.sln -RUN mkdir /reports - -# 5 - Publish performance tests sample - -RUN dotnet publish tests/performance-tests/Farfetch.LoadShedding.PerformanceTests/Farfetch.LoadShedding.PerformanceTests.csproj -c Release -o /out --no-restore - -## -## Unit Tests -## -FROM sdk-image AS unit-tests - -COPY --from=build /app /app -COPY --from=build /.nuget /.nuget - -WORKDIR /app - -RUN dotnet test LoadShedding.sln --filter Category=Unit --configuration Release - -# -# Integration Tests -# -FROM sdk-image AS integration-tests -ENV ASPNETCORE_ENVIRONMENT=Docker - -COPY --from=build /app /app -COPY --from=build /.nuget /.nuget - -WORKDIR /app - -CMD ["dotnet", "test", "--no-restore", "tests/integration-tests/Farfetch.LoadShedding.IntegrationTests/Farfetch.LoadShedding.IntegrationTests.csproj", "--logger", "trx", "--results-directory", "/reports"] - -# -# Performance Tests Sample -# -FROM aspnet-runtime-image AS performance-tests-sample -ENV ASPNETCORE_ENVIRONMENT=Docker - -COPY --from=build /.nuget /.nuget -COPY --from=build /out /app - -WORKDIR /app - -ENV ASPNETCORE_URLS=http://+:9025 \ - ASPNETCORE_ENVIRONMENT=Docker - -CMD dotnet Farfetch.LoadShedding.PerformanceTests.dll - -## -## Jmeter Performance Tests -## -FROM justb4/jmeter:5.5 As performance-tests -COPY --from=build /app/tests/performance-tests/AdaptiveLimiterTests.jmx /app -WORKDIR /app - -CMD ["jmeter", "-Jjmeter.save.saveservice.output_format=xml", "-JServerEndpoint=performance-tests-sample", "-JServerEndpointNoLimiter=performance-tests-sample-no-limiter", "-n", "-t", "AdaptiveLimiterTests.jmx", "-l", "results.jtl"] diff --git a/docker-compose.sample.yaml b/docker-compose.sample.yaml index 882b427..1240db9 100644 --- a/docker-compose.sample.yaml +++ b/docker-compose.sample.yaml @@ -10,7 +10,7 @@ services: - MongoConnectionString=mongodb://mongo:27017/loadshedding build: context: . - dockerfile: deploy/docker/Samples.Dockerfile + dockerfile: docker/Sample.Dockerfile depends_on: - mongo diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index 6017379..0000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,44 +0,0 @@ -version: "3.4" - -services: - unit-tests: - container_name: loadshedding-unit-tests - image: loadshedding-unit-tests - build: - context: . - dockerfile: deploy/docker/Dockerfile - target: unit-tests - - integration-tests: - container_name: loadshedding-integration-tests - image: loadshedding-integration-tests - build: - context: . - dockerfile: deploy/docker/Dockerfile - target: integration-tests - - performance-tests-sample: - container_name: loadshedding-performance-tests-sample - image: loadshedding-performance-tests-sample - build: - context: . - dockerfile: deploy/docker/Dockerfile - target: performance-tests-sample - - performance-tests-sample-no-limiter: - container_name: loadshedding-performance-tests-sample-no-limiter - image: loadshedding-performance-tests-sample-no-limiter - environment: - - UseLoadShedding=false - build: - context: . - dockerfile: deploy/docker/Dockerfile - target: performance-tests-sample - - performance-tests: - container_name: loadshedding-performance-tests - image: loadshedding-performance-tests - build: - context: . - dockerfile: deploy/docker/Dockerfile - target: performance-tests \ No newline at end of file diff --git a/deploy/docker/Sample.Dockerfile b/docker/Sample.Dockerfile similarity index 88% rename from deploy/docker/Sample.Dockerfile rename to docker/Sample.Dockerfile index f436bfd..2b62f06 100644 --- a/deploy/docker/Sample.Dockerfile +++ b/docker/Sample.Dockerfile @@ -1,6 +1,6 @@ ARG FROM_REPO=mcr.microsoft.com/dotnet -ARG DOTNET_SDK_IMAGE=sdk:sdk:8.0-jammy -ARG ASPNET_RUNTIME_IMAGE=aspnet:aspnet:8.0-jammy +ARG DOTNET_SDK_IMAGE=sdk:8.0-jammy +ARG ASPNET_RUNTIME_IMAGE=aspnet:8.0-jammy ARG RUNTIME_IDENTIFIER=linux-x64 FROM ${FROM_REPO}/${DOTNET_SDK_IMAGE} as sdk-image @@ -48,4 +48,4 @@ WORKDIR /out ENV ASPNETCORE_URLS=http://+:5261 COPY --from=publish /out . -ENTRYPOINT ["dotnet", "Samples.WebApi.dll"] \ No newline at end of file +ENTRYPOINT ["dotnet", "Samples.WebApi.dll"]