summaryrefslogtreecommitdiffstats
path: root/makefu/2configs/workadventure/workadventure.nix
blob: 02680aa77ee6a280e4231b95cb2c35024cc054be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
{ config, pkgs, lib, ... }:
let
  # If your Jitsi environment has authentication set up,
  # you MUST set JITSI_PRIVATE_MODE to "true" and
  # you MUST pass a SECRET_JITSI_KEY to generate the JWT secret
  jitsiPrivateMode = "false";

  secretJitsiKey = "";

  jitsiISS = "";

  workadventureSecretKey = "";

  jitsiURL = "meet.euer.krebsco.de";

  domain = "work.euer.krebsco.de";
  # domain will redirect to this map. (not play.${domain})
  defaultMap = "npeguin.github.io/office-map/map.json";

  apiURL = "api.${domain}";
  apiPort = 9002;

  frontURL = "play.${domain}";
  frontPort = 9004;

  pusherURL = "push.${domain}";
  pusherPort = 9005;

  uploaderURL = "ul.${domain}";
  uploaderPort = 9006;

  frontImage = "thecodingmachine/workadventure-front:develop";
  pusherImage = "thecodingmachine/workadventure-pusher:develop";
  apiImage = "thecodingmachine/workadventure-back:develop";
  uploaderImage = "thecodingmachine/workadventure-uploader:develop";

in {

  networking.firewall = {
    allowedTCPPorts = [ 80 443 ];
    allowedUDPPorts = [ 80 443 ];
  };

  services.nginx.enable = true;
  services.nginx.recommendedProxySettings = true;

  systemd.services.workadventure-network = {
    enable = true;
    wantedBy = [ "multi-user.target" ];
    script = ''
      ${pkgs.docker}/bin/docker network create --driver bridge workadventure ||:
    '';
    after = [ "docker" ];
    before = [
      "docker-workadventure-back.service"
      "docker-workadventure-pusher.service"
      "docker-workadventure-uploader.service"
      "docker-workadventure-website.service"
    ];
  };

  virtualisation.oci-containers.backend = "docker";
  security.acme.certs."${domain}".extraDomainNames = [ apiURL frontURL pusherURL uploaderURL ];
  services.nginx.virtualHosts."${domain}" = {
    enableACME = true;
    forceSSL = true;
    locations."/" = {
      return = "301 $scheme://play.${domain}/_/global/${defaultMap}";
    };
  };

  virtualisation.oci-containers.containers.workadventure-front = {
    image = frontImage;
    environment = {
      API_URL = pusherURL;
      JITSI_PRIVATE_MODE = jitsiPrivateMode;
      JITSI_URL = jitsiURL;
      SECRET_JITSI_KEY = secretJitsiKey;
      UPLOADER_URL = uploaderURL;
    };
    ports = [ "127.0.0.1:${toString frontPort}:80" ];
    extraOptions = [ "--network=workadventure" ];
  };
  services.nginx.virtualHosts."${frontURL}" = {
    useACMEHost = domain;
    forceSSL = true;
    locations."/" = { proxyPass = "http://127.0.0.1:${toString frontPort}"; };
  };

  virtualisation.oci-containers.containers.workadventure-pusher = {
    image = pusherImage;
    environment = {
      API_URL = "workadventure-back:50051";
      JITSI_ISS = jitsiISS;
      JITSI_URL = jitsiURL;
      SECRET_KEY = workadventureSecretKey;
    };
    ports = [ "127.0.0.1:${toString pusherPort}:8080" ];
    extraOptions = [ "--network=workadventure" ];
  };
  services.nginx.virtualHosts."${pusherURL}" = {
    useACMEHost = domain;
    forceSSL = true;
    locations."/" = {
      proxyPass = "http://127.0.0.1:${toString pusherPort}";
      proxyWebsockets = true;
    };
    locations."/room" = {
      proxyPass = "http://127.0.0.1:${toString pusherPort}";
      proxyWebsockets = true;
    };
  };

  virtualisation.oci-containers.containers.workadventure-back = {
    image = apiImage;
    environment = {
      #DEBUG = "*";
      JITSI_ISS = jitsiISS;
      JITSI_URL = jitsiURL;
      SECRET_KEY = workadventureSecretKey;
    };
    ports = [ "127.0.0.1:${toString apiPort}:8080" "50051" ];
    extraOptions = [ "--network=workadventure" ];
  };
  services.nginx.virtualHosts."${apiURL}" = {
    useACMEHost = domain;
    forceSSL = true;
    locations."/" = { proxyPass = "http://127.0.0.1:${toString apiPort}"; };
  };

  virtualisation.oci-containers.containers.workadventure-uploader = {
    image = uploaderImage;
    ports = [ "127.0.0.1:${toString uploaderPort}:8080" ];
    extraOptions = [ "--network=workadventure" ];
  };
  services.nginx.virtualHosts."${uploaderURL}" = {
    useACMEHost = domain;
    forceSSL = true;
    locations."/" = {
      proxyPass = "http://127.0.0.1:${toString uploaderPort}";
      proxyWebsockets = true;
    };
  };

  systemd.services.docker-workadventure-front.serviceConfig = {
    StandardOutput = lib.mkForce "journal";
    StandardError = lib.mkForce "journal";
  };
  systemd.services.docker-workadventure-uploader.serviceConfig = {
    StandardOutput = lib.mkForce "journal";
    StandardError = lib.mkForce "journal";
  };
  systemd.services.docker-workadventure-pusher.serviceConfig = {
    StandardOutput = lib.mkForce "journal";
    StandardError = lib.mkForce "journal";
  };
  systemd.services.docker-workadventure-back.serviceConfig = {
    StandardOutput = lib.mkForce "journal";
    StandardError = lib.mkForce "journal";
  };
}