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; class Build : NukeBuild { /// Support plugins are available for: /// - JetBrains ReSharper https://nuke.build/resharper /// - 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.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."); }); }