2017-11-06 23:28:02 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace Bit.Setup
|
|
|
|
|
{
|
|
|
|
|
public class DockerComposeBuilder
|
|
|
|
|
{
|
2017-11-07 16:54:00 +01:00
|
|
|
|
public DockerComposeBuilder(string os, string webVersion, string coreVersion)
|
2017-11-06 23:28:02 +01:00
|
|
|
|
{
|
|
|
|
|
MssqlDataDockerVolume = os == "mac";
|
2017-11-07 16:54:00 +01:00
|
|
|
|
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(webVersion))
|
|
|
|
|
{
|
|
|
|
|
WebVersion = webVersion;
|
|
|
|
|
}
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(coreVersion))
|
|
|
|
|
{
|
2018-03-30 22:07:01 +02:00
|
|
|
|
CoreVersion = coreVersion;
|
2017-11-07 16:54:00 +01:00
|
|
|
|
}
|
2017-11-06 23:28:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool MssqlDataDockerVolume { get; private set; }
|
2018-03-29 03:18:10 +02:00
|
|
|
|
public int HttpPort { get; private set; }
|
2018-03-28 17:03:20 +02:00
|
|
|
|
public int HttpsPort { get; private set; }
|
2017-11-07 16:54:00 +01:00
|
|
|
|
public string CoreVersion { get; private set; } = "latest";
|
|
|
|
|
public string WebVersion { get; private set; } = "latest";
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
|
|
|
|
public void BuildForInstaller(int httpPort, int httpsPort)
|
|
|
|
|
{
|
2018-03-28 17:03:20 +02:00
|
|
|
|
if(httpPort != default(int))
|
2017-11-06 23:28:02 +01:00
|
|
|
|
{
|
|
|
|
|
HttpPort = httpPort;
|
2018-03-28 17:03:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(httpsPort != default(int))
|
|
|
|
|
{
|
2017-11-06 23:28:02 +01:00
|
|
|
|
HttpsPort = httpsPort;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void BuildForUpdater()
|
|
|
|
|
{
|
2018-03-29 03:18:10 +02:00
|
|
|
|
var composeFile = "/bitwarden/docker/docker-compose.yml";
|
|
|
|
|
if(File.Exists(composeFile))
|
2017-11-06 23:28:02 +01:00
|
|
|
|
{
|
2018-03-29 03:18:10 +02:00
|
|
|
|
var fileLines = File.ReadAllLines(composeFile);
|
2017-11-06 23:28:02 +01:00
|
|
|
|
foreach(var line in fileLines)
|
|
|
|
|
{
|
|
|
|
|
if(!line.StartsWith("# Parameter:"))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var paramParts = line.Split("=");
|
|
|
|
|
if(paramParts.Length < 2)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-28 22:34:16 +02:00
|
|
|
|
if(paramParts[0] == "# Parameter:MssqlDataDockerVolume" &&
|
|
|
|
|
bool.TryParse(paramParts[1], out var mssqlDataDockerVolume))
|
|
|
|
|
{
|
|
|
|
|
MssqlDataDockerVolume = mssqlDataDockerVolume;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(paramParts[0] == "# Parameter:HttpPort" && int.TryParse(paramParts[1], out var httpPort))
|
2017-11-06 23:28:02 +01:00
|
|
|
|
{
|
|
|
|
|
HttpPort = httpPort;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-28 22:34:16 +02:00
|
|
|
|
if(paramParts[0] == "# Parameter:HttpsPort" && int.TryParse(paramParts[1], out var httpsPort))
|
2017-11-06 23:28:02 +01:00
|
|
|
|
{
|
|
|
|
|
HttpsPort = httpsPort;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Build()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Building docker-compose.yml.");
|
|
|
|
|
Directory.CreateDirectory("/bitwarden/docker/");
|
|
|
|
|
using(var sw = File.CreateText("/bitwarden/docker/docker-compose.yml"))
|
|
|
|
|
{
|
|
|
|
|
sw.Write($@"# https://docs.docker.com/compose/compose-file/
|
|
|
|
|
# Parameter:MssqlDataDockerVolume={MssqlDataDockerVolume}
|
|
|
|
|
# Parameter:HttpPort={HttpPort}
|
|
|
|
|
# Parameter:HttpsPort={HttpsPort}
|
|
|
|
|
# Parameter:CoreVersion={CoreVersion}
|
|
|
|
|
# Parameter:WebVersion={WebVersion}
|
|
|
|
|
|
|
|
|
|
version: '3'
|
|
|
|
|
|
|
|
|
|
services:
|
2017-12-21 17:18:36 +01:00
|
|
|
|
mssql:
|
2018-03-30 22:07:01 +02:00
|
|
|
|
image: bitwarden/mssql:{CoreVersion}
|
2017-12-08 02:01:41 +01:00
|
|
|
|
container_name: bitwarden-mssql
|
2017-11-06 23:28:02 +01:00
|
|
|
|
restart: always
|
|
|
|
|
volumes:");
|
|
|
|
|
|
|
|
|
|
if(MssqlDataDockerVolume)
|
|
|
|
|
{
|
|
|
|
|
sw.Write(@"
|
|
|
|
|
- mssql_data:/var/opt/mssql/data");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sw.Write(@"
|
2018-04-16 16:42:56 +02:00
|
|
|
|
- ../mssql/data:/var/opt/mssql/data");
|
2017-11-06 23:28:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sw.Write($@"
|
2018-04-16 16:42:56 +02:00
|
|
|
|
- ../logs/mssql:/var/opt/mssql/log
|
2017-11-06 23:28:02 +01:00
|
|
|
|
- ../mssql/backups:/etc/bitwarden/mssql/backups
|
|
|
|
|
env_file:
|
|
|
|
|
- mssql.env
|
2018-03-27 20:55:33 +02:00
|
|
|
|
- ../env/uid.env
|
2017-11-06 23:28:02 +01:00
|
|
|
|
- ../env/mssql.override.env
|
|
|
|
|
|
2017-12-21 17:18:36 +01:00
|
|
|
|
web:
|
2017-11-06 23:28:02 +01:00
|
|
|
|
image: bitwarden/web:{WebVersion}
|
2017-12-08 02:01:41 +01:00
|
|
|
|
container_name: bitwarden-web
|
2017-11-06 23:28:02 +01:00
|
|
|
|
restart: always
|
|
|
|
|
volumes:
|
|
|
|
|
- ../web:/etc/bitwarden/web
|
2018-03-27 20:55:33 +02:00
|
|
|
|
env_file:
|
|
|
|
|
- ../env/uid.env
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
2017-12-21 17:18:36 +01:00
|
|
|
|
attachments:
|
2017-11-06 23:28:02 +01:00
|
|
|
|
image: bitwarden/attachments:{CoreVersion}
|
2017-12-08 02:01:41 +01:00
|
|
|
|
container_name: bitwarden-attachments
|
2017-11-06 23:28:02 +01:00
|
|
|
|
restart: always
|
|
|
|
|
volumes:
|
|
|
|
|
- ../core/attachments:/etc/bitwarden/core/attachments
|
2018-03-27 20:55:33 +02:00
|
|
|
|
env_file:
|
|
|
|
|
- ../env/uid.env
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
2017-12-21 17:18:36 +01:00
|
|
|
|
api:
|
2017-11-06 23:28:02 +01:00
|
|
|
|
image: bitwarden/api:{CoreVersion}
|
2017-12-08 02:01:41 +01:00
|
|
|
|
container_name: bitwarden-api
|
2017-11-06 23:28:02 +01:00
|
|
|
|
restart: always
|
|
|
|
|
volumes:
|
|
|
|
|
- ../core:/etc/bitwarden/core
|
2018-03-29 14:59:50 +02:00
|
|
|
|
- ../ca-certificates:/etc/bitwarden/ca-certificates
|
2018-03-28 04:16:55 +02:00
|
|
|
|
- ../logs/api:/etc/bitwarden/logs
|
2017-11-06 23:28:02 +01:00
|
|
|
|
env_file:
|
|
|
|
|
- global.env
|
2018-03-27 20:55:33 +02:00
|
|
|
|
- ../env/uid.env
|
2017-11-06 23:28:02 +01:00
|
|
|
|
- ../env/global.override.env
|
|
|
|
|
|
2017-12-21 17:18:36 +01:00
|
|
|
|
identity:
|
2017-11-06 23:28:02 +01:00
|
|
|
|
image: bitwarden/identity:{CoreVersion}
|
2017-12-08 02:01:41 +01:00
|
|
|
|
container_name: bitwarden-identity
|
2017-11-06 23:28:02 +01:00
|
|
|
|
restart: always
|
|
|
|
|
volumes:
|
|
|
|
|
- ../identity:/etc/bitwarden/identity
|
|
|
|
|
- ../core:/etc/bitwarden/core
|
2018-03-29 14:59:50 +02:00
|
|
|
|
- ../ca-certificates:/etc/bitwarden/ca-certificates
|
2018-03-28 04:16:55 +02:00
|
|
|
|
- ../logs/identity:/etc/bitwarden/logs
|
2017-11-06 23:28:02 +01:00
|
|
|
|
env_file:
|
|
|
|
|
- global.env
|
2018-03-27 20:55:33 +02:00
|
|
|
|
- ../env/uid.env
|
2017-11-06 23:28:02 +01:00
|
|
|
|
- ../env/global.override.env
|
|
|
|
|
|
2018-03-24 02:11:17 +01:00
|
|
|
|
admin:
|
|
|
|
|
image: bitwarden/admin:{CoreVersion}
|
|
|
|
|
container_name: bitwarden-admin
|
|
|
|
|
restart: always
|
|
|
|
|
volumes:
|
|
|
|
|
- ../core:/etc/bitwarden/core
|
2018-03-29 05:47:43 +02:00
|
|
|
|
- ../ca-certificates:/etc/bitwarden/ca-certificates
|
2018-03-28 04:16:55 +02:00
|
|
|
|
- ../logs/admin:/etc/bitwarden/logs
|
2018-03-24 02:11:17 +01:00
|
|
|
|
env_file:
|
|
|
|
|
- global.env
|
2018-03-27 20:55:33 +02:00
|
|
|
|
- ../env/uid.env
|
2018-03-24 02:11:17 +01:00
|
|
|
|
- ../env/global.override.env
|
|
|
|
|
|
2017-12-21 17:18:36 +01:00
|
|
|
|
icons:
|
2017-11-06 23:28:02 +01:00
|
|
|
|
image: bitwarden/icons:{CoreVersion}
|
2017-12-08 02:01:41 +01:00
|
|
|
|
container_name: bitwarden-icons
|
2017-11-06 23:28:02 +01:00
|
|
|
|
restart: always
|
2018-03-27 20:55:33 +02:00
|
|
|
|
env_file:
|
|
|
|
|
- ../env/uid.env
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
2017-12-21 17:18:36 +01:00
|
|
|
|
nginx:
|
2017-11-06 23:28:02 +01:00
|
|
|
|
image: bitwarden/nginx:{CoreVersion}
|
2017-12-08 02:01:41 +01:00
|
|
|
|
container_name: bitwarden-nginx
|
2017-11-06 23:28:02 +01:00
|
|
|
|
restart: always
|
2018-03-29 03:18:10 +02:00
|
|
|
|
ports:");
|
|
|
|
|
|
|
|
|
|
if(HttpPort != default(int))
|
|
|
|
|
{
|
|
|
|
|
sw.Write($@"
|
2018-03-28 17:03:20 +02:00
|
|
|
|
- '{HttpPort}:8080'");
|
2018-03-29 03:18:10 +02:00
|
|
|
|
}
|
2018-03-28 17:03:20 +02:00
|
|
|
|
|
|
|
|
|
if(HttpsPort != default(int))
|
|
|
|
|
{
|
|
|
|
|
sw.Write($@"
|
2018-03-29 19:53:39 +02:00
|
|
|
|
- '{HttpsPort}:8443'");
|
2018-03-28 17:03:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sw.Write($@"
|
2017-11-06 23:28:02 +01:00
|
|
|
|
volumes:
|
|
|
|
|
- ../nginx:/etc/bitwarden/nginx
|
|
|
|
|
- ../letsencrypt:/etc/letsencrypt
|
2018-03-27 20:55:33 +02:00
|
|
|
|
- ../ssl:/etc/ssl
|
2018-03-28 04:16:55 +02:00
|
|
|
|
- ../logs/nginx:/var/log/nginx
|
2018-03-27 20:55:33 +02:00
|
|
|
|
env_file:
|
|
|
|
|
- ../env/uid.env");
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
|
|
|
|
if(MssqlDataDockerVolume)
|
|
|
|
|
{
|
|
|
|
|
sw.Write(@"
|
|
|
|
|
volumes:
|
|
|
|
|
mssql_data:");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// New line at end of file.
|
2017-11-07 16:54:00 +01:00
|
|
|
|
sw.Write("\n");
|
2017-11-06 23:28:02 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|