2022-08-29 22:06:55 +02:00
|
|
|
|
namespace Bit.Setup;
|
|
|
|
|
|
|
|
|
|
public class DockerComposeBuilder
|
2017-11-06 23:28:02 +01:00
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
private readonly Context _context;
|
|
|
|
|
|
|
|
|
|
public DockerComposeBuilder(Context context)
|
2022-08-29 20:53:16 +02:00
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
_context = context;
|
|
|
|
|
}
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
public void BuildForInstaller()
|
|
|
|
|
{
|
|
|
|
|
_context.Config.DatabaseDockerVolume = _context.HostOS == "mac";
|
|
|
|
|
Build();
|
|
|
|
|
}
|
2022-08-29 20:53:16 +02:00
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
public void BuildForUpdater()
|
|
|
|
|
{
|
|
|
|
|
Build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Build()
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory("/bitwarden/docker/");
|
|
|
|
|
Helpers.WriteLine(_context, "Building docker-compose.yml.");
|
|
|
|
|
if (!_context.Config.GenerateComposeConfig)
|
2017-11-06 23:28:02 +01:00
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
Helpers.WriteLine(_context, "...skipped");
|
|
|
|
|
return;
|
2017-11-06 23:28:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
var template = Helpers.ReadTemplate("DockerCompose");
|
|
|
|
|
var model = new TemplateModel(_context);
|
|
|
|
|
using (var sw = File.CreateText("/bitwarden/docker/docker-compose.yml"))
|
2017-11-06 23:28:02 +01:00
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
sw.Write(template(model));
|
2017-11-06 23:28:02 +01:00
|
|
|
|
}
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
public class TemplateModel
|
|
|
|
|
{
|
|
|
|
|
public TemplateModel(Context context)
|
2017-11-06 23:28:02 +01:00
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
MssqlDataDockerVolume = context.Config.DatabaseDockerVolume;
|
|
|
|
|
EnableKeyConnector = context.Config.EnableKeyConnector;
|
|
|
|
|
EnableScim = context.Config.EnableScim;
|
|
|
|
|
HttpPort = context.Config.HttpPort;
|
|
|
|
|
HttpsPort = context.Config.HttpsPort;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(context.CoreVersion))
|
2018-08-30 17:35:44 +02:00
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
CoreVersion = context.CoreVersion;
|
2022-08-29 20:53:16 +02:00
|
|
|
|
}
|
2022-08-29 22:06:55 +02:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(context.WebVersion))
|
2022-08-29 20:53:16 +02:00
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
WebVersion = context.WebVersion;
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(context.KeyConnectorVersion))
|
|
|
|
|
{
|
|
|
|
|
KeyConnectorVersion = context.KeyConnectorVersion;
|
2017-11-06 23:28:02 +01:00
|
|
|
|
}
|
2022-08-29 21:53:48 +02:00
|
|
|
|
}
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
|
|
|
|
public bool MssqlDataDockerVolume { get; set; }
|
|
|
|
|
public bool EnableKeyConnector { get; set; }
|
|
|
|
|
public bool EnableScim { get; set; }
|
|
|
|
|
public string HttpPort { get; set; }
|
|
|
|
|
public string HttpsPort { get; set; }
|
|
|
|
|
public bool HasPort => !string.IsNullOrWhiteSpace(HttpPort) || !string.IsNullOrWhiteSpace(HttpsPort);
|
|
|
|
|
public string CoreVersion { get; set; } = "latest";
|
|
|
|
|
public string WebVersion { get; set; } = "latest";
|
|
|
|
|
public string KeyConnectorVersion { get; set; } = "latest";
|
2017-11-06 23:28:02 +01:00
|
|
|
|
}
|
|
|
|
|
}
|