From 758c5e637bfb34384c55e8eceef341b87251fcdf Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Sun, 28 Apr 2019 08:09:06 -0500 Subject: [PATCH] wip misc docker updates --- .dockerignore | 16 +++- FilterLists.Api.sln | 78 +++++++++++++++++++ FilterLists.sln | 42 ---------- docker-compose.dcproj | 16 ---- ....filterlists-api.yml => docker-compose.yml | 17 +++- ops/nginx/Dockerfile | 2 - ops/nginx/dev/conf.d/filterlists-api.conf | 15 ++++ ops/nginx/nginx.conf | 30 ------- src/FilterLists.Api/Dockerfile | 32 ++++++-- .../FilterLists.Data.Tests.csproj | 1 - 10 files changed, 143 insertions(+), 106 deletions(-) create mode 100644 FilterLists.Api.sln delete mode 100644 docker-compose.dcproj rename docker-compose.filterlists-api.yml => docker-compose.yml (80%) delete mode 100644 ops/nginx/Dockerfile create mode 100644 ops/nginx/dev/conf.d/filterlists-api.conf delete mode 100644 ops/nginx/nginx.conf diff --git a/.dockerignore b/.dockerignore index 43e8ab1e3..774e6e7d4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,10 +1,18 @@ -.dockerignore -.env .git +.github +.gitattributes .gitignore .vs .vscode -docker-compose.yml -docker-compose.*.yml +images +ops +scripts */bin */obj +codecov.yml +.dockerignore +docker-compose.yml +docker-compose.*.yml +*.DotSettings* +FilterLists.postman_collection.json +LICENSE \ No newline at end of file diff --git a/FilterLists.Api.sln b/FilterLists.Api.sln new file mode 100644 index 000000000..8f9edffbd --- /dev/null +++ b/FilterLists.Api.sln @@ -0,0 +1,78 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28803.202 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FilterLists.Api", "src\FilterLists.Api\FilterLists.Api.csproj", "{0115C4AD-63F2-4075-98F4-DF97A1A961B0}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FilterLists.Data", "src\FilterLists.Data\FilterLists.Data.csproj", "{234B42ED-DE64-427A-9FAA-A4B4DA25BBFD}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FilterLists.Services", "src\FilterLists.Services\FilterLists.Services.csproj", "{8FACA060-B344-46C5-8614-5CA4273D38C4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FilterLists.Data.Tests", "tests\FilterLists.Data.Tests\FilterLists.Data.Tests.csproj", "{DB1E6B87-DF71-47B8-9235-BFCD1496EFA1}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FilterLists.Services.Tests", "tests\FilterLists.Services.Tests\FilterLists.Services.Tests.csproj", "{2ACC8D42-9E7D-4447-BC2B-9449B8981CF0}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B08FB2A1-A903-4C99-83E7-4991B49A9841}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{5D12BA97-CC9B-4195-8D9A-35012899D91C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "data", "data", "{95556DA4-5C8B-43E4-B0E7-29DCF7F81F8A}" + ProjectSection(SolutionItems) = preProject + data\Dependent.json = data\Dependent.json + data\FilterList.json = data\FilterList.json + data\FilterListLanguage.json = data\FilterListLanguage.json + data\FilterListMaintainer.json = data\FilterListMaintainer.json + data\FilterListTag.json = data\FilterListTag.json + data\Fork.json = data\Fork.json + data\Language.json = data\Language.json + data\License.json = data\License.json + data\Maintainer.json = data\Maintainer.json + data\Merge.json = data\Merge.json + data\Software.json = data\Software.json + data\SoftwareSyntax.json = data\SoftwareSyntax.json + data\Syntax.json = data\Syntax.json + data\Tag.json = data\Tag.json + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0115C4AD-63F2-4075-98F4-DF97A1A961B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0115C4AD-63F2-4075-98F4-DF97A1A961B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0115C4AD-63F2-4075-98F4-DF97A1A961B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0115C4AD-63F2-4075-98F4-DF97A1A961B0}.Release|Any CPU.Build.0 = Release|Any CPU + {234B42ED-DE64-427A-9FAA-A4B4DA25BBFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {234B42ED-DE64-427A-9FAA-A4B4DA25BBFD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {234B42ED-DE64-427A-9FAA-A4B4DA25BBFD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {234B42ED-DE64-427A-9FAA-A4B4DA25BBFD}.Release|Any CPU.Build.0 = Release|Any CPU + {8FACA060-B344-46C5-8614-5CA4273D38C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8FACA060-B344-46C5-8614-5CA4273D38C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8FACA060-B344-46C5-8614-5CA4273D38C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8FACA060-B344-46C5-8614-5CA4273D38C4}.Release|Any CPU.Build.0 = Release|Any CPU + {DB1E6B87-DF71-47B8-9235-BFCD1496EFA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DB1E6B87-DF71-47B8-9235-BFCD1496EFA1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DB1E6B87-DF71-47B8-9235-BFCD1496EFA1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DB1E6B87-DF71-47B8-9235-BFCD1496EFA1}.Release|Any CPU.Build.0 = Release|Any CPU + {2ACC8D42-9E7D-4447-BC2B-9449B8981CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2ACC8D42-9E7D-4447-BC2B-9449B8981CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2ACC8D42-9E7D-4447-BC2B-9449B8981CF0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2ACC8D42-9E7D-4447-BC2B-9449B8981CF0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {0115C4AD-63F2-4075-98F4-DF97A1A961B0} = {B08FB2A1-A903-4C99-83E7-4991B49A9841} + {234B42ED-DE64-427A-9FAA-A4B4DA25BBFD} = {B08FB2A1-A903-4C99-83E7-4991B49A9841} + {8FACA060-B344-46C5-8614-5CA4273D38C4} = {B08FB2A1-A903-4C99-83E7-4991B49A9841} + {DB1E6B87-DF71-47B8-9235-BFCD1496EFA1} = {5D12BA97-CC9B-4195-8D9A-35012899D91C} + {2ACC8D42-9E7D-4447-BC2B-9449B8981CF0} = {5D12BA97-CC9B-4195-8D9A-35012899D91C} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2A61003B-647A-4A20-A9D0-BE5AF9077426} + EndGlobalSection +EndGlobal diff --git a/FilterLists.sln b/FilterLists.sln index debd5aa7b..37aace757 100644 --- a/FilterLists.sln +++ b/FilterLists.sln @@ -35,43 +35,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FilterLists.Services.Tests" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FilterLists.Data.Tests", "tests\FilterLists.Data.Tests\FilterLists.Data.Tests.csproj", "{DA34DED7-B352-4855-9C7B-9E3D983DBE2E}" EndProject -Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{94FF757E-0A78-4E9C-971E-A0709206AC27}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{CE4AB25B-5501-42E9-B8B4-87B9C20472AC}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{041F9CFA-B6F7-4DEB-9441-829DE697B1BB}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ops", "ops", "{AF336194-8932-4C99-BF8B-30FF8EC146E9}" - ProjectSection(SolutionItems) = preProject - .gitignore = .gitignore - codecov.yml = codecov.yml - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nginx", "nginx", "{E11FDECE-A7F7-4ECB-A61F-83C124466412}" - ProjectSection(SolutionItems) = preProject - ops\nginx\Dockerfile = ops\nginx\Dockerfile - ops\nginx\nginx.conf = ops\nginx\nginx.conf - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "mariadb", "mariadb", "{982092B7-CCE2-4BD1-9240-E59D0817F5CF}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{EA7CB599-AE37-429E-A44D-E5C741F9FB3D}" - ProjectSection(SolutionItems) = preProject - ops\scripts\build.sh = ops\scripts\build.sh - ops\scripts\cron = ops\scripts\cron - ops\scripts\deploy.sh = ops\scripts\deploy.sh - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sql", "sql", "{D44C45FF-1AF9-4404-8510-418D9981B7CD}" - ProjectSection(SolutionItems) = preProject - ops\scripts\sql\createDb.sql = ops\scripts\sql\createDb.sql - ops\scripts\sql\duplicateRules.sql = ops\scripts\sql\duplicateRules.sql - ops\scripts\sql\orphanedSnapshotsRules.sql = ops\scripts\sql\orphanedSnapshotsRules.sql - ops\scripts\sql\resetSnapshotsRules.sql = ops\scripts\sql\resetSnapshotsRules.sql - ops\scripts\sql\snapshotMetrics.sql = ops\scripts\sql\snapshotMetrics.sql - ops\scripts\sql\snapshotTimeAnalysis.sql = ops\scripts\sql\snapshotTimeAnalysis.sql - EndProjectSection -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -106,10 +73,6 @@ Global {DA34DED7-B352-4855-9C7B-9E3D983DBE2E}.Debug|Any CPU.Build.0 = Debug|Any CPU {DA34DED7-B352-4855-9C7B-9E3D983DBE2E}.Release|Any CPU.ActiveCfg = Release|Any CPU {DA34DED7-B352-4855-9C7B-9E3D983DBE2E}.Release|Any CPU.Build.0 = Release|Any CPU - {94FF757E-0A78-4E9C-971E-A0709206AC27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {94FF757E-0A78-4E9C-971E-A0709206AC27}.Debug|Any CPU.Build.0 = Debug|Any CPU - {94FF757E-0A78-4E9C-971E-A0709206AC27}.Release|Any CPU.ActiveCfg = Release|Any CPU - {94FF757E-0A78-4E9C-971E-A0709206AC27}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -122,11 +85,6 @@ Global {4F39D132-498D-4A93-9F6C-1C604718300D} = {CE4AB25B-5501-42E9-B8B4-87B9C20472AC} {7D9F0D85-E906-401A-BDAD-724440B34567} = {041F9CFA-B6F7-4DEB-9441-829DE697B1BB} {DA34DED7-B352-4855-9C7B-9E3D983DBE2E} = {041F9CFA-B6F7-4DEB-9441-829DE697B1BB} - {94FF757E-0A78-4E9C-971E-A0709206AC27} = {AF336194-8932-4C99-BF8B-30FF8EC146E9} - {E11FDECE-A7F7-4ECB-A61F-83C124466412} = {AF336194-8932-4C99-BF8B-30FF8EC146E9} - {982092B7-CCE2-4BD1-9240-E59D0817F5CF} = {AF336194-8932-4C99-BF8B-30FF8EC146E9} - {EA7CB599-AE37-429E-A44D-E5C741F9FB3D} = {AF336194-8932-4C99-BF8B-30FF8EC146E9} - {D44C45FF-1AF9-4404-8510-418D9981B7CD} = {EA7CB599-AE37-429E-A44D-E5C741F9FB3D} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {8A31B449-52DD-4445-A9C4-033A24E25308} diff --git a/docker-compose.dcproj b/docker-compose.dcproj deleted file mode 100644 index ff04b2d1c..000000000 --- a/docker-compose.dcproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - 2.1 - Linux - 94ff757e-0a78-4e9c-971e-a0709206ac27 - LaunchBrowser - {Scheme}://localhost:{ServicePort} - filterlists.api - - - - - - - \ No newline at end of file diff --git a/docker-compose.filterlists-api.yml b/docker-compose.yml similarity index 80% rename from docker-compose.filterlists-api.yml rename to docker-compose.yml index 037bc5017..52a9194b0 100644 --- a/docker-compose.filterlists-api.yml +++ b/docker-compose.yml @@ -1,15 +1,24 @@ version: "3.7" services: + nginx: + image: nginx:alpine + restart: always + ports: + - "80:80" + networks: + - reverse-proxy + volumes: + - ./ops/nginx/dev/conf.d:/etc/nginx/conf.d:ro + filterlists-api: image: collinbarrett/filterlists.api + restart: always build: context: . dockerfile: src/FilterLists.Api/Dockerfile - ports: - - "80:80" - - "443:443" networks: + - reverse-proxy - filterlists-api depends_on: - mariadb_filterlists-api @@ -18,6 +27,7 @@ services: mariadb_filterlists-api: image: mariadb:10 + restart: always networks: - filterlists-api volumes: @@ -35,6 +45,7 @@ services: ] networks: + reverse-proxy: filterlists-api: volumes: diff --git a/ops/nginx/Dockerfile b/ops/nginx/Dockerfile deleted file mode 100644 index fbf884847..000000000 --- a/ops/nginx/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM nginx:stable-alpine -COPY nginx.conf /etc/nginx/nginx.conf \ No newline at end of file diff --git a/ops/nginx/dev/conf.d/filterlists-api.conf b/ops/nginx/dev/conf.d/filterlists-api.conf new file mode 100644 index 000000000..75f64fc2d --- /dev/null +++ b/ops/nginx/dev/conf.d/filterlists-api.conf @@ -0,0 +1,15 @@ +server { + listen 80; + + location ^~ /api { + rewrite ^/api/(.*)$ /$1 break; + proxy_pass http://filterlists-api:5000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection keep-alive; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} \ No newline at end of file diff --git a/ops/nginx/nginx.conf b/ops/nginx/nginx.conf deleted file mode 100644 index 3a148667b..000000000 --- a/ops/nginx/nginx.conf +++ /dev/null @@ -1,30 +0,0 @@ -worker_processes 4; - -events { worker_connections 1024; } - -http { - sendfile on; - - server { - listen 80; - - location ^~ /api { - rewrite ^/api/(.*)$ /$1 break; - proxy_pass http://FilterLists.Api:80; - proxy_redirect off; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Host $server_name; - } - - location / { - proxy_pass http://FilterLists.Web:80; - proxy_redirect off; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Host $server_name; - } - } -} \ No newline at end of file diff --git a/src/FilterLists.Api/Dockerfile b/src/FilterLists.Api/Dockerfile index 1c2890b5c..01f069eac 100644 --- a/src/FilterLists.Api/Dockerfile +++ b/src/FilterLists.Api/Dockerfile @@ -2,18 +2,34 @@ # Command: docker build -f src/FilterLists.Api/Dockerfile . FROM mcr.microsoft.com/dotnet/core/sdk:2.2-alpine AS build -WORKDIR /app +# restore +COPY ./FilterLists.Api.sln ./ +COPY src/*/*.csproj ./ +RUN for file in $(ls *.csproj); do mkdir -p src/${file%.*}/ && mv $file src/${file%.*}/; done +COPY tests/*/*.csproj ./ +RUN for file in $(ls *.csproj); do mkdir -p tests/${file%.*}/ && mv $file tests/${file%.*}/; done +RUN dotnet restore + +# build COPY src/FilterLists.Data/. ./FilterLists.Data/ COPY src/FilterLists.Services/. ./FilterLists.Services/ COPY src/FilterLists.Api/. ./FilterLists.Api/ -RUN dotnet publish FilterLists.Api/FilterLists.Api.csproj -c Release -o out +COPY tests/FilterLists.Data.Tests/. ./tests/FilterLists.Data.Tests/ +COPY tests/FilterLists.Services.Tests/. ./tests/FilterLists.Services.Tests/ +RUN dotnet build -c Release --no-restore +# test +RUN dotnet test "./tests/FilterLists.Data.Tests/FilterLists.Data.Tests.csproj" -c Release --no-build --no-restore +RUN dotnet test "./tests/FilterLists.Services.Tests/FilterLists.Services.Tests.csproj" -c Release --no-build --no-restore + +# publish +RUN dotnet publish FilterLists.Api/FilterLists.Api.csproj -c Release -o out --no-build --no-restore + +# run FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-alpine -WORKDIR /app -COPY --from=build /app/FilterLists.Api/out ./ -COPY data/. ./data/ ENV DataDirectory:Path="data" -EXPOSE 80 -EXPOSE 443 -ENTRYPOINT ["dotnet", "FilterLists.Api.dll"] \ No newline at end of file +ENV ASPNETCORE_URLS http://+:5000 +EXPOSE 5000 +ENTRYPOINT ["dotnet", "FilterLists.Api.dll"] +COPY --from=build /FilterLists.Api/out ./ diff --git a/tests/FilterLists.Data.Tests/FilterLists.Data.Tests.csproj b/tests/FilterLists.Data.Tests/FilterLists.Data.Tests.csproj index a35662227..8d8e6a229 100644 --- a/tests/FilterLists.Data.Tests/FilterLists.Data.Tests.csproj +++ b/tests/FilterLists.Data.Tests/FilterLists.Data.Tests.csproj @@ -38,7 +38,6 @@ -