2017-11-06 23:28:02 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace Bit.Setup
|
|
|
|
|
{
|
|
|
|
|
public class DockerComposeBuilder
|
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
private readonly Context _context;
|
2017-11-07 16:54:00 +01:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
public DockerComposeBuilder(Context context)
|
|
|
|
|
{
|
|
|
|
|
_context = context;
|
2017-11-06 23:28:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
public void BuildForInstaller()
|
2017-11-06 23:28:02 +01:00
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
_context.Config.DatabaseDockerVolume = _context.HostOS == "mac";
|
2017-11-06 23:28:02 +01:00
|
|
|
|
Build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void BuildForUpdater()
|
|
|
|
|
{
|
|
|
|
|
Build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Build()
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory("/bitwarden/docker/");
|
2018-08-30 17:35:44 +02:00
|
|
|
|
Console.WriteLine("Building docker-compose.yml.");
|
|
|
|
|
if(!_context.Config.GenerateComposeConfig)
|
2017-11-06 23:28:02 +01:00
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
Console.WriteLine("...skipped");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
var template = Helpers.ReadTemplate("DockerCompose");
|
|
|
|
|
var model = new TemplateModel(_context);
|
|
|
|
|
using(var sw = File.CreateText("/bitwarden/docker/docker-compose.yml"))
|
|
|
|
|
{
|
|
|
|
|
sw.Write(template(model));
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
public class TemplateModel
|
|
|
|
|
{
|
|
|
|
|
public TemplateModel(Context context)
|
|
|
|
|
{
|
2018-08-31 05:32:18 +02:00
|
|
|
|
if(!string.IsNullOrWhiteSpace(context.Config.ComposeVersion))
|
|
|
|
|
{
|
|
|
|
|
ComposeVersion = context.Config.ComposeVersion;
|
|
|
|
|
}
|
2018-08-30 17:35:44 +02:00
|
|
|
|
MssqlDataDockerVolume = context.Config.DatabaseDockerVolume;
|
|
|
|
|
HttpPort = context.Config.HttpPort;
|
|
|
|
|
HttpsPort = context.Config.HttpsPort;
|
2018-08-31 05:32:18 +02:00
|
|
|
|
if(!string.IsNullOrWhiteSpace(context.CoreVersion))
|
|
|
|
|
{
|
|
|
|
|
CoreVersion = context.CoreVersion;
|
|
|
|
|
}
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(context.WebVersion))
|
|
|
|
|
{
|
|
|
|
|
WebVersion = context.WebVersion;
|
|
|
|
|
}
|
2017-11-06 23:28:02 +01:00
|
|
|
|
}
|
2018-08-30 17:35:44 +02:00
|
|
|
|
|
2018-08-31 05:32:18 +02:00
|
|
|
|
public string ComposeVersion { get; set; } = "3";
|
2018-08-30 17:35:44 +02:00
|
|
|
|
public bool MssqlDataDockerVolume { get; set; }
|
|
|
|
|
public string HttpPort { get; set; }
|
|
|
|
|
public string HttpsPort { get; set; }
|
2018-09-26 22:53:37 +02:00
|
|
|
|
public bool HasPort => !string.IsNullOrWhiteSpace(HttpPort) || !string.IsNullOrWhiteSpace(HttpsPort);
|
2018-08-30 17:35:44 +02:00
|
|
|
|
public string CoreVersion { get; set; } = "latest";
|
|
|
|
|
public string WebVersion { get; set; } = "latest";
|
2017-11-06 23:28:02 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|