From 2a1dec45d89aad3399b076abe2c4e30823360ac9 Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Mon, 9 Oct 2023 15:29:53 +0200 Subject: [PATCH] build: add docker-compose & NUKE buildsystem --- Continuity.sln | 5 +++ Server/Server.csproj | 2 +- Server/docker-compose.yml | 30 +++++++++++++++++ Server/settings.Development.json | 8 ++--- build/Build.cs | 57 ++++++++++++++++++++++++++++++-- 5 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 Server/docker-compose.yml diff --git a/Continuity.sln b/Continuity.sln index a44f1f5..6f2b4f3 100644 --- a/Continuity.sln +++ b/Continuity.sln @@ -6,6 +6,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmarks", "Benchmarks\Be EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{046A3B46-FC08-4B08-A52A-1DC5D426120D}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C1303691-99F6-41CE-BAD3-2CA112D75DBF}" + ProjectSection(SolutionItems) = preProject + docker-compose.yml = docker-compose.yml + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/Server/Server.csproj b/Server/Server.csproj index f5e4614..01d9a81 100644 --- a/Server/Server.csproj +++ b/Server/Server.csproj @@ -70,7 +70,7 @@ - PreserveNewest + Always diff --git a/Server/docker-compose.yml b/Server/docker-compose.yml new file mode 100644 index 0000000..5cbd3e9 --- /dev/null +++ b/Server/docker-compose.yml @@ -0,0 +1,30 @@ +services: + server: + image: continuity-server:latest + environment: + - ENVIRONMENT=Development + - Testing:CreateAccountOnLogin=true + - DB:Host=db + - DB:Port=5432 + - DB:Username=continuity + - DB:Password=continuity + networks: + - continuity + ports: + - "10001:10001" + + db: + image: postgres:16.0-alpine + environment: + - POSTGRES_USER=continuity + - POSTGRES_DB=continuity + - POSTGRES_PASSWORD=continuity + networks: + - continuity + volumes: + - db-data:/var/lib/postgresql/data + +networks: + continuity: +volumes: + db-data: diff --git a/Server/settings.Development.json b/Server/settings.Development.json index 8b9e207..1b64c70 100644 --- a/Server/settings.Development.json +++ b/Server/settings.Development.json @@ -1,10 +1,10 @@ { "DB": { - "Username": "continuitydevuser", - "Host": "perf.rainote.dev", - "Password": "7>CU`D2/LKw6hD/7", + "Username": "continuity", + "Host": "localhost", + "Password": "continuity", "Database": "continuity", - "Port": "13543" + "Port": "5432" }, "Testing": { "CreateAccountOnLogin": true diff --git a/build/Build.cs b/build/Build.cs index 9026020..ba46dc2 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -2,11 +2,18 @@ using System; using System.Linq; using Nuke.Common; using Nuke.Common.CI; +using Nuke.Common.CI.GitHubActions; using Nuke.Common.Execution; +using Nuke.Common.Git; using Nuke.Common.IO; using Nuke.Common.ProjectModel; using Nuke.Common.Tooling; +using Nuke.Common.Tools.CodeMetrics; +using Nuke.Common.Tools.Docker; +using Nuke.Common.Tools.DotNet; +using Nuke.Common.Tools.SonarScanner; using Nuke.Common.Utilities.Collections; +using Serilog; using static Nuke.Common.EnvironmentInfo; using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.IO.PathConstruction; @@ -18,27 +25,73 @@ class Build : NukeBuild /// - JetBrains Rider https://nuke.build/rider /// - Microsoft VisualStudio https://nuke.build/visualstudio /// - Microsoft VSCode https://nuke.build/vscode - - public static int Main () => Execute(x => x.Compile); + public static int Main() => Execute(x => x.Information, x => x.Deploy); [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; + GitRepository GitRepository => GitRepository.FromLocalDirectory(RootDirectory); + + Target Information => _ => _ + .Before(Clean) + .Executes(() => + { + Log.Information("Branch Name: {BranchName}", GitRepository.Branch); + Log.Information("Commit: {Commit}", GitRepository.Commit); + }); + Target Clean => _ => _ .Before(Restore) .Executes(() => { + DotNetTasks.DotNetClean(); }); Target Restore => _ => _ .Executes(() => { + DotNetTasks.DotNetRestore(); }); Target Compile => _ => _ + .DependsOn(Clean) .DependsOn(Restore) .Executes(() => { + DockerTasks.DockerStackRm(settings => settings.SetStacks("continuity")); + DotNetTasks.DotNetBuild(settings => settings.SetNoRestore(true)); }); + Target Pack => _ => _ + .DependsOn(Compile) + .Executes(() => + { + DockerTasks.DockerBuild(settings => settings + .SetPath(AbsolutePath.Create(RootDirectory)) + .SetFile("Server/Dockerfile") + .SetTag("continuity-server:latest") + .SetCompress(true) + .SetProgress(ProgressType.auto)); + if (!IsLocalBuild) + { + DockerTasks.DockerPush(settings => settings.SetName("continuity-server:latest")); + } + }); + + Target Deploy => _ => _.DependsOn(Pack).Executes(() => + { + DockerTasks.DockerPull(settings => settings.SetName("postgres:16.0-alpine")); + if (IsLocalBuild) + { + var dockerComposeFile = AbsolutePath.Create(RootDirectory / "Server" / "docker-compose.yml"); + DockerTasks.DockerStackDeploy(settings => settings + .AddComposeFile(dockerComposeFile) + .SetStack("continuity") + .SetPrune(true) + ); + return; + } + + Log.Error("Deploy is only available on local builds."); + }); }