Skip to content

Commit

Permalink
Added CICD for story book
Browse files Browse the repository at this point in the history
  • Loading branch information
dyatlov-a committed Nov 11, 2024
1 parent 99bd3a4 commit 3398c2f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 52 deletions.
58 changes: 25 additions & 33 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@ public sealed class Build : NukeBuild

[Parameter("Server password", Name = "serverpassword")]
private readonly string ServerPassword = default!;



public static int Main () => Execute<Build>(x => x.Compile);

private AbsolutePath SourceDirectory => RootDirectory / "src";
private AbsolutePath OutputDirectory => RootDirectory / "output";
private AbsolutePath TestsDirectory => RootDirectory / "tests";
private AbsolutePath TestReportsDirectory => OutputDirectory / "test-reports";

private const string AppDirectory = "/home/teamassist/prod";
private const string MigrationRunnerProject = "Inc.TeamAssistant.MigrationsRunner";
private const string GatewayProject = "Inc.TeamAssistant.Gateway";
private readonly IEnumerable<string> AppProjects = [GatewayProject];
private readonly IEnumerable<string> AppProjects = ["Inc.TeamAssistant.Gateway", "Inc.TeamAssistant.Stories"];

private IEnumerable<string> ProjectsForPublish => AppProjects.Concat(MigrationRunnerProject);

Expand Down Expand Up @@ -115,13 +114,14 @@ public sealed class Build : NukeBuild
.DependsOn(Publish)
.Executes(() =>
{
DockerBuild(x => x
.DisableProcessLogOutput()
.SetProcessWorkingDirectory(RootDirectory)
.SetPath(".")
.SetFile("cicd/dockerfile.app_component")
.SetBuildArg($"PROJECT={GatewayProject}")
.SetTag(GetImageName(GatewayProject)));
foreach (var appProject in AppProjects)
DockerBuild(x => x
.DisableProcessLogOutput()
.SetProcessWorkingDirectory(RootDirectory)
.SetPath(".")
.SetFile("cicd/dockerfile.app_component")
.SetBuildArg($"PROJECT={appProject}")
.SetTag(GetImageName(appProject)));

DockerBuild(x => x
.DisableProcessLogOutput()
Expand All @@ -140,43 +140,35 @@ public sealed class Build : NukeBuild
.SetPassword(HubPassword)
.DisableProcessLogOutput());

DockerPush(s => s
.SetName(GetImageName(GatewayProject))
.DisableProcessLogOutput());
DockerPush(s => s
.SetName(GetImageName(MigrationRunnerProject))
.DisableProcessLogOutput());
foreach (var appProject in ProjectsForPublish)
DockerPush(s => s
.SetName(GetImageName(appProject))
.DisableProcessLogOutput());
});

private Target Deploy => _ => _
.DependsOn(PushImages)
.Executes(() =>
{
var appDirectory = "/home/teamassist/prod";
var appraiserImage = GetImageName(GatewayProject);
var migrationsRunnerImage = GetImageName(MigrationRunnerProject);

using var client = new SshClient(ServerName, ServerUsername, ServerPassword);

client.Connect();

client.RunCommand($"docker pull {appraiserImage}");
Console.WriteLine($"Image {appraiserImage} pulled");

client.RunCommand($"docker pull {migrationsRunnerImage}");
Console.WriteLine($"Image {migrationsRunnerImage} pulled");
foreach (var appProject in ProjectsForPublish)
{
var image = GetImageName(appProject);

client.RunCommand($"docker pull {image}");
Console.WriteLine($"Image {image} pulled");
}

client.RunCommand($"cd {appDirectory} && docker compose down");
client.RunCommand($"cd {AppDirectory} && docker compose down");
Console.WriteLine("App stopped");

client.RunCommand($"cd {appDirectory} && docker compose up -d");
client.RunCommand($"cd {AppDirectory} && docker compose up -d");
Console.WriteLine("App started");

client.Disconnect();
});

private string GetImageName(string projectName)
{
return $"dyatlovhome/{projectName.ToLowerInvariant()}:latest";
}
private string GetImageName(string projectName) => $"dyatlovhome/{projectName.ToLowerInvariant()}:latest";
}
11 changes: 11 additions & 0 deletions cicd/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ services:
networks:
- team_assistant
restart: unless-stopped

stories:
image: dyatlovhome/inc.teamassistant.stories:latest
environment:
- ASPNETCORE_ENVIRONMENT=Production
container_name: stories
expose:
- 8080
networks:
- team_assistant
restart: unless-stopped

migrate:
image: dyatlovhome/inc.teamassistant.migrationsrunner:latest
Expand Down
58 changes: 39 additions & 19 deletions cicd/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,36 +1,56 @@
events { }

http {

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
default upgrade;
'' close;
}

server {
server {
listen 80;
server_name teamassist.bot;
return 301 https://teamassist.bot$request_uri;
}
}

server {
server {
listen 443 ssl;
server_name teamassist.bot;
ssl_certificate /ssl/cert.crt;
ssl_certificate_key /ssl/key.key;

location / {
proxy_pass http://gateway:8080/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http://gateway:8080/ $scheme://$http_host/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
proxy_buffering off;
proxy_pass http://gateway:8080/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http://gateway:8080/ $scheme://$http_host/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
proxy_buffering off;
}
}

server {
listen 443 ssl;
server_name stories.teamassist.bot;
ssl_certificate /ssl/cert.crt;
ssl_certificate_key /ssl/key.key;

location / {
proxy_pass http://stories:8080/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http://stories:8080/ $scheme://$http_host/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
proxy_buffering off;
}
}
}
}

0 comments on commit 3398c2f

Please sign in to comment.