2022-06-30 01:46:41 +02:00
|
|
|
|
namespace Bit.Setup;
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2017-11-06 23:28:02 +01:00
|
|
|
|
public class DockerComposeBuilder
|
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
private readonly Context _context;
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2017-11-06 23:28:02 +01:00
|
|
|
|
public DockerComposeBuilder(Context context)
|
2022-08-29 20:53:16 +02:00
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
_context = context;
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
public void BuildForInstaller()
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
_context.Config.DatabaseDockerVolume = _context.HostOS == "mac";
|
2022-08-29 20:53:16 +02:00
|
|
|
|
Build();
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-06 23:28:02 +01:00
|
|
|
|
public void BuildForUpdater()
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
|
|
|
|
Build();
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-06 23:28:02 +01:00
|
|
|
|
private void Build()
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2020-03-27 19:36:37 +01:00
|
|
|
|
Directory.CreateDirectory("/bitwarden/docker/");
|
2017-11-06 23:28:02 +01:00
|
|
|
|
Helpers.WriteLine(_context, "Building docker-compose.yml.");
|
2020-03-27 19:36:37 +01:00
|
|
|
|
if (!_context.Config.GenerateComposeConfig)
|
2017-11-06 23:28:02 +01:00
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
Helpers.WriteLine(_context, "...skipped");
|
2017-11-06 23:28:02 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var template = Helpers.ReadTemplate("DockerCompose");
|
2020-03-27 19:36:37 +01:00
|
|
|
|
var model = new TemplateModel(_context);
|
2017-11-06 23:28:02 +01:00
|
|
|
|
using (var sw = File.CreateText("/bitwarden/docker/docker-compose.yml"))
|
|
|
|
|
{
|
|
|
|
|
sw.Write(template(model));
|
|
|
|
|
}
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
public class TemplateModel
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2017-11-06 23:28:02 +01:00
|
|
|
|
public TemplateModel(Context context)
|
|
|
|
|
{
|
2020-03-27 19:36:37 +01:00
|
|
|
|
MssqlDataDockerVolume = context.Config.DatabaseDockerVolume;
|
|
|
|
|
EnableKeyConnector = context.Config.EnableKeyConnector;
|
2022-07-14 21:58:48 +02:00
|
|
|
|
EnableScim = context.Config.EnableScim;
|
2018-08-30 17:35:44 +02:00
|
|
|
|
HttpPort = context.Config.HttpPort;
|
2020-03-27 19:36:37 +01:00
|
|
|
|
HttpsPort = context.Config.HttpsPort;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(context.CoreVersion))
|
2018-08-30 17:35:44 +02:00
|
|
|
|
{
|
2018-08-31 05:32:18 +02:00
|
|
|
|
CoreVersion = context.CoreVersion;
|
|
|
|
|
}
|
2021-12-29 17:07:16 +01:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(context.WebVersion))
|
|
|
|
|
{
|
2019-03-12 15:26:14 +01:00
|
|
|
|
WebVersion = context.WebVersion;
|
2022-08-29 21:53:48 +02:00
|
|
|
|
}
|
2021-12-29 17:07:16 +01:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(context.KeyConnectorVersion))
|
2022-08-29 21:53:48 +02:00
|
|
|
|
{
|
2021-12-29 17:07:16 +01:00
|
|
|
|
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
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
public bool MssqlDataDockerVolume { get; set; }
|
2021-11-16 18:52:02 +01:00
|
|
|
|
public bool EnableKeyConnector { get; set; }
|
2022-07-14 21:58:48 +02:00
|
|
|
|
public bool EnableScim { get; set; }
|
2018-08-30 17:35:44 +02:00
|
|
|
|
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";
|
2021-12-29 17:07:16 +01:00
|
|
|
|
public string KeyConnectorVersion { get; set; } = "latest";
|
2017-11-06 23:28:02 +01:00
|
|
|
|
}
|
|
|
|
|
}
|